aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSorikoff <46191832+Sorikoff@users.noreply.github.com>2020-02-16 17:00:54 +0200
committerGitHub <noreply@github.com>2020-02-16 16:00:54 +0100
commit5f20715e2f38a6eb721f443df9e13c84ecb11fbb (patch)
tree3e579145e64c9ab6bab717651a6d13ec73c3e199 /src
parent6176ce92ea01fd33b11c2e7f8e9ebb509e80c944 (diff)
[WIP] Core/AI: Pets musn't attack civilian NPC in aggressive mode (#24121)
* Core/AI: Pets musn't attack civilian NPC in aggressive mode * Move decision to ignore civilians to PetAI, keeping the check in GridNotifiers Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/CoreAI/PetAI.cpp2
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp4
-rw-r--r--src/server/game/Entities/Creature/Creature.h2
-rw-r--r--src/server/game/Grids/Notifiers/GridNotifiers.h9
4 files changed, 12 insertions, 5 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp
index 4ae3f985ba1..f53a4277c6e 100644
--- a/src/server/game/AI/CoreAI/PetAI.cpp
+++ b/src/server/game/AI/CoreAI/PetAI.cpp
@@ -349,7 +349,7 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const
if (me->HasReactState(REACT_AGGRESSIVE) && allowAutoSelect)
{
if (!me->GetCharmInfo()->IsReturning() || me->GetCharmInfo()->IsFollowing() || me->GetCharmInfo()->IsAtStay())
- if (Unit* nearTarget = me->SelectNearestHostileUnitInAggroRange(true))
+ if (Unit* nearTarget = me->SelectNearestHostileUnitInAggroRange(true, true))
return nearTarget;
}
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index c2aee8683c6..f45bb607890 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -2990,14 +2990,14 @@ float Creature::GetAggroRange(Unit const* target) const
return 0.0f;
}
-Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS) const
+Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS, bool ignoreCivilians) const
{
// Selects nearest hostile target within creature's aggro range. Used primarily by
// pets set to aggressive. Will not return neutral or friendly targets.
Unit* target = nullptr;
- Trinity::NearestHostileUnitInAggroRangeCheck u_check(this, useLOS);
+ Trinity::NearestHostileUnitInAggroRangeCheck u_check(this, useLOS, ignoreCivilians);
Trinity::UnitSearcher<Trinity::NearestHostileUnitInAggroRangeCheck> searcher(this, target, u_check);
Cell::VisitGridObjects(this, searcher, MAX_AGGRO_RADIUS);
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 87de314fb70..47f8d0d602a 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -232,7 +232,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
Unit* SelectNearestTarget(float dist = 0, bool playerOnly = false) const;
Unit* SelectNearestTargetInAttackDistance(float dist = 0) const;
- Unit* SelectNearestHostileUnitInAggroRange(bool useLOS = false) const;
+ Unit* SelectNearestHostileUnitInAggroRange(bool useLOS = false, bool ignoreCivilians = false) const;
void DoFleeToGetAssistance();
void CallForHelp(float fRadius);
diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h
index 923888c72a3..3fd95339948 100644
--- a/src/server/game/Grids/Notifiers/GridNotifiers.h
+++ b/src/server/game/Grids/Notifiers/GridNotifiers.h
@@ -1180,7 +1180,7 @@ namespace Trinity
class NearestHostileUnitInAggroRangeCheck
{
public:
- explicit NearestHostileUnitInAggroRangeCheck(Creature const* creature, bool useLOS = false) : _me(creature), _useLOS(useLOS) { }
+ explicit NearestHostileUnitInAggroRangeCheck(Creature const* creature, bool useLOS = false, bool ignoreCivilians = false) : _me(creature), _useLOS(useLOS), _ignoreCivilians(ignoreCivilians) { }
bool operator()(Unit* u) const
{
@@ -1196,12 +1196,19 @@ namespace Trinity
if (_useLOS && !u->IsWithinLOSInMap(_me))
return false;
+ // pets in aggressive do not attack civilians
+ if (_ignoreCivilians)
+ if (Creature* c = u->ToCreature())
+ if (c->IsCivilian())
+ return false;
+
return true;
}
private:
Creature const* _me;
bool _useLOS;
+ bool _ignoreCivilians;
NearestHostileUnitInAggroRangeCheck(NearestHostileUnitInAggroRangeCheck const&) = delete;
};