Mob Respawn

This commit is contained in:
dingo
2025-12-18 13:06:40 -05:00
parent b346b02ae0
commit 49451f5f73
+10 -21
View File
@@ -1927,27 +1927,16 @@ public sealed class DungeonHandler : IClientMessageHandler
var layout = DungeonGenerator.Generate(persisted.Seed, persisted.Tier);
var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin);
// Restore mob state if available
if (!string.IsNullOrEmpty(persisted.MobStateJson))
{
var mobStates = System.Text.Json.JsonSerializer.Deserialize<List<PersistedMobState>>(persisted.MobStateJson);
if (mobStates != null)
{
foreach (var mobState in mobStates)
{
if (simulation.Mobs.TryGetValue(mobState.Id, out var mob))
{
mob.X = mobState.X;
mob.Y = mobState.Y;
mob.Health = mobState.Health;
mob.IsAlive = mobState.IsAlive;
if (!mob.IsAlive) mob.State = MobState.Dead;
}
}
}
}
// NOTE: We intentionally do NOT restore mob state here.
// When a dungeon is restored (all players left), ALL mobs respawn fresh.
// This gives the dungeon a "reset" behavior when empty.
// The mob state is preserved in persistence for potential future use,
// but on restore we use the freshly generated mobs from DungeonSimulation.
_log.LogInformation("Dungeon {Id} restored with all mobs respawned (was persisted with {MobCount} mob states)",
persisted.Id,
string.IsNullOrEmpty(persisted.MobStateJson) ? 0 : "saved");
// Restore chest state if available
// Restore chest state if available (chests stay opened)
if (!string.IsNullOrEmpty(persisted.ChestStateJson))
{
var chestStates = System.Text.Json.JsonSerializer.Deserialize<List<PersistedChestState>>(persisted.ChestStateJson);
@@ -1980,7 +1969,7 @@ public sealed class DungeonHandler : IClientMessageHandler
LastPlayerActivity = DateTime.UtcNow
};
_log.LogInformation("Restored dungeon {Id} from persistence", persisted.Id);
_log.LogInformation("Restored dungeon {Id} from persistence with fresh mobs", persisted.Id);
return instance;
}
catch (Exception ex)