Admin Fix
This commit is contained in:
@@ -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<IActionResult> 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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user