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
This commit is contained in:
@@ -435,17 +435,36 @@ public partial class DungeonSimulation
|
||||
/// </summary>
|
||||
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(
|
||||
|
||||
@@ -106,6 +106,12 @@ public class MobInstance
|
||||
// === Abilities ===
|
||||
/// <summary>Abilities this mob can use</summary>
|
||||
public List<MobAbilityState> Abilities { get; set; } = new();
|
||||
|
||||
/// <summary>Last ability key used by this mob (for anti-repeat selection).</summary>
|
||||
public string? LastUsedAbilityKey { get; set; }
|
||||
|
||||
/// <summary>How many times in a row the same ability has been used.</summary>
|
||||
public int ConsecutiveAbilityUses { get; set; }
|
||||
|
||||
/// <summary>Currently casting ability (null if not casting)</summary>
|
||||
public MobAbilityState? CastingAbility { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user