diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2017-06-07 02:33:47 +0200 |
|---|---|---|
| committer | Carbenium <carbenium@outlook.com> | 2020-07-16 21:47:28 +0200 |
| commit | f7a7d02a7f50400cdc2be3c4722afeefe7efce80 (patch) | |
| tree | 0f405c9382ec9e96b3a40a8f4f722a07c791bd0f /src/server/game/AI | |
| parent | 5903a10a834b1198702b024182581799648540ff (diff) | |
Pet/Guardian AI hook re-organizing (#19824)
* Pet/Guardian AI hook re-organizing:
- Adjust OwnerAttacked/OwnerAttackedBy hooks on CreatureAI to fire for all owned units, not just player pets. This should allow guardians to more reliably recognize valid targets.
- Kill off the AttackedBy hook. While it was defined in CreatureAI.h as virtual, it was only ever invoked for player pets in specific situations. This makes it classic developer bait.
- Adjust PetAI to use DamageTaken instead of AttackedBy.
- Adjust behavior of AttackStart on PetAI to compensate.
(cherry picked from commit 1660bb7d27d6f42b49012a6b57e3c2b2eab20fd3)
Diffstat (limited to 'src/server/game/AI')
| -rw-r--r-- | src/server/game/AI/CoreAI/PetAI.cpp | 38 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/PetAI.h | 6 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 1 | ||||
| -rw-r--r-- | src/server/game/AI/CreatureAI.cpp | 27 | ||||
| -rw-r--r-- | src/server/game/AI/CreatureAI.h | 8 |
5 files changed, 34 insertions, 46 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index c16e1f945eb..a1c1b72e9b0 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -128,7 +128,7 @@ void PetAI::UpdateAI(uint32 diff) // Aggressive - Allow auto select if owner or pet don't have a target // Stay - Only pick from pet or owner targets / attackers so targets won't run by // while chasing our owner. Don't do auto select. - // All other cases (ie: defensive) - Targets are assigned by AttackedBy(), OwnerAttackedBy(), OwnerAttacked(), etc. + // All other cases (ie: defensive) - Targets are assigned by DamageTaken(), OwnerAttackedBy(), OwnerAttacked(), etc. Unit* nextTarget = SelectNextTarget(me->HasReactState(REACT_AGGRESSIVE)); if (nextTarget) @@ -322,8 +322,18 @@ void PetAI::KilledUnit(Unit* victim) void PetAI::AttackStart(Unit* target) { - // Overrides Unit::AttackStart to correctly evaluate Pet states + // Overrides Unit::AttackStart to prevent pet from switching off its assigned target + if (!target || target == me) + return; + + if (me->GetVictim() && me->EnsureVictim()->IsAlive()) + return; + + _AttackStart(target); +} +void PetAI::_AttackStart(Unit* target) +{ // Check all pet states to decide if we can attack this target if (!CanAttack(target)) return; @@ -337,7 +347,7 @@ void PetAI::OwnerAttackedBy(Unit* attacker) // Called when owner takes damage. This function helps keep pets from running off // simply due to owner gaining aggro. - if (!attacker) + if (!attacker || !me->IsAlive()) return; // Passive pets don't do anything @@ -358,7 +368,7 @@ void PetAI::OwnerAttacked(Unit* target) // that they need to assist // Target might be NULL if called from spell with invalid cast targets - if (!target) + if (!target || !me->IsAlive()) return; // Passive pets don't do anything @@ -626,23 +636,3 @@ void PetAI::ClearCharmInfoFlags() ci->SetIsReturning(false); } } - -void PetAI::AttackedBy(Unit* attacker) -{ - // Called when pet takes damage. This function helps keep pets from running off - // simply due to gaining aggro. - - if (!attacker) - return; - - // Passive pets don't do anything - if (me->HasReactState(REACT_PASSIVE)) - return; - - // Prevent pet from disengaging from current target - if (me->GetVictim() && me->EnsureVictim()->IsAlive()) - return; - - // Continue to evaluate and attack if necessary - AttackStart(attacker); -} diff --git a/src/server/game/AI/CoreAI/PetAI.h b/src/server/game/AI/CoreAI/PetAI.h index 4455c1cd494..e243d06debc 100644 --- a/src/server/game/AI/CoreAI/PetAI.h +++ b/src/server/game/AI/CoreAI/PetAI.h @@ -36,11 +36,12 @@ class TC_GAME_API PetAI : public CreatureAI static int32 Permissible(Creature const* creature); void KilledUnit(Unit* /*victim*/) override; - void AttackStart(Unit* target) override; + void AttackStart(Unit* target) override; // only start attacking if not attacking something else already + void _AttackStart(Unit* target); // always start attacking if possible void MovementInform(uint32 moveType, uint32 data) override; void OwnerAttackedBy(Unit* attacker) override; void OwnerAttacked(Unit* target) override; - void AttackedBy(Unit* attacker) override; + void DamageTaken(Unit* attacker, uint32& /*damage*/) override { AttackStart(attacker); } void ReceiveEmote(Player* player, uint32 textEmote) override; // The following aren't used by the PetAI but need to be defined to override @@ -53,7 +54,6 @@ class TC_GAME_API PetAI : public CreatureAI void OnCharmed(bool /*apply*/) override; private: - bool _isVisible(Unit*) const; bool _needToStop(void); void _stopAttack(void); diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index 508d9e70d70..39f54dff66a 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -246,7 +246,6 @@ class TC_GAME_API UnitAI // Called at any Damage from any attacker (before damage apply) // Note: it for recalculation damage or special reaction at damage - // for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also virtual void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/) { } // Called when the creature receives heal diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 80d59e4e7cc..54fbabd0b50 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -147,15 +147,22 @@ void CreatureAI::MoveInLineOfSight(Unit* who) if (me->GetVictim()) return; - if (me->GetCreatureType() == CREATURE_TYPE_NON_COMBAT_PET) // non-combat pets should just stand there and look good;) - return; - if (me->HasReactState(REACT_AGGRESSIVE) && me->CanStartAttack(who, false)) AttackStart(who); - //else if (who->GetVictim() && me->IsFriendlyTo(who) - // && me->IsWithinDistInMap(who, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS)) - // && me->CanStartAttack(who->GetVictim(), true)) /// @todo if we use true, it will not attack it when it arrives - // me->GetMotionMaster()->MoveChase(who->GetVictim()); +} + +void CreatureAI::_OnOwnerCombatInteraction(Unit* target) +{ + if (!target || !me->IsAlive()) + return; + + if (!me->HasReactState(REACT_PASSIVE) && me->CanStartAttack(target, true)) + { + if (me->IsInCombat()) + me->AddThreat(target, 0.0f); + else + AttackStart(target); + } } // Distract creature, if player gets too close while stealthed/prowling @@ -211,12 +218,6 @@ void CreatureAI::EnterEvadeMode(EvadeReason why) me->GetVehicleKit()->Reset(true); } -/*void CreatureAI::AttackedBy(Unit* attacker) -{ - if (!me->GetVictim()) - AttackStart(attacker); -}*/ - void CreatureAI::SetGazeOn(Unit* target) { if (me->IsValidAttackTarget(target)) diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 41e6ab2501d..754e936862d 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -119,8 +119,6 @@ class TC_GAME_API CreatureAI : public UnitAI // Called when spell hits a target virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spell*/) { } - // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) - virtual void AttackedBy(Unit* /*attacker*/) { } virtual bool IsEscorted() const { return false; } // Called when creature is spawned or respawned @@ -146,15 +144,14 @@ class TC_GAME_API CreatureAI : public UnitAI virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) { } // Called when owner takes damage - virtual void OwnerAttackedBy(Unit* /*attacker*/) { } + virtual void OwnerAttackedBy(Unit* attacker) { _OnOwnerCombatInteraction(attacker); } // Called when owner attacks something - virtual void OwnerAttacked(Unit* /*target*/) { } + virtual void OwnerAttacked(Unit* target) { _OnOwnerCombatInteraction(target); } /// == Triggered Actions Requested ================== // Called when creature attack expected (if creature can and no have current victim) - // Note: for reaction at hostile action must be called AttackedBy function. //virtual void AttackStart(Unit*) { } // Called at World update tick @@ -202,6 +199,7 @@ class TC_GAME_API CreatureAI : public UnitAI private: bool m_MoveInLineOfSight_locked; + void _OnOwnerCombatInteraction(Unit* target); }; enum Permitions : int32 |
