Fixes walk-up aggro latency (up to a full 10 s of obliviousness) and hardens the reacquire gate so no state can silence acquisition, while turning `AcquireOnApproach` into the reaction-time knob for future per-creature intelligence tuning. ### Why `AcquireFocusMob` re-armed the 10 s `ReacquireDelay` **before** scanning, success or failure. A creature that scanned an empty room was blind for 10 s to a player walking up — walk-up aggro latency was uniform in 0..10 s. Waking from sector sleep stacked the AI timer's 0–3 s construction stagger on top. And `NextReacquireTime` is not serialized: on hosts whose tick counter starts negative (GCP pass-through), the 0 default blocked **all** acquisition shard-wide after a restart until the counter crossed zero. ### What **Event-driven reaction — `AcquireOnApproachDelay` (the intelligence gradient)** - The paragon `AcquireOnApproach` bool becomes a `TimeSpan` on every creature: an enemy moving inside `AcquireOnApproachRange` (10 for all creatures — on-screen reactive aggro; the periodic scan keeps the wide `RangePerception` sweep) *clamps* the next scan to at most the delay. Repeated steps cannot shorten it further — one scan per delay period, not per step or think. - `Zero` (paragons) also prods the AI timer: the ranked scan engages within a wheel turn — the old snap, minus the special-cased engage path. The target now comes from the normal FightMode ranking instead of whichever mobile happened to move, and the `Combatant == null` guard stops re-engage spam. - The 2 s default reads as "took a beat to notice you"; larger values are dumber; `ReacquireDelay` alone is the oblivious floor. Mover checks are the approach logic's `IsEnemy` + `CanBeHarmful` (so pets count and hidden movers are excluded via `CanSee`), with `IsEnemy` first to cheaply reject same-team wild creatures wandering past. The check rides the `OnMovement` callback every step already pays for — no polling added. **Gate correctness** - Every scan re-arms the full `ReacquireDelay`, success or failure (classic semantics; reaction time is the approach path, not the poll). - Self-healing by construction: a deadline further out than `ReacquireDelay` is an illegal state and reads as open — no wedged or wrapped value can silence acquisition beyond one delay period. - `NextReacquireTime` is seeded from a live tick on deserialize (the GCP negative-tick blackout). **AI timer wake** - Activation (sector wake, spawn, resurrection) starts within a 0–256 ms spread instead of the 0–3 s construction stagger, which read as lag. - The stagger's real job — keeping same-speed cohorts out of lock-step (the RunUO town artifact) — is now a zero-mean ±period/8 jitter on each **idle** think, so phases random-walk apart within seconds and can never re-lock. Instrumentation showed why a one-shot spread can't do this job: the timer wheel fires within ±1 ms, so with 10 creatures on a 500 ms period some pair collides on nearly the same phase ~75% of the time (birthday paradox) and then steps in the same loop iteration *forever*. Jitter is scoped to passive speed: engaged cadence stays exact, since pursuit timing anchors to real step times. **Debug** - The `AcquireFocusMob` scan message no longer re-arms the shared 5 s debug cooldown, which swallowed every AI's "I have detected X" transition line. **API change** for custom scripts: `AcquireOnApproach` (bool) → `AcquireOnApproachDelay` (TimeSpan). Documented in `content-patterns.md` § Target Acquisition, `runuo-migration-docs/09` + `11`, and the migration skill checklist. ### Tests `AcquisitionTests`: both scan outcomes honor `ReacquireDelay`; a 60 s-wedged gate still acquires; enemy movement clamps the deadline (same-team wild movers and out-of-range movers ignored); repeated movement cannot shorten below the delay; `Zero` opens the gate and prods without a direct engage. Full suite: 755 UOContent green.
157 lines
4.2 KiB
C#
157 lines
4.2 KiB
C#
using System.Runtime.CompilerServices;
|
|
|
|
namespace Server.Mobiles;
|
|
|
|
public class MeleeAI : BaseAI
|
|
{
|
|
public MeleeAI(BaseCreature m) : base(m)
|
|
{
|
|
}
|
|
|
|
public override double FleeHealthThreshold => 0.2; // 20% is default
|
|
public override double FleeChance => 0.1; // 10% is default
|
|
|
|
public override bool DoActionWander()
|
|
{
|
|
if (AcquireFocusMob(Mobile.RangePerception, Mobile.FightMode, false, false, true))
|
|
{
|
|
this.DebugSayFormatted($"I have detected {Mobile.FocusMob.Name}, attacking");
|
|
|
|
Mobile.Combatant = Mobile.FocusMob;
|
|
Action = ActionType.Combat;
|
|
}
|
|
else
|
|
{
|
|
DebugSay("I am wandering");
|
|
Mobile.Warmode = false;
|
|
base.DoActionWander();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override bool DoActionCombat()
|
|
{
|
|
var combatant = Mobile.Combatant;
|
|
|
|
if (!IsValidCombatant(combatant))
|
|
{
|
|
DebugSay("My combatant is gone, so my guard is up");
|
|
Action = ActionType.Guard;
|
|
return true;
|
|
}
|
|
|
|
if (!Mobile.InRange(combatant, Mobile.RangePerception))
|
|
{
|
|
if (!HandleOutOfRangeCombatant(combatant))
|
|
{
|
|
return true;
|
|
}
|
|
combatant = Mobile.Combatant;
|
|
}
|
|
|
|
if (!AttemptMoveToCombatant(combatant))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (Core.TickCount - Mobile.LastMoveTime > 400)
|
|
{
|
|
Mobile.Direction = Mobile.GetDirectionTo(combatant);
|
|
}
|
|
|
|
if (Mobile.TriggerAbility(MonsterAbilityTrigger.CombatAction, combatant))
|
|
{
|
|
DebugSay("I used my abilities!");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
private bool IsValidCombatant(Mobile combatant) =>
|
|
combatant?.Deleted == false && combatant.Map == Mobile.Map && combatant.Alive && !combatant.IsDeadBondedPet;
|
|
|
|
private bool HandleOutOfRangeCombatant(Mobile combatant)
|
|
{
|
|
if (AcquireFocusMob(Mobile.RangePerception, Mobile.FightMode, false, false, true))
|
|
{
|
|
Mobile.Combatant = Mobile.FocusMob;
|
|
Mobile.FocusMob = null;
|
|
return true;
|
|
}
|
|
|
|
if (!Mobile.InRange(combatant, Mobile.ChaseLeashRange))
|
|
{
|
|
Mobile.Combatant = null;
|
|
}
|
|
|
|
if (Mobile.Combatant == null)
|
|
{
|
|
DebugSay("My combatant has fled, so I am on guard.");
|
|
Action = ActionType.Guard;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool AttemptMoveToCombatant(Mobile combatant)
|
|
{
|
|
if (MoveTo(combatant, Mobile.RangeFight))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (AcquireFocusMob(Mobile.RangePerception, Mobile.FightMode, false, false, true))
|
|
{
|
|
this.DebugSayFormatted($"My move is blocked, so I am going to attack {Mobile.FocusMob.Name}.");
|
|
Mobile.Combatant = Mobile.FocusMob;
|
|
Action = ActionType.Combat;
|
|
return true;
|
|
}
|
|
|
|
if (Mobile.GetDistanceToSqrt(combatant) > Mobile.RangePerception + 1)
|
|
{
|
|
this.DebugSayFormatted($"I cannot find {combatant.Name}, so my guard is up.");
|
|
Action = ActionType.Guard;
|
|
return false;
|
|
}
|
|
|
|
this.DebugSayFormatted($"I cannot reach {combatant.Name} but continuing to try.");
|
|
return true;
|
|
}
|
|
|
|
public override bool DoActionGuard()
|
|
{
|
|
if (AcquireFocusMob(Mobile.RangePerception, Mobile.FightMode, false, false, true))
|
|
{
|
|
this.DebugSayFormatted($"I have detected {Mobile.FocusMob.Name}, attacking");
|
|
|
|
Mobile.Combatant = Mobile.FocusMob;
|
|
Action = ActionType.Combat;
|
|
}
|
|
else
|
|
{
|
|
base.DoActionGuard();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override bool DoActionFlee()
|
|
{
|
|
if (Mobile.Hits > Mobile.HitsMax * FleeHealthThreshold)
|
|
{
|
|
DebugSay("I am stronger now, so I will continue fighting.");
|
|
Action = ActionType.Combat;
|
|
}
|
|
else
|
|
{
|
|
Mobile.FocusMob = Mobile.Combatant;
|
|
base.DoActionFlee();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|