Enable HealSelf and widen AI engagement to ability range
- Implement HealSelf execution in DungeonSimulation and mark it as implemented - Add healing log output for ability verification - Use mob engagement range derived from offensive ability ranges in Aggressive/Defensive/Tank behaviors - Allow ranged/projectile abilities to trigger before point-blank melee distance
This commit is contained in:
@@ -516,6 +516,10 @@ public partial class DungeonSimulation
|
||||
case MobAbilityType.HazardZone:
|
||||
SpawnHazardZone(mob, ability.Definition, target.X, target.Y);
|
||||
break;
|
||||
|
||||
case MobAbilityType.HealSelf:
|
||||
ProcessHealSelfAbility(mob, ability.Definition);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,10 +566,26 @@ public partial class DungeonSimulation
|
||||
MobAbilityType.Knockback => true,
|
||||
MobAbilityType.Pull => true,
|
||||
MobAbilityType.HazardZone => true,
|
||||
MobAbilityType.HealSelf => true,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
private static void ProcessHealSelfAbility(MobInstance mob, MobAbilityDefinition ability)
|
||||
{
|
||||
if (!mob.IsAlive || mob.MaxHealth <= 0) return;
|
||||
|
||||
// For test coverage and predictable behavior, HealSelf restores BaseDamage HP.
|
||||
// It is capped to MaxHealth.
|
||||
int healAmount = Math.Max(1, ability.BaseDamage);
|
||||
int oldHealth = mob.Health;
|
||||
mob.Health = Math.Min(mob.MaxHealth, mob.Health + healAmount);
|
||||
int actualHealed = mob.Health - oldHealth;
|
||||
|
||||
Console.WriteLine(
|
||||
$"[MobHeal] Mob {mob.Id} ({mob.Name}) HealSelf {ability.Key}: +{actualHealed} (requested={healAmount}) hp={mob.Health}/{mob.MaxHealth}");
|
||||
}
|
||||
|
||||
private void ProcessSummonAbility(MobInstance mob, MobAbilityDefinition ability)
|
||||
{
|
||||
if (!ability.SummonMobId.HasValue)
|
||||
|
||||
+35
-5
@@ -112,8 +112,10 @@ public static class MobAI
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
mob.CombatTime += deltaTime;
|
||||
|
||||
// In attack range?
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
float engageRange = GetEngagementRange(mob);
|
||||
|
||||
// In ability/attack range?
|
||||
if (distance <= engageRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
@@ -152,8 +154,9 @@ public static class MobAI
|
||||
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
|
||||
float engageRange = GetEngagementRange(mob);
|
||||
if (distance <= engageRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
@@ -308,7 +311,8 @@ public static class MobAI
|
||||
mob.TargetId = target.CharacterId;
|
||||
mob.UpdateFacingDirection(target.X, target.Y);
|
||||
|
||||
if (distance <= mob.Stats.AttackRange)
|
||||
float engageRange = GetEngagementRange(mob);
|
||||
if (distance <= engageRange)
|
||||
{
|
||||
mob.State = MobState.Attacking;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("attack");
|
||||
@@ -909,6 +913,32 @@ public static class MobAI
|
||||
float dy = y2 - y1;
|
||||
return MathF.Sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
private static float GetEngagementRange(MobInstance mob)
|
||||
{
|
||||
float range = Math.Max(0f, mob.Stats.AttackRange);
|
||||
|
||||
if (mob.Abilities.Count == 0) return range;
|
||||
|
||||
foreach (var ability in mob.Abilities)
|
||||
{
|
||||
var def = ability.Definition;
|
||||
if (def == null || def.Range <= 0) continue;
|
||||
|
||||
// Keep self/allied support skills from inflating engage distance.
|
||||
if (def.AbilityType is MobAbilityType.HealSelf or MobAbilityType.HealAlly or MobAbilityType.HealAoe
|
||||
or MobAbilityType.BuffSelf or MobAbilityType.BuffAllies or MobAbilityType.Shield
|
||||
or MobAbilityType.Enrage or MobAbilityType.PhaseChange
|
||||
or MobAbilityType.SummonSingle or MobAbilityType.SummonBulk)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
range = Math.Max(range, def.Range);
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user