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:
@@ -252,13 +252,16 @@ public partial class DungeonSimulation
|
|||||||
mob.Abilities.Clear();
|
mob.Abilities.Clear();
|
||||||
LoadMobAbilities(mob, mobDef);
|
LoadMobAbilities(mob, mobDef);
|
||||||
|
|
||||||
// If no abilities loaded, give a basic attack
|
bool hasBasicMelee = mob.Abilities.Any(a => a.Definition.AbilityType == MobAbilityType.MeleeAttack);
|
||||||
if (mob.Abilities.Count == 0)
|
|
||||||
|
// 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")
|
if (mobDef.Id == 100 || mobDef.Name == "The Bone Lord")
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
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
|
mob.Abilities.Add(new MobAbilityState
|
||||||
@@ -430,23 +433,20 @@ public partial class DungeonSimulation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void ProcessMobAbility(MobInstance mob, PlayerInstance target)
|
private void ProcessMobAbility(MobInstance mob, PlayerInstance target)
|
||||||
{
|
{
|
||||||
// Find the best available ability
|
// Find the best currently usable ability.
|
||||||
var ability = mob.Abilities
|
var ability = mob.Abilities
|
||||||
.Where(a => a.IsAvailable(mob.HpPercent))
|
.Where(a => a.IsAvailable(mob.HpPercent))
|
||||||
.Where(a => a.Phase == 0 || a.Phase == mob.CurrentPhase)
|
.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)
|
.OrderByDescending(a => a.Priority)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (ability == null) return;
|
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);
|
int manaCost = Math.Max(0, ability.Definition.ManaCost);
|
||||||
if (manaCost > 0)
|
if (manaCost > 0)
|
||||||
{
|
{
|
||||||
if (mob.Mana < manaCost) return;
|
|
||||||
mob.Mana -= manaCost;
|
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)
|
private void ProcessSummonAbility(MobInstance mob, MobAbilityDefinition ability)
|
||||||
{
|
{
|
||||||
if (!ability.SummonMobId.HasValue)
|
if (!ability.SummonMobId.HasValue)
|
||||||
|
|||||||
+9
-1
@@ -86,4 +86,12 @@ COMMIT;
|
|||||||
## Notes
|
## Notes
|
||||||
1. `SummonMobId` is set to `1` for summon tests; adjust if you want another summon target.
|
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.
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user