Ability fixes and cleanup
This commit is contained in:
@@ -47,9 +47,11 @@ public partial class DungeonSimulation
|
||||
|
||||
private int _nextDroppedItemId = 1;
|
||||
private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts
|
||||
private readonly object _mobIdLock = new();
|
||||
private readonly Dictionary<int, DungeonMobDefinition> _mobDefinitions;
|
||||
private readonly Dictionary<int, MobAbilityDefinition>? _abilityDefinitions;
|
||||
private readonly Dictionary<int, string?>? _spriteConfigs;
|
||||
private readonly Dictionary<int, MobAbilityAnimationMapping>? _abilityAnimationMappings;
|
||||
private readonly List<(int MobDefinitionId, float X, float Y, int Tier)> _pendingSummons = new();
|
||||
|
||||
public DungeonSimulation(
|
||||
@@ -58,7 +60,8 @@ public partial class DungeonSimulation
|
||||
Dictionary<int, DungeonMobDefinition> mobDefinitions,
|
||||
int bracketMin = 1,
|
||||
Dictionary<int, MobAbilityDefinition>? abilityDefinitions = null,
|
||||
Dictionary<int, string?>? spriteConfigs = null)
|
||||
Dictionary<int, string?>? spriteConfigs = null,
|
||||
Dictionary<int, MobAbilityAnimationMapping>? abilityAnimationMappings = null)
|
||||
{
|
||||
Layout = layout;
|
||||
Tier = tier;
|
||||
@@ -66,6 +69,7 @@ public partial class DungeonSimulation
|
||||
_mobDefinitions = mobDefinitions;
|
||||
_abilityDefinitions = abilityDefinitions;
|
||||
_spriteConfigs = spriteConfigs;
|
||||
_abilityAnimationMappings = abilityAnimationMappings;
|
||||
|
||||
SpawnMobs();
|
||||
InitializeChests();
|
||||
@@ -272,6 +276,7 @@ public partial class DungeonSimulation
|
||||
AnimationKey = "attack",
|
||||
DamageTypeKey = stats.DamageTypeKey
|
||||
},
|
||||
ResolvedAnimationKey = "attack",
|
||||
CooldownRemaining = 0,
|
||||
Priority = 1
|
||||
});
|
||||
@@ -434,9 +439,18 @@ public partial class DungeonSimulation
|
||||
float distance = Distance(mob.X, mob.Y, target.X, target.Y);
|
||||
bool isSummonAbility = ability.Definition.AbilityType is MobAbilityType.SummonSingle or MobAbilityType.SummonBulk;
|
||||
if (!isSummonAbility && ability.Definition.Range > 0 && distance > ability.Definition.Range) return;
|
||||
|
||||
int manaCost = Math.Max(0, ability.Definition.ManaCost);
|
||||
if (manaCost > 0)
|
||||
{
|
||||
if (mob.Mana < manaCost) return;
|
||||
mob.Mana -= manaCost;
|
||||
}
|
||||
|
||||
// Put ability on cooldown
|
||||
ability.CooldownRemaining = ability.Definition.Cooldown;
|
||||
|
||||
string animationKey = ResolveAbilityAnimationKey(mob, ability);
|
||||
|
||||
// Emit ability event for client animation
|
||||
_pendingAbilityEvents.Add(new AbilityEvent
|
||||
@@ -444,7 +458,7 @@ public partial class DungeonSimulation
|
||||
SourceType = EntityType.Mob,
|
||||
SourceId = mob.Id,
|
||||
AbilityKey = ability.Definition.Key,
|
||||
AnimationKey = ability.Definition.AnimationKey,
|
||||
AnimationKey = animationKey,
|
||||
TargetX = target.X,
|
||||
TargetY = target.Y,
|
||||
TargetId = (int)target.CharacterId
|
||||
@@ -574,6 +588,7 @@ public partial class DungeonSimulation
|
||||
{
|
||||
AbilityId = abilityDef.Id,
|
||||
Definition = abilityDef,
|
||||
ResolvedAnimationKey = ResolveMappedAnimationKey(assignment.Id, abilityDef),
|
||||
CooldownRemaining = 0,
|
||||
Priority = assignment.PriorityOverride ?? abilityDef.Priority,
|
||||
Phase = assignment.Phase,
|
||||
@@ -582,6 +597,32 @@ public partial class DungeonSimulation
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private string ResolveMappedAnimationKey(int abilityAssignmentId, MobAbilityDefinition abilityDef)
|
||||
{
|
||||
if (_abilityAnimationMappings != null &&
|
||||
_abilityAnimationMappings.TryGetValue(abilityAssignmentId, out var mapping) &&
|
||||
!string.IsNullOrWhiteSpace(mapping.AnimationKey))
|
||||
{
|
||||
return mapping.AnimationKey.Trim();
|
||||
}
|
||||
|
||||
return string.IsNullOrWhiteSpace(abilityDef.AnimationKey) ? "attack" : abilityDef.AnimationKey;
|
||||
}
|
||||
|
||||
private static string ResolveAbilityAnimationKey(MobInstance mob, MobAbilityState ability)
|
||||
{
|
||||
var key = string.IsNullOrWhiteSpace(ability.ResolvedAnimationKey)
|
||||
? ability.Definition.AnimationKey
|
||||
: ability.ResolvedAnimationKey;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
key = "attack";
|
||||
|
||||
key = key.Replace("[dir]", mob.FacingDirection, StringComparison.OrdinalIgnoreCase);
|
||||
key = key.Replace("{dir}", mob.FacingDirection, StringComparison.OrdinalIgnoreCase);
|
||||
return key;
|
||||
}
|
||||
|
||||
private void ProcessMeleeAbility(MobInstance mob, MobAbilityDefinition ability, PlayerInstance target)
|
||||
{
|
||||
@@ -1332,6 +1373,24 @@ public partial class DungeonSimulation
|
||||
_pendingSummons.Add((mobDefinitionId, x, y, tier));
|
||||
}
|
||||
|
||||
public int AllocateRuntimeMobId()
|
||||
{
|
||||
lock (_mobIdLock)
|
||||
{
|
||||
if (_nextMobId < 10000)
|
||||
{
|
||||
_nextMobId = 10000;
|
||||
}
|
||||
|
||||
while (Mobs.ContainsKey(_nextMobId))
|
||||
{
|
||||
_nextMobId++;
|
||||
}
|
||||
|
||||
return _nextMobId++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process all pending summon requests
|
||||
/// </summary>
|
||||
@@ -1374,7 +1433,7 @@ public partial class DungeonSimulation
|
||||
|
||||
var mob = new MobInstance
|
||||
{
|
||||
Id = _nextMobId++,
|
||||
Id = AllocateRuntimeMobId(),
|
||||
DefinitionId = mobDef.Id,
|
||||
Name = mobDef.Name,
|
||||
X = x,
|
||||
|
||||
Reference in New Issue
Block a user