boss handles
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user