Abilities
This commit is contained in:
@@ -46,9 +46,11 @@ public partial class DungeonSimulation
|
||||
private readonly List<ProjectileExpiredEvent> _pendingProjectileExpiredEvents = new();
|
||||
|
||||
private int _nextDroppedItemId = 1;
|
||||
private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts
|
||||
private readonly Dictionary<int, DungeonMobDefinition> _mobDefinitions;
|
||||
private readonly Dictionary<int, MobAbilityDefinition>? _abilityDefinitions;
|
||||
private readonly Dictionary<int, string?>? _spriteConfigs;
|
||||
private readonly List<(int MobDefinitionId, float X, float Y, int Tier)> _pendingSummons = new();
|
||||
|
||||
public DungeonSimulation(
|
||||
DungeonLayout layout,
|
||||
@@ -407,7 +409,10 @@ public partial class DungeonSimulation
|
||||
Phase = DungeonPhase.Cleared;
|
||||
SpawnExit();
|
||||
}
|
||||
|
||||
|
||||
// Process pending summons
|
||||
ProcessPendingSummons();
|
||||
|
||||
return new TickResult
|
||||
{
|
||||
DamageEvents = new List<DamageEvent>(_pendingDamageEvents),
|
||||
@@ -561,10 +566,11 @@ public partial class DungeonSimulation
|
||||
|
||||
private void UpdateProjectiles()
|
||||
{
|
||||
if (Projectiles.Count > 0)
|
||||
{
|
||||
Console.WriteLine($"[UpdateProjectiles] Updating {Projectiles.Count} projectiles. Mobs alive: {Mobs.Values.Count(m => m.IsAlive)}");
|
||||
}
|
||||
// Debug logging disabled
|
||||
// if (Projectiles.Count > 0)
|
||||
// {
|
||||
// Console.WriteLine($"[UpdateProjectiles] Updating {Projectiles.Count} projectiles. Mobs alive: {Mobs.Values.Count(m => m.IsAlive)}");
|
||||
// }
|
||||
|
||||
var toRemove = new List<int>();
|
||||
|
||||
@@ -1228,7 +1234,132 @@ public partial class DungeonSimulation
|
||||
float dy = y2 - y1;
|
||||
return MathF.Sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Request a mob to be summoned (will be processed at end of tick)
|
||||
/// </summary>
|
||||
public void RequestMobSummon(int mobDefinitionId, float x, float y, int tier)
|
||||
{
|
||||
_pendingSummons.Add((mobDefinitionId, x, y, tier));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process all pending summon requests
|
||||
/// </summary>
|
||||
private void ProcessPendingSummons()
|
||||
{
|
||||
if (_pendingSummons.Count == 0) return;
|
||||
|
||||
foreach (var summon in _pendingSummons)
|
||||
{
|
||||
SpawnSummonedMob(summon.MobDefinitionId, summon.X, summon.Y, summon.Tier);
|
||||
}
|
||||
|
||||
_pendingSummons.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn a summoned mob at runtime
|
||||
/// </summary>
|
||||
private void SpawnSummonedMob(int mobDefinitionId, float x, float y, int tier)
|
||||
{
|
||||
if (!_mobDefinitions.TryGetValue(mobDefinitionId, out var mobDef))
|
||||
{
|
||||
Console.WriteLine($"[DungeonSimulation] Cannot summon mob {mobDefinitionId} - definition not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Use bracket-aware stat scaling
|
||||
var stats = mobDef.GetStatsForBracket(BracketMin);
|
||||
|
||||
// Get sprite config
|
||||
string? spriteConfig = null;
|
||||
if (_spriteConfigs != null && _spriteConfigs.TryGetValue(mobDef.Id, out var config) && !string.IsNullOrEmpty(config))
|
||||
{
|
||||
spriteConfig = config;
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteConfig = mobDef.SpriteConfigJson;
|
||||
}
|
||||
|
||||
var mob = new MobInstance
|
||||
{
|
||||
Id = _nextMobId++,
|
||||
DefinitionId = mobDef.Id,
|
||||
Name = mobDef.Name,
|
||||
X = x,
|
||||
Y = y,
|
||||
SpawnX = x,
|
||||
SpawnY = y,
|
||||
Health = stats.MaxHealth,
|
||||
MaxHealth = stats.MaxHealth,
|
||||
Mana = mobDef.BaseMana,
|
||||
MaxMana = mobDef.BaseMana,
|
||||
IsAlive = true,
|
||||
Type = mobDef.Type,
|
||||
Behavior = mobDef.Behavior,
|
||||
PreferredRange = mobDef.PreferredRange,
|
||||
FleeThreshold = mobDef.FleeThreshold,
|
||||
Stats = stats,
|
||||
State = MobState.Idle,
|
||||
StateTime = 0,
|
||||
SpriteConfigJson = spriteConfig,
|
||||
TintColor = mobDef.TintColor,
|
||||
Scale = mobDef.Scale,
|
||||
CurrentAnimation = "idle_down",
|
||||
FacingDirection = "down",
|
||||
Phases = mobDef.Phases
|
||||
};
|
||||
|
||||
// Load abilities for this mob
|
||||
if (_abilityDefinitions != null && mobDef.AbilityAssignments != null)
|
||||
{
|
||||
foreach (var assignment in mobDef.AbilityAssignments.Where(a => a.IsEnabled))
|
||||
{
|
||||
if (_abilityDefinitions.TryGetValue(assignment.AbilityDefinitionId, out var abilityDef))
|
||||
{
|
||||
mob.Abilities.Add(new MobAbilityState
|
||||
{
|
||||
AbilityId = abilityDef.Id,
|
||||
Definition = abilityDef,
|
||||
CooldownRemaining = 0,
|
||||
Priority = assignment.PriorityOverride ?? abilityDef.Priority,
|
||||
Phase = assignment.Phase,
|
||||
MinHpPercent = assignment.MinHpPercent,
|
||||
MaxHpPercent = assignment.MaxHpPercent
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no abilities loaded, give a basic attack
|
||||
if (mob.Abilities.Count == 0)
|
||||
{
|
||||
mob.Abilities.Add(new MobAbilityState
|
||||
{
|
||||
AbilityId = 0,
|
||||
Definition = new MobAbilityDefinition
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Basic Attack",
|
||||
Key = "basic_attack",
|
||||
AbilityType = MobAbilityType.MeleeAttack,
|
||||
BaseDamage = stats.PhysicalDamage,
|
||||
Range = stats.AttackRange,
|
||||
Cooldown = 1f / stats.AttackSpeed,
|
||||
AnimationKey = "attack",
|
||||
DamageTypeKey = stats.DamageTypeKey
|
||||
},
|
||||
CooldownRemaining = 0,
|
||||
Priority = 1
|
||||
});
|
||||
}
|
||||
|
||||
Mobs[mob.Id] = mob;
|
||||
Console.WriteLine($"[DungeonSimulation] Summoned {mob.Name} (ID {mob.Id}) at ({x}, {y})");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user