diff --git a/Game/Dungeon/DungeonHandlerAdmin.cs b/Game/Dungeon/DungeonHandlerAdmin.cs
index ab60899..b7835b7 100644
--- a/Game/Dungeon/DungeonHandlerAdmin.cs
+++ b/Game/Dungeon/DungeonHandlerAdmin.cs
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
+using DataServer.Data.Entities;
namespace GameServer.Dungeon;
@@ -67,6 +68,89 @@ public partial class DungeonHandler
BossesKilled = dungeons.Count(d => d.BossKilled)
};
}
+
+ ///
+ /// Get the pre-built sprite config for a mob definition (admin use)
+ ///
+ public string? GetMobSpriteConfig(int mobDefinitionId)
+ {
+ if (_mobSpriteConfigs.TryGetValue(mobDefinitionId, out var config))
+ return config;
+ return null;
+ }
+
+ ///
+ /// Get a mob definition by ID (admin use)
+ ///
+ public DungeonMobDefinition? GetMobDefinition(int mobDefinitionId)
+ {
+ if (_mobDefinitions.TryGetValue(mobDefinitionId, out var def))
+ return def;
+ return null;
+ }
+
+ ///
+ /// Spawn a mob in a dungeon (admin action)
+ /// Uses the same sprite config system as dungeon generation
+ ///
+ public MobInstance? SpawnMobInDungeon(Guid dungeonId, int mobDefinitionId, float x, float y)
+ {
+ if (!_dungeons.TryGetValue(dungeonId, out var dungeon))
+ return null;
+
+ if (!_mobDefinitions.TryGetValue(mobDefinitionId, out var mobDef))
+ return null;
+
+ // Get sprite config from pre-built cache (same as dungeon generation uses)
+ string? spriteConfig = null;
+ if (_mobSpriteConfigs.TryGetValue(mobDefinitionId, out var cachedConfig) && !string.IsNullOrEmpty(cachedConfig))
+ {
+ spriteConfig = cachedConfig;
+ }
+ else
+ {
+ spriteConfig = mobDef.SpriteConfigJson;
+ }
+
+ // Generate unique mob ID
+ var maxId = dungeon.Simulation.Mobs.Keys.DefaultIfEmpty(0).Max();
+ var newMobId = maxId + 1;
+
+ // Use bracket-aware stat scaling
+ var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin);
+
+ var mob = new MobInstance
+ {
+ Id = newMobId,
+ DefinitionId = mobDef.Id,
+ Name = mobDef.Name,
+ Type = mobDef.Type,
+ X = x,
+ Y = y,
+ SpawnX = x,
+ SpawnY = y,
+ Health = stats.MaxHealth,
+ MaxHealth = stats.MaxHealth,
+ Mana = mobDef.BaseMana,
+ MaxMana = mobDef.BaseMana,
+ Stats = stats,
+ State = MobState.Idle,
+ StateTime = 0,
+ IsAlive = true,
+ Behavior = mobDef.Behavior,
+ PreferredRange = mobDef.PreferredRange,
+ FleeThreshold = mobDef.FleeThreshold,
+ SpriteConfigJson = spriteConfig,
+ TintColor = mobDef.TintColor ?? "#ffffff",
+ Scale = mobDef.Scale,
+ CurrentAnimation = "idle_down",
+ FacingDirection = "down"
+ };
+
+ dungeon.Simulation.Mobs[newMobId] = mob;
+
+ return mob;
+ }
}
///
diff --git a/Services/Admin/Pages/Dungeons/View.cshtml.cs b/Services/Admin/Pages/Dungeons/View.cshtml.cs
index a92aebb..4b94141 100644
--- a/Services/Admin/Pages/Dungeons/View.cshtml.cs
+++ b/Services/Admin/Pages/Dungeons/View.cshtml.cs
@@ -84,7 +84,7 @@ public class ViewModel : AdminPageModel
MobsJson = JsonSerializer.Serialize(
Dungeon.Simulation.Mobs.Values.Select(m => new
{
- id = m.Id.ToString(),
+ id = m.Id,
name = m.Name,
x = m.X,
y = m.Y,
@@ -93,7 +93,7 @@ public class ViewModel : AdminPageModel
alive = m.IsAlive,
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss,
type = m.Type.ToString(),
- state = m.State.ToString() ?? "Idle",
+ state = m.State.ToString(),
definitionId = m.DefinitionId
})
);
@@ -118,7 +118,7 @@ public class ViewModel : AdminPageModel
}),
mobs = dungeon.Simulation.Mobs.Values.Select(m => new
{
- id = m.Id.ToString(),
+ id = m.Id,
name = m.Name,
x = m.X,
y = m.Y,
@@ -127,22 +127,19 @@ public class ViewModel : AdminPageModel
alive = m.IsAlive,
isBoss = m.Type == DataServer.Data.Enums.MobType.Boss,
type = m.Type.ToString(),
- state = m.State.ToString() ?? "Idle",
+ state = m.State.ToString(),
definitionId = m.DefinitionId
})
});
}
- public IActionResult OnPostKillMob(Guid id, string mobId)
+ public IActionResult OnPostKillMob(Guid id, int mobId)
{
var dungeon = _dungeonHandler.GetDungeon(id);
if (dungeon == null)
return new JsonResult(new { error = "Dungeon not found" }) { StatusCode = 404 };
- if (!int.TryParse(mobId, out var mobInt))
- return new JsonResult(new { error = "Invalid mob ID" }) { StatusCode = 400 };
-
- if (dungeon.Simulation.Mobs.TryGetValue(mobInt, out var mob))
+ if (dungeon.Simulation.Mobs.TryGetValue(mobId, out var mob))
{
mob.Health = 0;
mob.IsAlive = false;
@@ -152,48 +149,12 @@ public class ViewModel : AdminPageModel
return new JsonResult(new { error = "Mob not found" }) { StatusCode = 404 };
}
- public async Task OnPostSpawnMob(Guid id, int mobDefId, float x, float y)
+ public IActionResult OnPostSpawnMob(Guid id, int mobDefId, float x, float y)
{
- var dungeon = _dungeonHandler.GetDungeon(id);
- if (dungeon == null)
- return new JsonResult(new { error = "Dungeon not found" }) { StatusCode = 404 };
+ var mob = _dungeonHandler.SpawnMobInDungeon(id, mobDefId, x, y);
- var mobDef = await _db.DungeonMobDefinitions.FindAsync(mobDefId);
- if (mobDef == null)
- return new JsonResult(new { error = "Mob definition not found" }) { StatusCode = 404 };
- int mobId = dungeon.Simulation.Mobs.Count + 1;
- var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin);
- var rng = new Random(dungeon.LayoutV2.Seed);
- // Create a new mob instance
- var mob = new MobInstance
- {
- Id = mobId,
- DefinitionId = mobDef.Id,
- Name = mobDef.Name,
- Type = mobDef.Type,
- X = x,
- Y = y,
- SpawnX = x,
- SpawnY = y,
- Health = stats.MaxHealth,
- MaxHealth = stats.MaxHealth,
- Mana = mobDef.BaseMana,
- MaxMana = mobDef.BaseMana,
- Stats = stats,
- State = MobState.Idle,
- StateTime = (float)(rng.NextDouble() * 3f),
- SpriteConfigJson = mobDef.SpriteConfigJson,
- TintColor = mobDef.TintColor,
- Scale = mobDef.Scale,
- Behavior = mobDef.Behavior,
- PreferredRange = mobDef.PreferredRange,
- FleeThreshold = mobDef.FleeThreshold,
- Phases = mobDef.Phases,
- CurrentAnimation = "idle_down",
- FacingDirection = "down"
- };
-
- dungeon.Simulation.Mobs[mob.Id] = mob;
+ if (mob == null)
+ return new JsonResult(new { error = "Failed to spawn mob - dungeon or mob definition not found" }) { StatusCode = 400 };
return new JsonResult(new { success = true, mobId = mob.Id });
}