ModernUO/Projects/UOContent.Tests/Tests/Mobiles
Kamron Batman 6b910ff089
fix(ai): guarding pets never target their owner or the owner's pets (#2665)
Supersedes #2657 (rebased onto #2662, which the original branch conflicted with). Credit to @MithrilHammer for the diagnosis, the fix and the regression tests; their three commits are kept as authored.

Fixes #2656.

## Root cause

When a guarding pet's combatant hides or becomes invalid, its AI calls `AcquireFocusMob` to find a new target. A controlled creature with no `ControlTarget` (Guard normally has none) fell out of `HandleControlled` and into the wild-creature scan, where `IsEnemy` treats any player as an enemy. With `FightMode.Closest`, the owner won. The fall-through dates to #2232. RunUO never let a controlled creature reach the wild scan.

## Changes

- `AcquireFocusMob`: a controlled creature returns whatever `HandleControlled` decides. Guard uses `FindGuardTarget`, Attack uses its `ControlTarget`, and every other order acquires nothing.
- `FindGuardTarget` skips guard allies: the master and creatures the master controls, including controlled summons. Uncontrolled summons (energy vortex, blade spirits) attack their caster, so a guard still defends against them, as in RunUO.
- Friendly fire: `BaseAI.OnAggressiveAction` stands a guard down when an ally is the aggressor. `BaseCreature.Combatant` refuses an ally while guarding, because `Mobile.AggressiveAction` assigns the first aggressor as `Combatant` before any retaliation policy runs. The veto sits on `Combatant` rather than `CanBeHarmful`, so what a pet can harm doesn't depend on its current order. An explicit Attack order and bard provocation can still target an ally.

## Tests

16 regression cases in `GuardFriendlyFireTests` (skipped without client map data), including a real `WhiteWyrm` reproduction. `UOContent.Tests`: 1142 passed, 2 skipped, 0 failed on Windows.
2026-09-23 10:13:34 -07:00
..
AI fix(ai): guarding pets never target their owner or the owner's pets (#2665) 2026-09-23 10:13:34 -07:00
BaseCreatureSerializationTests.cs refactor: Changes BaseCreature to the SerializationGenerator (delta save requirement) (#2611) 2026-09-06 14:11:51 -07:00
LootingRightsTests.cs perf: keep damage entries in an inline intrusive list (#2605) 2026-09-01 23:25:14 -07:00
MountRegionTests.cs fix: respect active region MountsAllowed for players (#2630) 2026-09-11 17:26:06 -07:00