fix(ai): BaseAI.OnAggressiveAction owns the retaliation policy; familiars refuse cleanly (#2662)
> [!IMPORTANT] > **Breaking change to API to fix NPC AI issues** ## Symptom `FamiliarAITests.HiddenCaster_FamiliarRefusesRetaliation` fails on main at `Assert.False(wolf.Warmode)`: the familiar's `Combatant` stays null as intended, but it is left in war stance. In-game the familiar of a hidden caster flips into warmode for a tick when struck, until `FamiliarAI.StandDown()` clears it on the next think. CI never saw it because the familiar tests are `SkippableFact` (they need client tiledata). ## Root cause #2644 and #2645 landed a day apart and are individually correct but conflict at one seam. Since #2645, a familiar (`Commandable == false`) is no longer "told to stand down", so `BaseCreature.AggressiveAction` continues past `AIObject.OnAggressiveAction(aggressor)` to its generic fallback: ```cs else if (Combatant == null && !BardPacified) { Warmode = true; Combatant = aggressor; } ``` `FamiliarAI.OnAggressiveAction` had already declined (caster hidden), but the hook was `void`, so the creature could not tell. The fallback raised `Warmode` before `BaseFamiliar.Combatant` vetoed the target. ## Fix This is the follow-up agreed in #2645: the retaliation policy moves into a virtual `BaseAI.OnAggressiveAction(aggressor) -> bool`. - **`BaseAI.OnAggressiveAction`** now holds the stand-down verdict, the closer-aggressor swap (`PreferCloserAggressor`), and the `IssueOrder(Attack)` vs `Combatant =` decision. Returns `false` when the creature stands down. - **`BaseCreature.AggressiveAction`** keeps only bookkeeping — `ControlMaster.Aggressors` entry, `StopFlee`, `ForceReacquire`, ethics `FinishShield` — keyed off the return, so an AI that declines is never second-guessed. - **`FamiliarAI`** overrides the whole policy: no orders to stand down on, never fights for a hidden caster or a hidden aggressor. Behaviour for every other AI is unchanged. Moving the fallback ahead of `StopFlee`/`ForceReacquire` is order-safe: both are pure field resets, `IssueAttack` does not `Think()`, and `OnCombatantChange` only derives `Warmode`. Two commits: the first is the minimal `bool` hook that alone fixes the test, the second the policy move. ## Not changed (noted for later) - `Warmode = true; Combatant = x;` (also in `FamiliarAI.Act`, `IssueAttack`) is redundant when the setter accepts — `BaseCreature.OnCombatantChange` derives `Warmode` — and is the dangling-warmode hazard whenever a `Combatant` setter vetoes. - Since #2614 a stood-down pet skips the ethics `FinishShield`; RunUO ran it unconditionally. Preserved as-is. ## Tests `HiddenCaster_FamiliarRefusesRetaliation` fails on main and passes here. Full `UOContent.Tests`: 1126 passed, 0 failed, 2 skipped (spawner fixture capture + benchmark).
This commit is contained in:
parent
29a3ab1bd4
commit
502c3f6aa4
7 changed files with 96 additions and 31 deletions
|
|
@ -31,6 +31,7 @@ description: >
|
|||
- Expression-bodied overrides: `public override int Meat { get { return 1; } }` -> `public override int Meat => 1;`
|
||||
- AI movement calls lose the `run` flag: `MoveTo(m, true, range)` -> `MoveTo(m, range)` (also `WalkMobileRange`, `ApproachTarget`, `MoveToPoint`, `PathFollower.Follow`); the Running bit is derived from step pace -> `dev-docs/runuo-migration-docs/09-items-mobiles-creatures.md` § AI Movement
|
||||
- `AcquireOnApproach` (bool) -> `AcquireOnApproachDelay` (TimeSpan; `Zero` = old instant behavior) -> same doc § Target Acquisition
|
||||
- `BaseAI.OnAggressiveAction(aggressor)` is `bool`, not `void`: the AI owns the retaliation policy (`BaseCreature` no longer sets `Combatant` after it); an early `return;` that refused a fight -> `return false;`, otherwise `return true;`; swap-only overrides call `PreferCloserAggressor(aggressor)` instead of `base` -> same doc § Retaliation
|
||||
- `DamageEntries` is an inline `ref readonly ValueLinkList<DamageEntry>`, not a `List`: indexer/`Add`/`Remove`/`Clear` -> `foreach` / `.ByDescending()` (needs `using Server.Collections;`) and `ClearDamageEntries()`; `GetLootingRights` takes it by `in` -> same doc § Damage Entries
|
||||
|
||||
## Anti-Patterns
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ class — `OnThink` is for content extras (see the excess-call contract below).
|
|||
creature is dispatched through `Obey()`, an uncontrolled one through `Think()`; an AI that owns
|
||||
both routes them into one decision (`FamiliarAI.Act`). Overriding `IssueOrder` to return a
|
||||
fixed order is how "command immunity" is expressed without bypassing the order machinery.
|
||||
`OnAggressiveAction(aggressor) -> bool` is the retaliation policy: `BaseCreature` sets no
|
||||
combatant of its own and runs `StopFlee`/`ForceReacquire` only on `true`, so an AI that
|
||||
returns `false` has refused the fight outright.
|
||||
|
||||
### Fight Modes
|
||||
| FightMode | Behavior |
|
||||
|
|
|
|||
|
|
@ -497,6 +497,49 @@ An isolated step (after the creature stood for at least a walk interval) goes ou
|
|||
walk regardless of pace — only a continuing cadence, or a pace faster than the run
|
||||
interpolation, flags run.
|
||||
|
||||
## Retaliation: `OnAggressiveAction` Returns `bool`
|
||||
|
||||
RunUO's `BaseAI.OnAggressiveAction` was a `void` hook that only swapped to a closer
|
||||
aggressor; `BaseCreature.AggressiveAction` then decided the response itself and set
|
||||
`Combatant` regardless of what the AI had done. ModernUO moves the whole retaliation policy
|
||||
into the hook — the stand-down verdict for commanded pets, the closer-aggressor swap
|
||||
(`PreferCloserAggressor`), and the `IssueOrder(Attack)` vs `Combatant =` choice — and
|
||||
`BaseCreature` only runs its bookkeeping (`StopFlee`, `ForceReacquire`, ethics shield) when
|
||||
the hook returns `true`:
|
||||
|
||||
```csharp
|
||||
// RunUO — swap only; BaseCreature picks the combatant afterwards
|
||||
public override void OnAggressiveAction(Mobile aggressor)
|
||||
{
|
||||
if (m_Mobile.Combatant == null)
|
||||
{
|
||||
m_Mobile.Combatant = aggressor;
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnAggressiveAction(aggressor);
|
||||
}
|
||||
|
||||
// ModernUO — the AI owns the response; false = stood down, nothing else fires
|
||||
public override bool OnAggressiveAction(Mobile aggressor)
|
||||
{
|
||||
if (Mobile.Combatant == null)
|
||||
{
|
||||
Mobile.Combatant = aggressor;
|
||||
}
|
||||
else
|
||||
{
|
||||
PreferCloserAggressor(aggressor);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
An override that used to `return;` early to refuse a fight now returns `false`; calling
|
||||
`base.OnAggressiveAction` runs the full stock policy, including setting `Combatant`, so an AI
|
||||
that only wants the closer-aggressor swap calls `PreferCloserAggressor` instead.
|
||||
|
||||
## Target Acquisition: `AcquireOnApproach` Is a Delay
|
||||
|
||||
RunUO's `AcquireOnApproach` bool (paragon insta-aggro on approach) is now
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ Alphabetical by RunUO API name. Use Ctrl+F / Cmd+F to search.
|
|||
| `WalkMobileRange(m, steps, run, min, max)` | `WalkMobileRange(m, steps, min, max)` | Same |
|
||||
| `PathFollower.Follow(run, range)` | `Follow(range)` | Same |
|
||||
| `AcquireOnApproach` (bool) | `AcquireOnApproachDelay` (TimeSpan) | Reaction-time gradient; `Zero` = old instant behavior |
|
||||
| `BaseAI.OnAggressiveAction(m)` (`void`) | `OnAggressiveAction(m)` (`bool`) | The AI owns the retaliation policy; `false` = stood down; swap-only overrides call `PreferCloserAggressor` |
|
||||
| `m.DamageEntries` (`List<DamageEntry>`) | `m.DamageEntries` (`ref readonly ValueLinkList<DamageEntry>`) | Inline, least→most recent; `foreach` / `.ByDescending()` only, needs `using Server.Collections;`; no indexer, `Add`, `Remove`, `Clear` |
|
||||
| `m.DamageEntries.Clear()` | `m.ClearDamageEntries()` | |
|
||||
| `GetLootingRights(List<DamageEntry>, int)` | `GetLootingRights(in ValueLinkList<DamageEntry>, int)` | Callers passing `m.DamageEntries` compile unchanged |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue