118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
namespace GameServer.Dungeon;
|
|
|
|
/// <summary>
|
|
/// Represents an active dungeon instance
|
|
/// </summary>
|
|
public class DungeonInstance
|
|
{
|
|
public Guid Id { get; set; }
|
|
public int Tier { get; set; }
|
|
public int Seed { get; set; }
|
|
public DungeonSimulation Simulation { get; set; } = null!;
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
public bool ClearedHandled { get; set; } = false;
|
|
|
|
// Level bracket system
|
|
public int LevelBracketMin { get; set; }
|
|
public int LevelBracketMax { get; set; }
|
|
public int CreatorLevel { get; set; }
|
|
public ulong CreatorCharacterId { get; set; }
|
|
public string CreatorName { get; set; } = "";
|
|
|
|
// V2 Layout with visual tiles (null if generated with V1)
|
|
public DungeonLayoutV2? LayoutV2 { get; set; }
|
|
|
|
// Auto-join window (5 minutes)
|
|
public DateTime JoinWindowEnd => CreatedAt.AddMinutes(5);
|
|
public bool IsJoinWindowOpen => DateTime.UtcNow < JoinWindowEnd;
|
|
|
|
// Persistence
|
|
public DateTime LastPlayerActivity { get; set; } = DateTime.UtcNow;
|
|
public bool IsPersisted { get; set; } = false;
|
|
public bool BossKilled { get; set; } = false;
|
|
public int TotalBossCount { get; set; } = 1;
|
|
public int BossesDefeatedCount { get; set; } = 0;
|
|
public bool BossesRespawnOnReload { get; set; } = false;
|
|
|
|
// Admin editing
|
|
public bool HasPendingTileUpdates { get; set; } = false;
|
|
private HashSet<int> _defeatedBossMobIds { get; } = new();
|
|
|
|
/// <summary>
|
|
/// Check if a player level is within the bracket range
|
|
/// </summary>
|
|
public bool IsLevelInBracket(int playerLevel)
|
|
{
|
|
return playerLevel >= LevelBracketMin && playerLevel <= LevelBracketMax;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculate level bracket from a player's level (brackets of 10: 1-10, 11-20, 21-30, etc.)
|
|
/// </summary>
|
|
public static (int min, int max) GetLevelBracket(int level)
|
|
{
|
|
// Bracket 1: 1-10, Bracket 2: 11-20, etc.
|
|
int bracketIndex = (level - 1) / 10;
|
|
int min = bracketIndex * 10 + 1;
|
|
int max = min + 9;
|
|
return (min, max);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the bracket number (1, 2, 3, etc.)
|
|
/// </summary>
|
|
public int BracketNumber => (LevelBracketMin - 1) / 10 + 1;
|
|
|
|
public bool AllBossesDefeated => TotalBossCount > 0 && BossesDefeatedCount >= TotalBossCount;
|
|
|
|
public void InitializeBossState(int totalBossCount, bool allBossesDefeated = false)
|
|
{
|
|
TotalBossCount = Math.Max(1, totalBossCount);
|
|
BossesDefeatedCount = allBossesDefeated ? TotalBossCount : 0;
|
|
_defeatedBossMobIds.Clear();
|
|
BossKilled = AllBossesDefeated;
|
|
}
|
|
|
|
public void RegisterBossSpawn(int mobId)
|
|
{
|
|
if (_defeatedBossMobIds.Contains(mobId))
|
|
return;
|
|
|
|
TotalBossCount = Math.Max(1, TotalBossCount + 1);
|
|
BossKilled = AllBossesDefeated;
|
|
}
|
|
|
|
public bool RegisterBossDefeat(int mobId)
|
|
{
|
|
if (_defeatedBossMobIds.Contains(mobId))
|
|
return false;
|
|
|
|
_defeatedBossMobIds.Add(mobId);
|
|
BossesDefeatedCount = Math.Min(TotalBossCount, BossesDefeatedCount + 1);
|
|
BossKilled = AllBossesDefeated;
|
|
return true;
|
|
}
|
|
|
|
public HashSet<int> GetDefeatedBossMobIdsSnapshot()
|
|
{
|
|
return new HashSet<int>(_defeatedBossMobIds);
|
|
}
|
|
|
|
public void SetDefeatedBossMobIds(IEnumerable<int> mobIds)
|
|
{
|
|
_defeatedBossMobIds.Clear();
|
|
foreach (var mobId in mobIds)
|
|
_defeatedBossMobIds.Add(mobId);
|
|
|
|
BossesDefeatedCount = Math.Min(TotalBossCount, _defeatedBossMobIds.Count);
|
|
BossKilled = AllBossesDefeated;
|
|
}
|
|
|
|
public void ResetBossProgress()
|
|
{
|
|
BossesDefeatedCount = 0;
|
|
_defeatedBossMobIds.Clear();
|
|
BossKilled = false;
|
|
}
|
|
}
|