Fix ability selection deadlock and improve temp ability test usability

- Always add a basic melee fallback when mobs have no melee ability

- Select only currently usable/implemented abilities (phase, cooldown, mana, range) before execution

- Add test note in abilityTemp.md to set TEMP_TEST abilities ManaCost=0 for low-mana mobs
This commit is contained in:
dingo
2026-02-10 14:53:21 -05:00
parent 1f68928c83
commit 2df33f4a62
2 changed files with 65 additions and 10 deletions
+56 -9
View File
@@ -252,13 +252,16 @@ public partial class DungeonSimulation
mob.Abilities.Clear();
LoadMobAbilities(mob, mobDef);
// If no abilities loaded, give a basic attack
if (mob.Abilities.Count == 0)
bool hasBasicMelee = mob.Abilities.Any(a => a.Definition.AbilityType == MobAbilityType.MeleeAttack);
// Always ensure there is at least one reliable melee fallback.
// This prevents ability setups (mana-gated/unimplemented types) from disabling all mob damage.
if (!hasBasicMelee)
{
if (mobDef.Id == 100 || mobDef.Name == "The Bone Lord")
{
Console.WriteLine(
$"[DungeonSimulation] Bone Lord has no loaded abilities; falling back to Basic Attack.");
$"[DungeonSimulation] Bone Lord has no melee fallback; adding Basic Attack.");
}
mob.Abilities.Add(new MobAbilityState
@@ -430,23 +433,20 @@ public partial class DungeonSimulation
/// </summary>
private void ProcessMobAbility(MobInstance mob, PlayerInstance target)
{
// Find the best available ability
// Find the best currently usable ability.
var ability = mob.Abilities
.Where(a => a.IsAvailable(mob.HpPercent))
.Where(a => a.Phase == 0 || a.Phase == mob.CurrentPhase)
.Where(a => IsImplementedAbilityType(a.Definition.AbilityType))
.Where(a => CanUseAbilityNow(mob, target, a.Definition))
.OrderByDescending(a => a.Priority)
.FirstOrDefault();
if (ability == null) return;
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;
}
@@ -517,6 +517,53 @@ public partial class DungeonSimulation
}
}
private static bool CanUseAbilityNow(MobInstance mob, PlayerInstance target, MobAbilityDefinition definition)
{
int manaCost = Math.Max(0, definition.ManaCost);
if (manaCost > 0 && mob.Mana < manaCost)
{
return false;
}
bool isSummonAbility = definition.AbilityType is MobAbilityType.SummonSingle or MobAbilityType.SummonBulk;
if (!isSummonAbility && definition.Range > 0)
{
float distance = Distance(mob.X, mob.Y, target.X, target.Y);
if (distance > definition.Range)
{
return false;
}
}
return true;
}
private static bool IsImplementedAbilityType(MobAbilityType type)
{
return type switch
{
MobAbilityType.SummonSingle => true,
MobAbilityType.SummonBulk => true,
MobAbilityType.MeleeAttack => true,
MobAbilityType.Cleave => true,
MobAbilityType.ProjectileSingle => true,
MobAbilityType.ProjectileAoe => true,
MobAbilityType.GroundAoe => true,
MobAbilityType.ConeAttack => true,
MobAbilityType.Poison => true,
MobAbilityType.Bleed => true,
MobAbilityType.Burn => true,
MobAbilityType.Stun => true,
MobAbilityType.Slow => true,
MobAbilityType.Root => true,
MobAbilityType.Fear => true,
MobAbilityType.Knockback => true,
MobAbilityType.Pull => true,
MobAbilityType.HazardZone => true,
_ => false
};
}
private void ProcessSummonAbility(MobInstance mob, MobAbilityDefinition ability)
{
if (!ability.SummonMobId.HasValue)
+9 -1
View File
@@ -86,4 +86,12 @@ COMMIT;
## Notes
1. `SummonMobId` is set to `1` for summon tests; adjust if you want another summon target.
2. These are seeded with `TEMP_TEST_*` keys so you can remove them quickly.
3. If you want, I can generate a matching cleanup script for `dungeon_mob_ability_assignments` by key lookup.
3. For broad behavior testing on low/zero-mana mobs, run this after insert:
```sql
UPDATE `dungeon_mob_abilities`
SET `ManaCost` = 0
WHERE `Key` LIKE 'TEMP_TEST_%';
```
4. If you want, I can generate a matching cleanup script for `dungeon_mob_ability_assignments` by key lookup.