From 63fa8636f470734461ffa312bef950098f9a84a0 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 7 Jan 2022 09:36:23 -0500 Subject: [PATCH] [WIP] Core/AI: Pets musn't attack civilian NPC in aggressive mode Port From (https://github.com/TrinityCore/TrinityCore/commit/1e932109996a0ce2117f3d5268064ee882267e84) --- Source/Game/AI/CoreAI/PetAI.cs | 2 +- Source/Game/Entities/Creature/Creature.cs | 4 ++-- Source/Game/Maps/GridNotifiers.cs | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/Game/AI/CoreAI/PetAI.cs b/Source/Game/AI/CoreAI/PetAI.cs index 8c5627758..2adfa7a9b 100644 --- a/Source/Game/AI/CoreAI/PetAI.cs +++ b/Source/Game/AI/CoreAI/PetAI.cs @@ -336,7 +336,7 @@ namespace Game.AI { if (!me.GetCharmInfo().IsReturning() || me.GetCharmInfo().IsFollowing() || me.GetCharmInfo().IsAtStay()) { - Unit nearTarget = me.SelectNearestHostileUnitInAggroRange(true); + Unit nearTarget = me.SelectNearestHostileUnitInAggroRange(true, true); if (nearTarget) return nearTarget; } diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 8c613bbdd..81ede10d4 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2858,11 +2858,11 @@ namespace Game.Entities return 0.0f; } - public Unit SelectNearestHostileUnitInAggroRange(bool useLOS = false) + public Unit SelectNearestHostileUnitInAggroRange(bool useLOS = false, bool ignoreCivilians = false) { // Selects nearest hostile target within creature's aggro range. Used primarily by // pets set to aggressive. Will not return neutral or friendly targets - var u_check = new NearestHostileUnitInAggroRangeCheck(this, useLOS); + var u_check = new NearestHostileUnitInAggroRangeCheck(this, useLOS, ignoreCivilians); var searcher = new UnitSearcher(this, u_check); Cell.VisitGridObjects(this, searcher, SharedConst.MaxAggroRadius); return searcher.GetTarget(); diff --git a/Source/Game/Maps/GridNotifiers.cs b/Source/Game/Maps/GridNotifiers.cs index 524da4b60..77c426a39 100644 --- a/Source/Game/Maps/GridNotifiers.cs +++ b/Source/Game/Maps/GridNotifiers.cs @@ -2246,10 +2246,11 @@ namespace Game.Maps class NearestHostileUnitInAggroRangeCheck : ICheck { - public NearestHostileUnitInAggroRangeCheck(Creature creature, bool useLOS = false) + public NearestHostileUnitInAggroRangeCheck(Creature creature, bool useLOS = false, bool ignoreCivilians = false) { _me = creature; _useLOS = useLOS; + _ignoreCivilians = ignoreCivilians; } public bool Invoke(Unit u) @@ -2266,11 +2267,21 @@ namespace Game.Maps if (_useLOS && !u.IsWithinLOSInMap(_me)) return false; + // pets in aggressive do not attack civilians + if (_ignoreCivilians) + { + Creature c = u.ToCreature(); + if (c != null) + if (c.IsCivilian()) + return false; + } + return true; } Creature _me; bool _useLOS; + bool _ignoreCivilians; } class AnyAssistCreatureInRangeCheck : ICheck