new builder
This commit is contained in:
@@ -62,7 +62,7 @@ public sealed partial class DungeonHandler
|
||||
// Get active dungeons in player's bracket
|
||||
var availableDungeons = _dungeons.Values
|
||||
.Where(d => d.Simulation.Phase == DungeonPhase.Active &&
|
||||
!d.BossKilled)
|
||||
!d.AllBossesDefeated)
|
||||
.Select(d => new
|
||||
{
|
||||
id = d.Id.ToString(),
|
||||
@@ -75,6 +75,8 @@ public sealed partial class DungeonHandler
|
||||
playerCount = d.Simulation.Players.Count,
|
||||
maxPlayers = 20,
|
||||
isJoinWindowOpen = d.IsJoinWindowOpen,
|
||||
totalBosses = d.TotalBossCount,
|
||||
defeatedBosses = d.BossesDefeatedCount,
|
||||
createdAt = d.CreatedAt,
|
||||
secondsRemaining = d.IsJoinWindowOpen ? (int)(d.JoinWindowEnd - DateTime.UtcNow).TotalSeconds : 0
|
||||
})
|
||||
@@ -220,6 +222,7 @@ public sealed partial class DungeonHandler
|
||||
CreatorName = session.Character.Name,
|
||||
LayoutV2 = layoutV2 // Store V2 layout for visual tile data
|
||||
};
|
||||
instance.InitializeBossState(simulation.Mobs.Values.Count(m => m.Type == MobType.Boss));
|
||||
|
||||
_dungeons[dungeonId] = instance;
|
||||
_log.LogInformation("Player {Name} (Level {Level}) created dungeon {Id} (tier {Tier}, bracket {Min}-{Max})",
|
||||
@@ -268,7 +271,7 @@ public sealed partial class DungeonHandler
|
||||
}
|
||||
|
||||
// Check if boss killed
|
||||
if (instance.BossKilled)
|
||||
if (instance.AllBossesDefeated)
|
||||
{
|
||||
await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new { ok = false, error = "dungeon_cleared" }, ct);
|
||||
return;
|
||||
@@ -540,6 +543,7 @@ public sealed partial class DungeonHandler
|
||||
IsPersisted = false,
|
||||
LastPlayerActivity = DateTime.UtcNow
|
||||
};
|
||||
instance.InitializeBossState(simulation.Mobs.Values.Count(m => m.Type == MobType.Boss), persisted.BossKilled);
|
||||
|
||||
_log.LogInformation("Restored dungeon {Id} from persistence with fresh mobs", persisted.Id);
|
||||
return instance;
|
||||
@@ -557,6 +561,15 @@ public sealed partial class DungeonHandler
|
||||
/// </summary>
|
||||
private void RespawnAllMobs(DungeonInstance instance)
|
||||
{
|
||||
var defeatedBossMobIds = !instance.BossesRespawnOnReload
|
||||
? instance.GetDefeatedBossMobIdsSnapshot()
|
||||
: new HashSet<int>();
|
||||
|
||||
if (instance.BossesRespawnOnReload)
|
||||
{
|
||||
instance.ResetBossProgress();
|
||||
}
|
||||
|
||||
// Check if any existing mobs have carried player loot - don't respawn those
|
||||
var mobsWithLoot = instance.Simulation.Mobs.Values
|
||||
.Where(m => m.HasCarriedLoot)
|
||||
@@ -587,6 +600,15 @@ public sealed partial class DungeonHandler
|
||||
else
|
||||
{
|
||||
// Use the fresh mob
|
||||
if (!instance.BossesRespawnOnReload &&
|
||||
mob.Value.Type == MobType.Boss &&
|
||||
defeatedBossMobIds.Contains(mob.Key))
|
||||
{
|
||||
mob.Value.IsAlive = false;
|
||||
mob.Value.Health = 0;
|
||||
mob.Value.State = MobState.Dead;
|
||||
}
|
||||
|
||||
instance.Simulation.Mobs.TryAdd(mob.Key, mob.Value);
|
||||
}
|
||||
}
|
||||
@@ -612,8 +634,8 @@ public sealed partial class DungeonHandler
|
||||
}
|
||||
}
|
||||
|
||||
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id} (preserved {PreservedCount} with loot)",
|
||||
instance.Simulation.Mobs.Count, instance.Id, mobsWithLoot.Count);
|
||||
_log.LogDebug("Respawned {MobCount} mobs in dungeon {Id} (preserved {PreservedCount} with loot, bossesRespawn={BossesRespawn})",
|
||||
instance.Simulation.Mobs.Count, instance.Id, mobsWithLoot.Count, instance.BossesRespawnOnReload);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -621,7 +643,7 @@ public sealed partial class DungeonHandler
|
||||
/// </summary>
|
||||
private async Task PersistDungeonAsync(DungeonInstance instance, CancellationToken ct)
|
||||
{
|
||||
if (instance.IsPersisted || instance.BossKilled) return;
|
||||
if (instance.IsPersisted || instance.AllBossesDefeated) return;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -653,7 +675,7 @@ public sealed partial class DungeonHandler
|
||||
// Update existing record
|
||||
existing.LastActivity = instance.LastPlayerActivity;
|
||||
existing.PersistedAt = DateTime.UtcNow;
|
||||
existing.BossKilled = instance.BossKilled;
|
||||
existing.BossKilled = instance.AllBossesDefeated;
|
||||
existing.MobStateJson = System.Text.Json.JsonSerializer.Serialize(mobStates);
|
||||
existing.ChestStateJson = System.Text.Json.JsonSerializer.Serialize(chestStates);
|
||||
}
|
||||
@@ -672,7 +694,7 @@ public sealed partial class DungeonHandler
|
||||
CreatedAt = instance.CreatedAt,
|
||||
LastActivity = instance.LastPlayerActivity,
|
||||
PersistedAt = DateTime.UtcNow,
|
||||
BossKilled = instance.BossKilled,
|
||||
BossKilled = instance.AllBossesDefeated,
|
||||
MobStateJson = System.Text.Json.JsonSerializer.Serialize(mobStates),
|
||||
ChestStateJson = System.Text.Json.JsonSerializer.Serialize(chestStates)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user