Mob Respawn p2
This commit is contained in:
@@ -363,6 +363,13 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
dungeonId = id;
|
dungeonId = id;
|
||||||
_log.LogInformation("Player {Name} joining existing dungeon {Id} (tier {Tier}, bracket {Min}-{Max}, {Players}/{Max} players)",
|
_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);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -776,7 +783,7 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
var emptyTime = DateTime.UtcNow - instance.LastPlayerActivity;
|
var emptyTime = DateTime.UtcNow - instance.LastPlayerActivity;
|
||||||
|
|
||||||
// If boss not killed and empty for 10+ minutes, persist to database
|
// 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);
|
_ = PersistDungeonAsync(instance, CancellationToken.None);
|
||||||
_dungeons.TryRemove(dungeonId, out _);
|
_dungeons.TryRemove(dungeonId, out _);
|
||||||
@@ -1787,6 +1794,13 @@ public sealed class DungeonHandler : IClientMessageHandler
|
|||||||
return;
|
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);
|
await AddPlayerToDungeonAsync(connection, session, instance, ct);
|
||||||
return;
|
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>
|
/// <summary>
|
||||||
/// Persist a dungeon to SQL (called when empty for 10 minutes)
|
/// Persist a dungeon to SQL (called when empty for 10 minutes)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user