Admin updates, dungeon viewer

This commit is contained in:
dingo
2026-01-10 13:43:59 -05:00
parent c43a334d8b
commit ff7357c557
15 changed files with 1033 additions and 1403 deletions
@@ -0,0 +1,163 @@
using Microsoft.AspNetCore.Mvc;
using Server.Game.Dungeon;
using System.Text.Json;
namespace Server.Services.Admin.Pages.Dungeons;
public class ViewModel : AdminPageModel
{
private readonly DungeonHandler _dungeonHandler;
public ViewModel(DungeonHandler dungeonHandler)
{
_dungeonHandler = dungeonHandler;
}
public DungeonInstance? Dungeon { get; set; }
public string Duration { get; set; } = "";
public int RoomCount { get; set; }
public int MapWidth { get; set; }
public int MapHeight { get; set; }
public string WalkableJson { get; set; } = "[]";
public string PlayersJson { get; set; } = "[]";
public string MobsJson { get; set; } = "[]";
public void OnGet(Guid id)
{
Dungeon = _dungeonHandler.GetDungeon(id);
if (Dungeon == null) return;
Duration = FormatDuration(DateTime.UtcNow - Dungeon.CreatedAt);
RoomCount = Dungeon.LayoutV2?.Rooms?.Count ?? Dungeon.Simulation.Layout.Rooms.Count;
// Get map dimensions
var layout = Dungeon.LayoutV2 ?? (DungeonLayoutV2?)null;
if (layout != null)
{
MapWidth = layout.Width;
MapHeight = layout.Height;
// Flatten walkable array
var walkable = new List<bool>();
for (int y = 0; y < layout.Height; y++)
{
for (int x = 0; x < layout.Width; x++)
{
walkable.Add(layout.Walkable[x, y]);
}
}
WalkableJson = JsonSerializer.Serialize(walkable);
}
else
{
// Fallback for V1 layouts
MapWidth = 100;
MapHeight = 100;
WalkableJson = "[]";
}
// Serialize entity positions
PlayersJson = JsonSerializer.Serialize(
Dungeon.Simulation.Players.Values.Select(p => new
{
name = p.CharacterName,
x = p.X,
y = p.Y,
health = p.Health,
maxHealth = p.MaxHealth
})
);
MobsJson = JsonSerializer.Serialize(
Dungeon.Simulation.Mobs.Values.Select(m => new
{
name = m.Name,
x = m.X,
y = m.Y,
alive = m.IsAlive,
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss
})
);
}
public IActionResult OnGetStatus(Guid id)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon == null)
return new JsonResult(new { error = "Not found" }) { StatusCode = 404 };
return new JsonResult(new
{
playerCount = dungeon.Simulation.Players.Count,
mobsAlive = dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive),
duration = FormatDuration(DateTime.UtcNow - dungeon.CreatedAt),
players = dungeon.Simulation.Players.Values.Select(p => new
{
name = p.CharacterName,
x = p.X,
y = p.Y
}),
mobs = dungeon.Simulation.Mobs.Values.Where(m => m.IsAlive).Select(m => new
{
name = m.Name,
x = m.X,
y = m.Y,
alive = m.IsAlive,
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss
})
});
}
public IActionResult OnPostKillAllMobs(Guid id)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon != null)
{
foreach (var mob in dungeon.Simulation.Mobs.Values)
{
mob.Health = 0;
mob.IsAlive = false;
}
TempData["Message"] = "All mobs killed.";
}
return RedirectToPage(new { id });
}
public IActionResult OnPostCompleteDungeon(Guid id)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon != null)
{
dungeon.Simulation.ForceComplete();
TempData["Message"] = "Dungeon marked as completed.";
}
return RedirectToPage(new { id });
}
public IActionResult OnPostDelete(Guid id)
{
var result = _dungeonHandler.ForceCloseDungeon(id);
if (result)
{
TempData["Message"] = "Dungeon deleted.";
}
else
{
TempData["Error"] = "Failed to delete dungeon.";
}
return RedirectToPage("/Dungeons/Index");
}
private static string FormatDuration(TimeSpan duration)
{
if (duration.TotalHours >= 1)
return $"{(int)duration.TotalHours}h {duration.Minutes}m";
if (duration.TotalMinutes >= 1)
return $"{(int)duration.TotalMinutes}m {duration.Seconds}s";
return $"{(int)duration.TotalSeconds}s";
}
}