More Dungeon Features

This commit is contained in:
dingo
2026-01-10 21:27:08 -05:00
parent ae1951f876
commit 13ee594e29
3 changed files with 649 additions and 243 deletions
+72 -30
View File
@@ -32,7 +32,6 @@ public class ViewModel : AdminPageModel
{
Dungeon = _dungeonHandler.GetDungeon(id);
// Load mob definitions for spawn dropdown
MobDefinitions = await _db.DungeonMobDefinitions
.Where(m => m.IsEnabled)
.OrderBy(m => m.Name)
@@ -43,41 +42,38 @@ public class ViewModel : AdminPageModel
Duration = FormatDuration(DateTime.UtcNow - Dungeon.CreatedAt);
RoomCount = Dungeon.LayoutV2?.Rooms?.Count ?? Dungeon.Simulation.Layout.Rooms.Count;
// Get map dimensions
var layout = Dungeon.LayoutV2;
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
{
id = p.CharacterId.ToString(),
name = p.CharacterName,
x = p.X,
y = p.Y,
health = p.Health,
maxHealth = p.MaxHealth
maxHealth = p.MaxHealth,
mana = p.Mana,
maxMana = p.MaxMana,
isAlive = p.IsAlive,
isInCombat = p.IsInCombat
})
);
@@ -112,9 +108,16 @@ public class ViewModel : AdminPageModel
duration = FormatDuration(DateTime.UtcNow - dungeon.CreatedAt),
players = dungeon.Simulation.Players.Values.Select(p => new
{
id = p.CharacterId.ToString(),
name = p.CharacterName,
x = p.X,
y = p.Y
y = p.Y,
health = p.Health,
maxHealth = p.MaxHealth,
mana = p.Mana,
maxMana = p.MaxMana,
isAlive = p.IsAlive,
isInCombat = p.IsInCombat
}),
mobs = dungeon.Simulation.Mobs.Values.Select(m => new
{
@@ -133,6 +136,8 @@ public class ViewModel : AdminPageModel
});
}
// ==================== MOB HANDLERS ====================
public IActionResult OnPostKillMob(Guid id, int mobId)
{
var dungeon = _dungeonHandler.GetDungeon(id);
@@ -152,10 +157,8 @@ public class ViewModel : AdminPageModel
public IActionResult OnPostSpawnMob(Guid id, int mobDefId, float x, float y)
{
var mob = _dungeonHandler.SpawnMobInDungeon(id, mobDefId, x, y);
if (mob == null)
return new JsonResult(new { error = "Failed to spawn mob - dungeon or mob definition not found" }) { StatusCode = 400 };
return new JsonResult(new { error = "Failed to spawn mob" }) { StatusCode = 400 };
return new JsonResult(new { success = true, mobId = mob.Id });
}
@@ -169,36 +172,75 @@ public class ViewModel : AdminPageModel
mob.Health = 0;
mob.IsAlive = false;
}
TempData["Message"] = "All mobs killed.";
}
return RedirectToPage(new { id });
}
// ==================== TILE EDITING HANDLERS ====================
public IActionResult OnPostSetTile(Guid id, int x, int y, bool walkable)
{
var result = _dungeonHandler.SetTileWalkable(id, x, y, walkable);
return new JsonResult(new { success = result });
}
public IActionResult OnPostFillRect(Guid id, int x1, int y1, int x2, int y2, bool walkable)
{
var count = _dungeonHandler.FillTileRect(id, x1, y1, x2, y2, walkable);
return new JsonResult(new { success = count > 0, count });
}
// ==================== PLAYER HANDLERS ====================
public IActionResult OnPostHealPlayer(Guid id, string playerId)
{
if (!ulong.TryParse(playerId, out var charId))
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
var result = _dungeonHandler.HealPlayer(id, charId);
return new JsonResult(new { success = result });
}
public IActionResult OnPostTeleportPlayer(Guid id, string playerId, float x, float y)
{
if (!ulong.TryParse(playerId, out var charId))
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
var result = _dungeonHandler.TeleportPlayer(id, charId, x, y);
return new JsonResult(new { success = result });
}
public IActionResult OnPostKillPlayer(Guid id, string playerId)
{
if (!ulong.TryParse(playerId, out var charId))
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
var result = _dungeonHandler.KillPlayer(id, charId);
return new JsonResult(new { success = result });
}
public IActionResult OnPostSetGodMode(Guid id, string playerId, bool enabled)
{
if (!ulong.TryParse(playerId, out var charId))
return new JsonResult(new { error = "Invalid player ID" }) { StatusCode = 400 };
var result = _dungeonHandler.SetPlayerInvulnerable(id, charId, enabled);
return new JsonResult(new { success = result });
}
// ==================== DUNGEON HANDLERS ====================
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.";
}
_dungeonHandler.ForceCloseDungeon(id);
return RedirectToPage("/Dungeons/Index");
}