mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-06 00:48:39 +01:00
[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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user