Mob Respawn p2

This commit is contained in:
dingo
2025-12-18 14:50:23 -05:00
parent 49451f5f73
commit 62d5469fd2
+55 -1
View File
@@ -363,6 +363,13 @@ public sealed class DungeonHandler : IClientMessageHandler
dungeonId = id;
_log.LogInformation("Player {Name} joining existing dungeon {Id} (tier {Tier}, bracket {Min}-{Max}, {Players}/{Max} players)",
session.Character.Name, id, tier, bracketMin, bracketMax, dungeon.Simulation.Players.Count, maxPlayersPerDungeon);
// If dungeon is empty, respawn all mobs
if (dungeon.Simulation.Players.Count == 0)
{
RespawnAllMobs(dungeon);
_log.LogInformation("Respawned all mobs in dungeon {Id} (was empty when player joined via Quick Join)", id);
}
break;
}
}
@@ -776,7 +783,7 @@ public sealed class DungeonHandler : IClientMessageHandler
var emptyTime = DateTime.UtcNow - instance.LastPlayerActivity;
// If boss not killed and empty for 10+ minutes, persist to database
if (!instance.BossKilled && !instance.IsPersisted && emptyTime.TotalMinutes >= 10)
if (!instance.BossKilled && !instance.IsPersisted && emptyTime.TotalMinutes >= 5)
{
_ = PersistDungeonAsync(instance, CancellationToken.None);
_dungeons.TryRemove(dungeonId, out _);
@@ -1787,6 +1794,13 @@ public sealed class DungeonHandler : IClientMessageHandler
return;
}
// If dungeon is currently empty (no players), respawn all mobs
if (instance.Simulation.Players.Count == 0)
{
RespawnAllMobs(instance);
_log.LogInformation("Respawned all mobs in dungeon {Id} (was empty when player joined)", dungeonId);
}
await AddPlayerToDungeonAsync(connection, session, instance, ct);
return;
}
@@ -1979,6 +1993,46 @@ public sealed class DungeonHandler : IClientMessageHandler
}
}
/// <summary>
/// Respawn all mobs in a dungeon (called when dungeon was empty and player rejoins)
/// </summary>
private void RespawnAllMobs(DungeonInstance instance)
{
// Create a fresh simulation with the same parameters
var layout = DungeonGenerator.Generate(instance.Seed, instance.Tier);
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin);
// Copy fresh mobs to the existing simulation
instance.Simulation.Mobs.Clear();
foreach (var mob in freshSimulation.Mobs)
{
instance.Simulation.Mobs.TryAdd(mob.Key, mob.Value);
}
// Reset chest states (they respawn closed)
foreach (var chest in instance.Simulation.Chests.Values)
{
chest.IsOpened = false;
}
// Clear any loot chests (personal drops don't persist through respawn)
instance.Simulation.LootChests.Clear();
// Clear dropped items
instance.Simulation.DroppedItems.Clear();
// Reset portals (exit portal should be inactive until boss killed)
foreach (var portal in instance.Simulation.Portals.Values)
{
if (portal.Type == PortalType.Exit)
{
portal.IsActive = false;
}
}
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id}", instance.Simulation.Mobs.Count, instance.Id);
}
/// <summary>
/// Persist a dungeon to SQL (called when empty for 10 minutes)
/// </summary>