Ability fixes and cleanup
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
# Ability System Review (Dungeon)
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
- Files reviewed: `Game/Dungeon/MobAI.cs`, `Game/Dungeon/DungeonSimulation.cs`, `Game/Dungeon/DungeonHandler.cs`, `Game/Dungeon/DungeonHandlerAdmin.cs`.
|
||||||
|
- Goal: document what works, what is missing, and the plan for per-ability animation binding when assigning abilities to mobs.
|
||||||
|
|
||||||
|
## How It Currently Works
|
||||||
|
1. Mob definitions and ability assignments are loaded into cache in `DungeonHandler` (`RefreshMobCacheAsync`).
|
||||||
|
2. When a dungeon simulation is created, each spawned mob gets runtime `MobAbilityState` entries from `MobAbilityAssignment`.
|
||||||
|
3. During ticks, mobs in `MobState.Attacking` call `ProcessMobAbility`.
|
||||||
|
4. `ProcessMobAbility` selects highest-priority available ability and routes to the implementation by `MobAbilityType`.
|
||||||
|
5. Ability visuals are emitted as `AbilityEvent` and now sent to clients in dungeon state packets (`events.abilities`).
|
||||||
|
|
||||||
|
## Ability Type Coverage
|
||||||
|
|
||||||
|
### Implemented in `DungeonSimulation.ProcessMobAbility`
|
||||||
|
- `MeleeAttack`
|
||||||
|
- `Cleave`
|
||||||
|
- `ProjectileSingle`
|
||||||
|
- `ProjectileAoe`
|
||||||
|
- `GroundAoe`
|
||||||
|
- `ConeAttack`
|
||||||
|
- `SummonSingle`
|
||||||
|
- `SummonBulk`
|
||||||
|
- `Poison`
|
||||||
|
- `Bleed`
|
||||||
|
- `Burn`
|
||||||
|
- `Stun`
|
||||||
|
- `Slow`
|
||||||
|
- `Root`
|
||||||
|
- `Fear`
|
||||||
|
- `Knockback`
|
||||||
|
- `Pull`
|
||||||
|
- `HazardZone`
|
||||||
|
|
||||||
|
### Declared in enum but not executed in `ProcessMobAbility`
|
||||||
|
- `HealSelf`
|
||||||
|
- `HealAlly`
|
||||||
|
- `HealAoe`
|
||||||
|
- `Silence` (status builder exists, but switch does not route this type)
|
||||||
|
- `BuffSelf`
|
||||||
|
- `BuffAllies`
|
||||||
|
- `Debuff`
|
||||||
|
- `Enrage`
|
||||||
|
- `Shield`
|
||||||
|
- `Charge`
|
||||||
|
- `Teleport`
|
||||||
|
- `Retreat`
|
||||||
|
- `PhaseChange`
|
||||||
|
|
||||||
|
## Known Gaps / Risks
|
||||||
|
- Healer AI can enter `MobState.Healing`, but ability execution currently only runs when state is `MobState.Attacking`.
|
||||||
|
- `Targeting` metadata on ability definitions is currently not used in runtime targeting logic.
|
||||||
|
- Player ability-cast pipeline is not present in dungeon simulation right now (player flow is basic attack), so player-ability mana enforcement is pending until player ability execution exists.
|
||||||
|
|
||||||
|
## Bonelord / Summon Issue Notes
|
||||||
|
- Root cause for disappearing admin-spawned boss after cast: runtime mob ID collision risk between admin-spawned IDs and summoned IDs.
|
||||||
|
- Fix approach implemented: centralized runtime ID allocation for both admin spawns and summons.
|
||||||
|
|
||||||
|
## Plan: Ability Animation Binding on Mob Ability Assignment
|
||||||
|
1. Add optional mapping from `MobAbilityAssignment` to animation key.
|
||||||
|
2. Resolve animation key for each runtime ability at load:
|
||||||
|
- mapping override if present
|
||||||
|
- else ability definition animation
|
||||||
|
- else `attack`
|
||||||
|
3. Support directional placeholders (`[dir]` / `{dir}`) at cast time.
|
||||||
|
4. Emit resolved animation key in ability events.
|
||||||
|
5. Admin UX: when assigning ability, optionally choose animation key from assigned mob animations.
|
||||||
|
6. Show assigned/resolved animation in mob ability table for transparency.
|
||||||
|
|
||||||
|
## Implementation Checklist
|
||||||
|
- [x] Load `mob_ability_animation_mappings` into dungeon mob cache.
|
||||||
|
- [x] Pass ability-animation mappings into all `DungeonSimulation` constructors.
|
||||||
|
- [x] Resolve mapped animation key into runtime `MobAbilityState`.
|
||||||
|
- [x] Support `[dir]` / `{dir}` replacement when emitting ability animation key.
|
||||||
|
- [x] Include ability events in outbound dungeon state payload (`events.abilities`).
|
||||||
|
- [x] Enforce mob ability mana costs before casting.
|
||||||
|
- [x] Add admin UI support to select optional animation key when assigning a mob ability.
|
||||||
|
- [x] Display ability animation (and override marker) in mob ability list.
|
||||||
|
- [x] Remove ability-animation mappings when removing an ability assignment.
|
||||||
|
- [x] Fix runtime mob ID allocation so admin spawns and summons cannot collide.
|
||||||
|
- [ ] Enforce mana for **player-cast abilities** once player ability casting exists in dungeon runtime.
|
||||||
@@ -204,7 +204,7 @@ public sealed partial class DungeonHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs);
|
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings);
|
||||||
|
|
||||||
var instance = new DungeonInstance
|
var instance = new DungeonInstance
|
||||||
{
|
{
|
||||||
@@ -497,7 +497,7 @@ public sealed partial class DungeonHandler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var layout = DungeonGenerator.Generate(persisted.Seed, persisted.Tier);
|
var layout = DungeonGenerator.Generate(persisted.Seed, persisted.Tier);
|
||||||
var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin, _abilityDefinitions, _mobSpriteConfigs);
|
var simulation = new DungeonSimulation(layout, persisted.Tier, _mobDefinitions, persisted.LevelBracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings);
|
||||||
|
|
||||||
// NOTE: We intentionally do NOT restore mob state here.
|
// NOTE: We intentionally do NOT restore mob state here.
|
||||||
// When a dungeon is restored (all players left), ALL mobs respawn fresh.
|
// When a dungeon is restored (all players left), ALL mobs respawn fresh.
|
||||||
@@ -571,7 +571,7 @@ public sealed partial class DungeonHandler
|
|||||||
// Using DungeonGenerator.Generate() would create a V1 layout which has different
|
// Using DungeonGenerator.Generate() would create a V1 layout which has different
|
||||||
// room geometry than V2/V3, causing mobs to spawn in wrong positions.
|
// room geometry than V2/V3, causing mobs to spawn in wrong positions.
|
||||||
var layout = instance.Simulation.Layout;
|
var layout = instance.Simulation.Layout;
|
||||||
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin, _abilityDefinitions, _mobSpriteConfigs);
|
var freshSimulation = new DungeonSimulation(layout, instance.Tier, _mobDefinitions, instance.LevelBracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings);
|
||||||
|
|
||||||
// Clear and rebuild mobs, keeping those with loot
|
// Clear and rebuild mobs, keeping those with loot
|
||||||
instance.Simulation.Mobs.Clear();
|
instance.Simulation.Mobs.Clear();
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public sealed partial class DungeonHandler
|
|||||||
|
|
||||||
_abilityDefinitions = abilities.ToDictionary(a => a.Id);
|
_abilityDefinitions = abilities.ToDictionary(a => a.Id);
|
||||||
|
|
||||||
|
var abilityAnimationMappings = await db.Set<MobAbilityAnimationMapping>()
|
||||||
|
.ToListAsync();
|
||||||
|
_abilityAnimationMappings = abilityAnimationMappings.ToDictionary(m => m.AbilityAssignmentId);
|
||||||
|
|
||||||
// Build sprite configs from animation assignments
|
// Build sprite configs from animation assignments
|
||||||
var spriteConfigBuilder = new MobSpriteConfigBuilder(db);
|
var spriteConfigBuilder = new MobSpriteConfigBuilder(db);
|
||||||
_mobSpriteConfigs = await spriteConfigBuilder.BuildSpriteConfigsAsync(mobs.Select(m => m.Id));
|
_mobSpriteConfigs = await spriteConfigBuilder.BuildSpriteConfigsAsync(mobs.Select(m => m.Id));
|
||||||
@@ -50,10 +54,11 @@ public sealed partial class DungeonHandler
|
|||||||
var assignmentCount = await db.Set<MobAnimationAssignment>().CountAsync();
|
var assignmentCount = await db.Set<MobAnimationAssignment>().CountAsync();
|
||||||
var abilityAssignmentsCount = mobs.Sum(m => m.AbilityAssignments?.Count ?? 0);
|
var abilityAssignmentsCount = mobs.Sum(m => m.AbilityAssignments?.Count ?? 0);
|
||||||
_log.LogInformation(
|
_log.LogInformation(
|
||||||
"Refreshed mob cache: {MobCount} mobs, {AbilityCount} abilities, {AbilityAssignments} ability assignments, {AssignmentCount} animation assignments",
|
"Refreshed mob cache: {MobCount} mobs, {AbilityCount} abilities, {AbilityAssignments} ability assignments, {AbilityAnimationMappings} ability animation mappings, {AssignmentCount} animation assignments",
|
||||||
mobs.Count,
|
mobs.Count,
|
||||||
_abilityDefinitions.Count,
|
_abilityDefinitions.Count,
|
||||||
abilityAssignmentsCount,
|
abilityAssignmentsCount,
|
||||||
|
_abilityAnimationMappings.Count,
|
||||||
assignmentCount);
|
assignmentCount);
|
||||||
|
|
||||||
if (abilityAssignmentsCount > 0)
|
if (abilityAssignmentsCount > 0)
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
// Mob definitions cache
|
// Mob definitions cache
|
||||||
private Dictionary<int, DungeonMobDefinition> _mobDefinitions = new();
|
private Dictionary<int, DungeonMobDefinition> _mobDefinitions = new();
|
||||||
private Dictionary<int, MobAbilityDefinition> _abilityDefinitions = new();
|
private Dictionary<int, MobAbilityDefinition> _abilityDefinitions = new();
|
||||||
|
private Dictionary<int, MobAbilityAnimationMapping> _abilityAnimationMappings = new();
|
||||||
private Dictionary<int, string?> _mobSpriteConfigs = new(); // MobDefinitionId -> SpriteConfig JSON
|
private Dictionary<int, string?> _mobSpriteConfigs = new(); // MobDefinitionId -> SpriteConfig JSON
|
||||||
private bool _initialized = false;
|
private bool _initialized = false;
|
||||||
|
|
||||||
@@ -678,7 +679,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs);
|
var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, _abilityDefinitions, _mobSpriteConfigs, _abilityAnimationMappings);
|
||||||
|
|
||||||
instance = new DungeonInstance
|
instance = new DungeonInstance
|
||||||
{
|
{
|
||||||
@@ -1531,7 +1532,6 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
{
|
{
|
||||||
_ = HandleDungeonClearedAsync(session);
|
_ = HandleDungeonClearedAsync(session);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var session in playersInDungeon)
|
foreach (var session in playersInDungeon)
|
||||||
@@ -2891,6 +2891,16 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
x = e.X,
|
x = e.X,
|
||||||
y = e.Y,
|
y = e.Y,
|
||||||
reason = e.Reason
|
reason = e.Reason
|
||||||
|
}),
|
||||||
|
abilities = tickResult.AbilityEvents.Select(e => new
|
||||||
|
{
|
||||||
|
sourceType = e.SourceType.ToString().ToLower(),
|
||||||
|
sourceId = e.SourceId,
|
||||||
|
abilityKey = e.AbilityKey,
|
||||||
|
animationKey = e.AnimationKey,
|
||||||
|
targetX = e.TargetX,
|
||||||
|
targetY = e.TargetY,
|
||||||
|
targetId = e.TargetId
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -2919,10 +2929,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
|||||||
{
|
{
|
||||||
_log.LogInformation("Dungeon cleared! Player {Name} can now exit via portal", session.Character.Name);
|
_log.LogInformation("Dungeon cleared! Player {Name} can now exit via portal", session.Character.Name);
|
||||||
|
|
||||||
// Send dungeon cleared notification (but don't force exit)
|
// Send dungeon cleared notification on dedicated opcode.
|
||||||
await SendAsync(session.Connection, DungeonOpCodes.DUNGEON_STATE, new
|
// Full world state still flows through regular DUNGEON_STATE packets.
|
||||||
|
await SendAsync(session.Connection, DungeonOpCodes.DUNGEON_CLEARED, new
|
||||||
{
|
{
|
||||||
phase = "cleared",
|
|
||||||
message = "Dungeon cleared! Use the portal to exit."
|
message = "Dungeon cleared! Use the portal to exit."
|
||||||
}, CancellationToken.None);
|
}, CancellationToken.None);
|
||||||
|
|
||||||
|
|||||||
@@ -134,8 +134,7 @@ public partial class DungeonHandler
|
|||||||
else
|
else
|
||||||
spriteConfig = mobDef.SpriteConfigJson;
|
spriteConfig = mobDef.SpriteConfigJson;
|
||||||
|
|
||||||
var maxId = dungeon.Simulation.Mobs.Keys.DefaultIfEmpty(0).Max();
|
var newMobId = dungeon.Simulation.AllocateRuntimeMobId();
|
||||||
var newMobId = maxId + 1;
|
|
||||||
var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin);
|
var stats = mobDef.GetStatsForBracket(dungeon.LevelBracketMin);
|
||||||
|
|
||||||
var mob = new MobInstance
|
var mob = new MobInstance
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ public partial class DungeonSimulation
|
|||||||
|
|
||||||
private int _nextDroppedItemId = 1;
|
private int _nextDroppedItemId = 1;
|
||||||
private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts
|
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, DungeonMobDefinition> _mobDefinitions;
|
||||||
private readonly Dictionary<int, MobAbilityDefinition>? _abilityDefinitions;
|
private readonly Dictionary<int, MobAbilityDefinition>? _abilityDefinitions;
|
||||||
private readonly Dictionary<int, string?>? _spriteConfigs;
|
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();
|
private readonly List<(int MobDefinitionId, float X, float Y, int Tier)> _pendingSummons = new();
|
||||||
|
|
||||||
public DungeonSimulation(
|
public DungeonSimulation(
|
||||||
@@ -58,7 +60,8 @@ public partial class DungeonSimulation
|
|||||||
Dictionary<int, DungeonMobDefinition> mobDefinitions,
|
Dictionary<int, DungeonMobDefinition> mobDefinitions,
|
||||||
int bracketMin = 1,
|
int bracketMin = 1,
|
||||||
Dictionary<int, MobAbilityDefinition>? abilityDefinitions = null,
|
Dictionary<int, MobAbilityDefinition>? abilityDefinitions = null,
|
||||||
Dictionary<int, string?>? spriteConfigs = null)
|
Dictionary<int, string?>? spriteConfigs = null,
|
||||||
|
Dictionary<int, MobAbilityAnimationMapping>? abilityAnimationMappings = null)
|
||||||
{
|
{
|
||||||
Layout = layout;
|
Layout = layout;
|
||||||
Tier = tier;
|
Tier = tier;
|
||||||
@@ -66,6 +69,7 @@ public partial class DungeonSimulation
|
|||||||
_mobDefinitions = mobDefinitions;
|
_mobDefinitions = mobDefinitions;
|
||||||
_abilityDefinitions = abilityDefinitions;
|
_abilityDefinitions = abilityDefinitions;
|
||||||
_spriteConfigs = spriteConfigs;
|
_spriteConfigs = spriteConfigs;
|
||||||
|
_abilityAnimationMappings = abilityAnimationMappings;
|
||||||
|
|
||||||
SpawnMobs();
|
SpawnMobs();
|
||||||
InitializeChests();
|
InitializeChests();
|
||||||
@@ -272,6 +276,7 @@ public partial class DungeonSimulation
|
|||||||
AnimationKey = "attack",
|
AnimationKey = "attack",
|
||||||
DamageTypeKey = stats.DamageTypeKey
|
DamageTypeKey = stats.DamageTypeKey
|
||||||
},
|
},
|
||||||
|
ResolvedAnimationKey = "attack",
|
||||||
CooldownRemaining = 0,
|
CooldownRemaining = 0,
|
||||||
Priority = 1
|
Priority = 1
|
||||||
});
|
});
|
||||||
@@ -434,9 +439,18 @@ public partial class DungeonSimulation
|
|||||||
float distance = Distance(mob.X, mob.Y, target.X, target.Y);
|
float distance = Distance(mob.X, mob.Y, target.X, target.Y);
|
||||||
bool isSummonAbility = ability.Definition.AbilityType is MobAbilityType.SummonSingle or MobAbilityType.SummonBulk;
|
bool isSummonAbility = ability.Definition.AbilityType is MobAbilityType.SummonSingle or MobAbilityType.SummonBulk;
|
||||||
if (!isSummonAbility && ability.Definition.Range > 0 && distance > ability.Definition.Range) return;
|
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
|
// Put ability on cooldown
|
||||||
ability.CooldownRemaining = ability.Definition.Cooldown;
|
ability.CooldownRemaining = ability.Definition.Cooldown;
|
||||||
|
|
||||||
|
string animationKey = ResolveAbilityAnimationKey(mob, ability);
|
||||||
|
|
||||||
// Emit ability event for client animation
|
// Emit ability event for client animation
|
||||||
_pendingAbilityEvents.Add(new AbilityEvent
|
_pendingAbilityEvents.Add(new AbilityEvent
|
||||||
@@ -444,7 +458,7 @@ public partial class DungeonSimulation
|
|||||||
SourceType = EntityType.Mob,
|
SourceType = EntityType.Mob,
|
||||||
SourceId = mob.Id,
|
SourceId = mob.Id,
|
||||||
AbilityKey = ability.Definition.Key,
|
AbilityKey = ability.Definition.Key,
|
||||||
AnimationKey = ability.Definition.AnimationKey,
|
AnimationKey = animationKey,
|
||||||
TargetX = target.X,
|
TargetX = target.X,
|
||||||
TargetY = target.Y,
|
TargetY = target.Y,
|
||||||
TargetId = (int)target.CharacterId
|
TargetId = (int)target.CharacterId
|
||||||
@@ -574,6 +588,7 @@ public partial class DungeonSimulation
|
|||||||
{
|
{
|
||||||
AbilityId = abilityDef.Id,
|
AbilityId = abilityDef.Id,
|
||||||
Definition = abilityDef,
|
Definition = abilityDef,
|
||||||
|
ResolvedAnimationKey = ResolveMappedAnimationKey(assignment.Id, abilityDef),
|
||||||
CooldownRemaining = 0,
|
CooldownRemaining = 0,
|
||||||
Priority = assignment.PriorityOverride ?? abilityDef.Priority,
|
Priority = assignment.PriorityOverride ?? abilityDef.Priority,
|
||||||
Phase = assignment.Phase,
|
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)
|
private void ProcessMeleeAbility(MobInstance mob, MobAbilityDefinition ability, PlayerInstance target)
|
||||||
{
|
{
|
||||||
@@ -1332,6 +1373,24 @@ public partial class DungeonSimulation
|
|||||||
_pendingSummons.Add((mobDefinitionId, x, y, tier));
|
_pendingSummons.Add((mobDefinitionId, x, y, tier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int AllocateRuntimeMobId()
|
||||||
|
{
|
||||||
|
lock (_mobIdLock)
|
||||||
|
{
|
||||||
|
if (_nextMobId < 10000)
|
||||||
|
{
|
||||||
|
_nextMobId = 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (Mobs.ContainsKey(_nextMobId))
|
||||||
|
{
|
||||||
|
_nextMobId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _nextMobId++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process all pending summon requests
|
/// Process all pending summon requests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1374,7 +1433,7 @@ public partial class DungeonSimulation
|
|||||||
|
|
||||||
var mob = new MobInstance
|
var mob = new MobInstance
|
||||||
{
|
{
|
||||||
Id = _nextMobId++,
|
Id = AllocateRuntimeMobId(),
|
||||||
DefinitionId = mobDef.Id,
|
DefinitionId = mobDef.Id,
|
||||||
Name = mobDef.Name,
|
Name = mobDef.Name,
|
||||||
X = x,
|
X = x,
|
||||||
|
|||||||
@@ -544,6 +544,10 @@ public static class MobAI
|
|||||||
{
|
{
|
||||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.02f * deltaTime));
|
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.02f * deltaTime));
|
||||||
}
|
}
|
||||||
|
if (mob.Mana < mob.MaxMana)
|
||||||
|
{
|
||||||
|
mob.Mana = Math.Min(mob.MaxMana, mob.Mana + (int)(mob.MaxMana * 0.02f * deltaTime));
|
||||||
|
}
|
||||||
|
|
||||||
// State machine for wandering
|
// State machine for wandering
|
||||||
// States: Idle (standing still) -> Moving to wander target -> Idle again
|
// States: Idle (standing still) -> Moving to wander target -> Idle again
|
||||||
@@ -635,6 +639,10 @@ public static class MobAI
|
|||||||
{
|
{
|
||||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.05f * deltaTime));
|
mob.Health = Math.Min(mob.MaxHealth, mob.Health + (int)(mob.MaxHealth * 0.05f * deltaTime));
|
||||||
}
|
}
|
||||||
|
if (mob.Mana < mob.MaxMana)
|
||||||
|
{
|
||||||
|
mob.Mana = Math.Min(mob.MaxMana, mob.Mana + (int)(mob.MaxMana * 0.05f * deltaTime));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class MobAbilityState
|
|||||||
{
|
{
|
||||||
public int AbilityId { get; set; }
|
public int AbilityId { get; set; }
|
||||||
public MobAbilityDefinition Definition { get; set; } = null!;
|
public MobAbilityDefinition Definition { get; set; } = null!;
|
||||||
|
public string ResolvedAnimationKey { get; set; } = "attack";
|
||||||
public float CooldownRemaining { get; set; }
|
public float CooldownRemaining { get; set; }
|
||||||
public int Priority { get; set; }
|
public int Priority { get; set; }
|
||||||
public int Phase { get; set; }
|
public int Phase { get; set; }
|
||||||
|
|||||||
@@ -384,6 +384,7 @@
|
|||||||
<tr class="border-b border-gray-700">
|
<tr class="border-b border-gray-700">
|
||||||
<th class="py-2 text-left text-gray-400">Ability</th>
|
<th class="py-2 text-left text-gray-400">Ability</th>
|
||||||
<th class="py-2 text-left text-gray-400">Type</th>
|
<th class="py-2 text-left text-gray-400">Type</th>
|
||||||
|
<th class="py-2 text-left text-gray-400">Animation</th>
|
||||||
<th class="py-2 text-left text-gray-400">Damage</th>
|
<th class="py-2 text-left text-gray-400">Damage</th>
|
||||||
<th class="py-2 text-left text-gray-400">Range</th>
|
<th class="py-2 text-left text-gray-400">Range</th>
|
||||||
<th class="py-2 text-left text-gray-400">Cooldown</th>
|
<th class="py-2 text-left text-gray-400">Cooldown</th>
|
||||||
@@ -396,9 +397,20 @@
|
|||||||
@foreach (var assignment in Model.MobAbilities)
|
@foreach (var assignment in Model.MobAbilities)
|
||||||
{
|
{
|
||||||
var ability = assignment.AbilityDefinition;
|
var ability = assignment.AbilityDefinition;
|
||||||
|
var hasMappedAnimation = Model.AbilityAnimationByAssignmentId.TryGetValue(assignment.Id, out var mappedAnimation);
|
||||||
|
var resolvedAnimation = hasMappedAnimation
|
||||||
|
? mappedAnimation
|
||||||
|
: (!string.IsNullOrWhiteSpace(ability?.AnimationKey) ? ability!.AnimationKey : "attack");
|
||||||
<tr class="hover:bg-gray-800/50">
|
<tr class="hover:bg-gray-800/50">
|
||||||
<td class="py-3 text-white font-medium">@ability?.Name</td>
|
<td class="py-3 text-white font-medium">@ability?.Name</td>
|
||||||
<td class="py-3 text-gray-300">@ability?.AbilityType</td>
|
<td class="py-3 text-gray-300">@ability?.AbilityType</td>
|
||||||
|
<td class="py-3 text-gray-300">
|
||||||
|
@resolvedAnimation
|
||||||
|
@if (hasMappedAnimation)
|
||||||
|
{
|
||||||
|
<span class="ml-1 text-xs text-cyan-400">(override)</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
<td class="py-3 text-gray-300">@ability?.BaseDamage</td>
|
<td class="py-3 text-gray-300">@ability?.BaseDamage</td>
|
||||||
<td class="py-3 text-gray-300">@ability?.Range</td>
|
<td class="py-3 text-gray-300">@ability?.Range</td>
|
||||||
<td class="py-3 text-gray-300">@ability?.Cooldown.ToString("0.#")s</td>
|
<td class="py-3 text-gray-300">@ability?.Cooldown.ToString("0.#")s</td>
|
||||||
@@ -475,6 +487,20 @@
|
|||||||
<label class="label">Priority Override (0 = use default)</label>
|
<label class="label">Priority Override (0 = use default)</label>
|
||||||
<input type="number" name="priority" value="0" class="input" min="0" />
|
<input type="number" name="priority" value="0" class="input" min="0" />
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Animation (optional override)</label>
|
||||||
|
<select name="animationKey" class="input">
|
||||||
|
<option value="">Use ability default</option>
|
||||||
|
@foreach (var key in Model.AvailableAbilityAnimationKeys)
|
||||||
|
{
|
||||||
|
<option value="@key">@key</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
@if (!Model.AvailableAbilityAnimationKeys.Any())
|
||||||
|
{
|
||||||
|
<p class="text-xs text-amber-400 mt-1">No mob animations assigned yet. Add animations first.</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="label">Phase (0 = all phases)</label>
|
<label class="label">Phase (0 = all phases)</label>
|
||||||
<input type="number" name="phase" value="0" class="input" min="0" />
|
<input type="number" name="phase" value="0" class="input" min="0" />
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ public class EditModel : AdminPageModel
|
|||||||
// Ability management
|
// Ability management
|
||||||
public List<MobAbilityAssignment> MobAbilities { get; set; } = new();
|
public List<MobAbilityAssignment> MobAbilities { get; set; } = new();
|
||||||
public List<MobAbilityDefinition> AllAbilities { get; set; } = new();
|
public List<MobAbilityDefinition> AllAbilities { get; set; } = new();
|
||||||
|
public Dictionary<int, string> AbilityAnimationByAssignmentId { get; set; } = new();
|
||||||
|
public List<string> AvailableAbilityAnimationKeys { get; set; } = new();
|
||||||
|
|
||||||
// Animation management
|
// Animation management
|
||||||
public List<MobAnimationAssignment> MobAnimations { get; set; } = new();
|
public List<MobAnimationAssignment> MobAnimations { get; set; } = new();
|
||||||
@@ -138,12 +140,22 @@ public class EditModel : AdminPageModel
|
|||||||
.OrderBy(a => a.AbilityDefinition!.Name)
|
.OrderBy(a => a.AbilityDefinition!.Name)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
MobAnimations = await _db.MobAnimationAssignments
|
MobAnimations = await _db.MobAnimationAssignments
|
||||||
.Include(a => a.AnimationDefinition)
|
.Include(a => a.AnimationDefinition)
|
||||||
.ThenInclude(d => d!.SpriteSheet)
|
.ThenInclude(d => d!.SpriteSheet)
|
||||||
.Where(a => a.MobDefinitionId == id.Value)
|
.Where(a => a.MobDefinitionId == id.Value)
|
||||||
.OrderBy(a => a.AnimationDefinition!.Key)
|
.OrderBy(a => a.AnimationDefinition!.Key)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
AvailableAbilityAnimationKeys = BuildAvailableAbilityAnimationKeys(MobAnimations);
|
||||||
|
var assignmentIds = MobAbilities.Select(a => a.Id).ToList();
|
||||||
|
if (assignmentIds.Count > 0)
|
||||||
|
{
|
||||||
|
var mappings = await _db.Set<MobAbilityAnimationMapping>()
|
||||||
|
.Where(m => assignmentIds.Contains(m.AbilityAssignmentId))
|
||||||
|
.ToListAsync();
|
||||||
|
AbilityAnimationByAssignmentId = mappings.ToDictionary(m => m.AbilityAssignmentId, m => m.AnimationKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -376,7 +388,7 @@ public class EditModel : AdminPageModel
|
|||||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnPostAddAbilityAsync(int mobId, int abilityId, int priority, int phase)
|
public async Task<IActionResult> OnPostAddAbilityAsync(int mobId, int abilityId, int priority, int phase, string? animationKey)
|
||||||
{
|
{
|
||||||
// Check if already assigned
|
// Check if already assigned
|
||||||
var existing = await _db.MobAbilityAssignments
|
var existing = await _db.MobAbilityAssignments
|
||||||
@@ -400,6 +412,17 @@ public class EditModel : AdminPageModel
|
|||||||
_db.MobAbilityAssignments.Add(assignment);
|
_db.MobAbilityAssignments.Add(assignment);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(animationKey))
|
||||||
|
{
|
||||||
|
var mapping = new MobAbilityAnimationMapping
|
||||||
|
{
|
||||||
|
AbilityAssignmentId = assignment.Id,
|
||||||
|
AnimationKey = animationKey.Trim()
|
||||||
|
};
|
||||||
|
_db.Set<MobAbilityAnimationMapping>().Add(mapping);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,6 +431,14 @@ public class EditModel : AdminPageModel
|
|||||||
var assignment = await _db.MobAbilityAssignments.FindAsync(assignmentId);
|
var assignment = await _db.MobAbilityAssignments.FindAsync(assignmentId);
|
||||||
if (assignment != null)
|
if (assignment != null)
|
||||||
{
|
{
|
||||||
|
var mappings = await _db.Set<MobAbilityAnimationMapping>()
|
||||||
|
.Where(m => m.AbilityAssignmentId == assignmentId)
|
||||||
|
.ToListAsync();
|
||||||
|
if (mappings.Count > 0)
|
||||||
|
{
|
||||||
|
_db.Set<MobAbilityAnimationMapping>().RemoveRange(mappings);
|
||||||
|
}
|
||||||
|
|
||||||
_db.MobAbilityAssignments.Remove(assignment);
|
_db.MobAbilityAssignments.Remove(assignment);
|
||||||
await _db.SaveChangesAsync();
|
await _db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
@@ -477,4 +508,15 @@ public class EditModel : AdminPageModel
|
|||||||
|
|
||||||
return Redirect($"/admin/mobs/edit?id={mobId}#animations-section");
|
return Redirect($"/admin/mobs/edit?id={mobId}#animations-section");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<string> BuildAvailableAbilityAnimationKeys(IEnumerable<MobAnimationAssignment> assignments)
|
||||||
|
{
|
||||||
|
return assignments
|
||||||
|
.Select(a => !string.IsNullOrWhiteSpace(a.OverrideKey) ? a.OverrideKey : a.AnimationDefinition?.Key)
|
||||||
|
.Where(k => !string.IsNullOrWhiteSpace(k))
|
||||||
|
.Select(k => k!.Trim())
|
||||||
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||||
|
.OrderBy(k => k)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user