From e5ee966451134a4b2322c704ba4a84e58efb7db1 Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 11 Feb 2026 09:19:32 -0500 Subject: [PATCH] Add anti-repeat mob ability selection when multiple options are valid - Track last used ability key and consecutive-use count on MobInstance - In ProcessMobAbility, avoid repeating the same ability more than 3 times in a row if alternatives are currently usable - Keep existing priority-based selection as primary behavior --- Game/Dungeon/DungeonSimulation.cs | 40 +++++++++++++++++++++++++++---- Game/Dungeon/MobInstance.cs | 6 +++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 2821653..e16fe34 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -435,17 +435,36 @@ public partial class DungeonSimulation /// private void ProcessMobAbility(MobInstance mob, PlayerInstance target) { - // Find the best currently usable ability. - var ability = mob.Abilities + const int maxConsecutiveAbilityRepeats = 3; + + // Find currently usable abilities. + var usableAbilities = 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; + .ToList(); + if (usableAbilities.Count == 0) return; + + var ability = usableAbilities[0]; + + // Anti-repeat: if a mob is stuck using one ability and other valid options exist, + // force variety after a small streak. + if (usableAbilities.Count > 1 && + !string.IsNullOrWhiteSpace(mob.LastUsedAbilityKey) && + string.Equals(ability.Definition.Key, mob.LastUsedAbilityKey, StringComparison.OrdinalIgnoreCase) && + mob.ConsecutiveAbilityUses >= maxConsecutiveAbilityRepeats) + { + var alternate = usableAbilities + .FirstOrDefault(a => !string.Equals(a.Definition.Key, mob.LastUsedAbilityKey, StringComparison.OrdinalIgnoreCase)); + if (alternate != null) + { + ability = alternate; + } + } + int manaCost = Math.Max(0, ability.Definition.ManaCost); if (manaCost > 0) { @@ -455,6 +474,17 @@ public partial class DungeonSimulation // Put ability on cooldown ability.CooldownRemaining = ability.Definition.Cooldown; + if (!string.IsNullOrWhiteSpace(mob.LastUsedAbilityKey) && + string.Equals(mob.LastUsedAbilityKey, ability.Definition.Key, StringComparison.OrdinalIgnoreCase)) + { + mob.ConsecutiveAbilityUses++; + } + else + { + mob.LastUsedAbilityKey = ability.Definition.Key; + mob.ConsecutiveAbilityUses = 1; + } + string animationKey = ResolveAbilityAnimationKey(mob, ability); Console.WriteLine( diff --git a/Game/Dungeon/MobInstance.cs b/Game/Dungeon/MobInstance.cs index bb7289d..345a170 100644 --- a/Game/Dungeon/MobInstance.cs +++ b/Game/Dungeon/MobInstance.cs @@ -106,6 +106,12 @@ public class MobInstance // === Abilities === /// Abilities this mob can use public List Abilities { get; set; } = new(); + + /// Last ability key used by this mob (for anti-repeat selection). + public string? LastUsedAbilityKey { get; set; } + + /// How many times in a row the same ability has been used. + public int ConsecutiveAbilityUses { get; set; } /// Currently casting ability (null if not casting) public MobAbilityState? CastingAbility { get; set; }