187 lines
5.9 KiB
C#
187 lines
5.9 KiB
C#
using System.Collections.Concurrent;
|
|
using DataServer.Data.Entities;
|
|
|
|
namespace GameServer.Dungeon;
|
|
|
|
/// <summary>
|
|
/// Admin/management extensions for DungeonHandler
|
|
/// </summary>
|
|
public partial class DungeonHandler
|
|
{
|
|
/// <summary>
|
|
/// Get all active dungeon instances (for admin viewing)
|
|
/// </summary>
|
|
public IReadOnlyCollection<DungeonInstance> GetActiveDungeons()
|
|
{
|
|
return _dungeons.Values.ToList().AsReadOnly();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a specific dungeon by ID (for admin viewing)
|
|
/// </summary>
|
|
public DungeonInstance? GetDungeon(Guid id)
|
|
{
|
|
_dungeons.TryGetValue(id, out var dungeon);
|
|
return dungeon;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Force close a dungeon (admin action)
|
|
/// Removes all players and destroys the instance
|
|
/// </summary>
|
|
public bool ForceCloseDungeon(Guid dungeonId)
|
|
{
|
|
if (!_dungeons.TryGetValue(dungeonId, out var dungeon))
|
|
return false;
|
|
|
|
// Remove all players from the dungeon
|
|
foreach (var player in dungeon.Simulation.Players.Values.ToList())
|
|
{
|
|
try
|
|
{
|
|
// Send them back to town
|
|
// Note: This is a simplified version - in production you'd want to
|
|
// properly handle player state transitions
|
|
//dungeon.Simulation.RemovePlayer(player.CharacterId);
|
|
Console.WriteLine("Remove Player - Not Implemented.");
|
|
}
|
|
catch { /* Ignore errors during cleanup */ }
|
|
}
|
|
|
|
// Remove the dungeon
|
|
return _dungeons.TryRemove(dungeonId, out _);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get summary statistics for admin dashboard
|
|
/// </summary>
|
|
public DungeonStats GetStats()
|
|
{
|
|
var dungeons = _dungeons.Values.ToList();
|
|
|
|
return new DungeonStats
|
|
{
|
|
ActiveCount = dungeons.Count,
|
|
TotalPlayers = dungeons.Sum(d => d.Simulation.Players.Count),
|
|
TotalMobsAlive = dungeons.Sum(d => d.Simulation.Mobs.Values.Count(m => m.IsAlive)),
|
|
CompletedCount = dungeons.Count(d => d.Simulation.Phase == DungeonPhase.Cleared),
|
|
BossesKilled = dungeons.Count(d => d.BossKilled)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the pre-built sprite config for a mob definition (admin use)
|
|
/// </summary>
|
|
public string? GetMobSpriteConfig(int mobDefinitionId)
|
|
{
|
|
if (_mobSpriteConfigs.TryGetValue(mobDefinitionId, out var config))
|
|
return config;
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get a mob definition by ID (admin use)
|
|
/// </summary>
|
|
public DungeonMobDefinition? GetMobDefinition(int mobDefinitionId)
|
|
{
|
|
if (_mobDefinitions.TryGetValue(mobDefinitionId, out var def))
|
|
return def;
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Spawn a mob in a dungeon (admin action)
|
|
/// Uses the same sprite config system as dungeon generation
|
|
/// </summary>
|
|
public MobInstance? SpawnMobInDungeon(Guid dungeonId, int mobDefinitionId, float x, float y)
|
|
{
|
|
if (!_dungeons.TryGetValue(dungeonId, out var dungeon))
|
|
return null;
|
|
|
|
if (!_mobDefinitions.TryGetValue(mobDefinitionId, out var mobDef))
|
|
return null;
|
|
|
|
// Get sprite config from pre-built cache (same as dungeon generation uses)
|
|
string? spriteConfig = null;
|
|
if (_mobSpriteConfigs.TryGetValue(mobDefinitionId, out var cachedConfig) && !string.IsNullOrEmpty(cachedConfig))
|
|
{
|
|
spriteConfig = cachedConfig;
|
|
}
|
|
else
|
|
{
|
|
spriteConfig = mobDef.SpriteConfigJson;
|
|
}
|
|
|
|
// Generate unique mob ID
|
|
var maxId = dungeon.Simulation.Mobs.Keys.DefaultIfEmpty(0).Max();
|
|
var newMobId = maxId + 1;
|
|
|
|
// Use bracket-aware stat scaling
|
|
var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin);
|
|
|
|
var mob = new MobInstance
|
|
{
|
|
Id = newMobId,
|
|
DefinitionId = mobDef.Id,
|
|
Name = mobDef.Name,
|
|
Type = mobDef.Type,
|
|
X = x,
|
|
Y = y,
|
|
SpawnX = x,
|
|
SpawnY = y,
|
|
Health = stats.MaxHealth,
|
|
MaxHealth = stats.MaxHealth,
|
|
Mana = mobDef.BaseMana,
|
|
MaxMana = mobDef.BaseMana,
|
|
Stats = stats,
|
|
State = MobState.Idle,
|
|
StateTime = 0,
|
|
IsAlive = true,
|
|
Behavior = mobDef.Behavior,
|
|
PreferredRange = mobDef.PreferredRange,
|
|
FleeThreshold = mobDef.FleeThreshold,
|
|
SpriteConfigJson = spriteConfig,
|
|
TintColor = mobDef.TintColor ?? "#ffffff",
|
|
Scale = mobDef.Scale,
|
|
CurrentAnimation = "idle_down",
|
|
FacingDirection = "down"
|
|
};
|
|
|
|
// Add basic attack ability (same as DungeonSimulation fallback)
|
|
mob.Abilities.Add(new MobAbilityState
|
|
{
|
|
AbilityId = 0,
|
|
Definition = new DataServer.Data.Entities.MobAbilityDefinition
|
|
{
|
|
Id = 0,
|
|
Name = "Basic Attack",
|
|
Key = "basic_attack",
|
|
AbilityType = DataServer.Data.Enums.MobAbilityType.MeleeAttack,
|
|
BaseDamage = stats.PhysicalDamage,
|
|
Range = stats.AttackRange,
|
|
Cooldown = 1f / stats.AttackSpeed,
|
|
AnimationKey = "attack",
|
|
DamageTypeKey = stats.DamageTypeKey
|
|
},
|
|
CooldownRemaining = 0,
|
|
Priority = 1
|
|
});
|
|
|
|
dungeon.Simulation.Mobs[newMobId] = mob;
|
|
|
|
return mob;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Statistics for admin dashboard
|
|
/// </summary>
|
|
public class DungeonStats
|
|
{
|
|
public int ActiveCount { get; set; }
|
|
public int TotalPlayers { get; set; }
|
|
public int TotalMobsAlive { get; set; }
|
|
public int CompletedCount { get; set; }
|
|
public int BossesKilled { get; set; }
|
|
}
|