perf(ai): make IsEnemy the single authority for Honor/Ethereal Voyage (#2655)
## Summary Profiling with thousands of creatures in range of each other showed `BaseAI.IsInvalidFactionTarget` checking Ethereal Voyage and active Honor on every acquisition candidate and then calling `BaseCreature.IsEnemy`, which checked both again. This makes `IsEnemy` the single authority and removes the duplicate per-pair work. ## Changes - **`BaseCreature.IsEnemy`**: the Ethereal Voyage check sat below the `m is not BaseCreature` early return, so it never reached players — the only mobiles that cast it. It is hoisted next to the Honor veto. `GetMaster()` was called three times per creature pair (inside `Ethics.Player.Find(m, true)` and twice at the bottom); it is now computed once. - **`BaseAI.IsInvalidFactionTarget`**: reduced to `IsFriend` / `IsEnemy` / `CanBeHarmful`. The removed `Combatant != m` Honor exception was dead code — `IsEnemy` vetoed Honor unconditionally on the following line. - **`Ethics.Player.Find`** / **`TransformationSpellHelper.GetContext`**: small simplifications on the same path. ## Behavior - `ShouldAcquireOnApproach` and `OnAggressiveAction` only consult `IsEnemy`, so movement-triggered acquisition now respects Ethereal Voyage for players (previously a player under Ethereal Voyage walking past a monster was still acquired on approach). - `BaseFactionGuard.IsEnemy` does not call base, so faction guards no longer skip honoring/voyaging enemy-faction players. Accepted: both mechanics describe monsters, not guards. - `HealerAI`/`BerserkAI`/`PredatorAI` (`bFacFriend`) callers are unaffected — `IsFriend` already required a `BaseCreature`, so players were excluded before these checks ran. `MilitiaFighter`/`MilitiaCanoneer` return `false` for all players, so they are unaffected too. ## Testing - `dotnet build` clean. - Pure predicate reorder; no new tests.
This commit is contained in:
parent
35e3a31b4c
commit
f211607d63
4 changed files with 14 additions and 44 deletions
|
|
@ -16,10 +16,8 @@
|
|||
using System;
|
||||
using Server.Engines.Quests.Necro;
|
||||
using Server.Engines.Spawners;
|
||||
using Server.Engines.Virtues;
|
||||
using Server.Factions;
|
||||
using Server.Spells;
|
||||
using Server.Spells.Spellweaving;
|
||||
using Server.Targets;
|
||||
|
||||
namespace Server.Mobiles;
|
||||
|
|
@ -998,21 +996,9 @@ public abstract partial class BaseAI
|
|||
Mobile.IsAnimatedDead && (pm != null || bc?.IsAnimatedDead == true || bc?.Controlled == true);
|
||||
}
|
||||
|
||||
private bool IsInvalidFactionTarget(Mobile m, bool bFacFriend, bool bFacFoe)
|
||||
{
|
||||
if (bFacFriend && !Mobile.IsFriend(m))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TransformationSpellHelper.UnderTransformation(m, typeof(EtherealVoyageSpell)) ||
|
||||
Mobile.Combatant != m && VirtueSystem.GetVirtues(m as PlayerMobile)?.HonorActive == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return bFacFoe && (!Mobile.IsEnemy(m) || !bFacFriend && !Mobile.CanBeHarmful(m, false));
|
||||
}
|
||||
private bool IsInvalidFactionTarget(Mobile m, bool bFacFriend, bool bFacFoe) =>
|
||||
bFacFriend && !Mobile.IsFriend(m) ||
|
||||
bFacFoe && (!Mobile.IsEnemy(m) || !bFacFriend && !Mobile.CanBeHarmful(m, false));
|
||||
|
||||
private bool IsInvalidFightModeTarget(Mobile m, FightMode acqType, BaseCreature bc)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue