boss handles

This commit is contained in:
dingo
2026-02-08 22:08:58 -05:00
parent 7b03b4139a
commit b5738e0db3
3 changed files with 135 additions and 8 deletions
+61
View File
@@ -1466,4 +1466,65 @@ public partial class DungeonSimulation
Console.WriteLine($"[DungeonSimulation] Summoned {mob.Name} (ID {mob.Id}) at ({x}, {y})");
}
/// <summary>
/// Recreate a persisted mob state that is not part of static layout spawns (for example, admin/runtime-spawned mobs).
/// </summary>
public bool TrySpawnMobFromPersistedState(PersistedMobState mobState)
{
if (!_mobDefinitions.TryGetValue(mobState.DefinitionId, out var mobDef))
return false;
var stats = mobDef.GetStatsForBracket(BracketMin);
string? spriteConfig = null;
if (_spriteConfigs != null && _spriteConfigs.TryGetValue(mobDef.Id, out var config) && !string.IsNullOrEmpty(config))
{
spriteConfig = config;
}
else
{
spriteConfig = mobDef.SpriteConfigJson;
}
var mob = new MobInstance
{
Id = mobState.Id,
DefinitionId = mobDef.Id,
Name = mobDef.Name,
X = mobState.X,
Y = mobState.Y,
SpawnX = mobState.X,
SpawnY = mobState.Y,
Health = mobState.IsAlive ? Math.Clamp(mobState.Health, 1, stats.MaxHealth) : 0,
MaxHealth = stats.MaxHealth,
Mana = mobDef.BaseMana,
MaxMana = mobDef.BaseMana,
IsAlive = mobState.IsAlive,
Type = mobDef.Type,
Behavior = mobDef.Behavior,
PreferredRange = mobDef.PreferredRange,
FleeThreshold = mobDef.FleeThreshold,
Stats = stats,
State = mobState.IsAlive ? MobState.Idle : MobState.Dead,
StateTime = 0,
SpriteConfigJson = spriteConfig,
TintColor = mobDef.TintColor,
Scale = mobDef.Scale,
CurrentAnimation = "idle_down",
FacingDirection = "down",
Phases = mobDef.Phases
};
InitializeMobAbilities(mob, mobDef, stats);
Mobs[mob.Id] = mob;
lock (_mobIdLock)
{
if (mob.Id >= _nextMobId)
_nextMobId = mob.Id + 1;
}
return true;
}
}