Dungeon Fixes

This commit is contained in:
dingo
2026-01-31 10:36:35 -05:00
parent dd0969a9f0
commit fd7a55e149
4 changed files with 137 additions and 44 deletions
+55 -2
View File
@@ -1,4 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using DataServer.Data;
using DataServer.Data.Entities;
using GameServer.Dungeon;
namespace GameServices.Admin.Pages.Dungeons;
@@ -6,13 +9,16 @@ namespace GameServices.Admin.Pages.Dungeons;
public class IndexModel : AdminPageModel
{
private readonly DungeonHandler _dungeonHandler;
private readonly GameDbContext _db;
public IndexModel(DungeonHandler dungeonHandler)
public IndexModel(DungeonHandler dungeonHandler, GameDbContext db)
{
_dungeonHandler = dungeonHandler;
_db = db;
}
public List<DungeonSummary> Dungeons { get; set; } = new();
public List<ArchivedDungeonSummary> ArchivedDungeons { get; set; } = new();
// Stats
public int ActiveCount { get; set; }
@@ -25,7 +31,7 @@ public class IndexModel : AdminPageModel
public int? TierFilter { get; set; }
public int? BracketFilter { get; set; }
public void OnGet(string? status, int? tier, int? bracket)
public async Task OnGetAsync(string? status, int? tier, int? bracket)
{
StatusFilter = status;
TierFilter = tier;
@@ -95,6 +101,24 @@ public class IndexModel : AdminPageModel
var avgMinutes = completedDungeons.Average(d => (DateTime.UtcNow - d.CreatedAt).TotalMinutes);
AverageDuration = avgMinutes.ToString("F1");
}
ArchivedDungeons = await _db.Set<DungeonPersistence>()
.Where(d => !d.IsCleared)
.OrderByDescending(d => d.PersistedAt ?? d.CreatedAt)
.Select(d => new ArchivedDungeonSummary
{
Id = d.Id,
Tier = d.Tier,
Seed = d.Seed,
LevelBracketMin = d.LevelBracketMin,
LevelBracketMax = d.LevelBracketMax,
CreatorName = d.CreatorName,
CreatedAt = d.CreatedAt,
LastActivity = d.LastActivity,
PersistedAt = d.PersistedAt,
BossKilled = d.BossKilled
})
.ToListAsync();
}
public IActionResult OnPostDelete(Guid id)
@@ -111,6 +135,21 @@ public class IndexModel : AdminPageModel
return RedirectToPage();
}
public async Task<IActionResult> OnPostArchiveAsync(Guid id)
{
var (ok, error) = await _dungeonHandler.ForceArchiveDungeonAsync(id);
if (ok)
{
TempData["Message"] = "Dungeon archived successfully.";
}
else
{
TempData["Error"] = error ?? "Failed to archive dungeon.";
}
return RedirectToPage();
}
private static string FormatDuration(TimeSpan duration)
{
@@ -139,3 +178,17 @@ public class DungeonSummary
public bool BossKilled { get; set; }
public string Duration { get; set; } = "";
}
public class ArchivedDungeonSummary
{
public Guid Id { get; set; }
public int Tier { get; set; }
public int Seed { get; set; }
public int LevelBracketMin { get; set; }
public int LevelBracketMax { get; set; }
public string CreatorName { get; set; } = "";
public DateTime CreatedAt { get; set; }
public DateTime LastActivity { get; set; }
public DateTime? PersistedAt { get; set; }
public bool BossKilled { get; set; }
}