From b6e3227f29d47ff2d5cb186a5faa93b9c62a978f Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 10 Feb 2026 21:31:24 -0500 Subject: [PATCH] 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 --- Game/Dungeon/DungeonSimulation.cs | 20 ++++++++++++++++ Game/Dungeon/MobAI.cs | 40 +++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 14aa8c3..68700f0 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -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) diff --git a/Game/Dungeon/MobAI.cs b/Game/Dungeon/MobAI.cs index b636536..878c00e 100644 --- a/Game/Dungeon/MobAI.cs +++ b/Game/Dungeon/MobAI.cs @@ -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 }