aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2017-06-07 02:33:47 +0200
committerGitHub <noreply@github.com>2017-06-07 02:33:47 +0200
commit1660bb7d27d6f42b49012a6b57e3c2b2eab20fd3 (patch)
treecf63a9cb6e89e621d7ae8b901684bc98a40a7e08 /src/server/game/Entities
parent2335b9de1a46a409c714a1dc89cbd0565545e70e (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.
Diffstat (limited to 'src/server/game/Entities')
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index f16366e50e9..e1633edbeaa 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -683,20 +683,16 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
// Signal to pets that their owner was attacked - except when DOT.
if (damagetype != DOT)
{
- Pet* pet = victim->ToPlayer()->GetPet();
-
- if (pet && pet->IsAlive())
- pet->AI()->OwnerAttackedBy(this);
+ for (Unit* controlled : victim->m_Controlled)
+ if (Creature* cControlled = controlled->ToCreature())
+ if (cControlled->IsAIEnabled)
+ cControlled->AI()->OwnerAttackedBy(this);
}
if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
return 0;
}
- // Signal the pet it was attacked so the AI can respond if needed
- if (victim->GetTypeId() == TYPEID_UNIT && this != victim && victim->IsPet() && victim->IsAlive())
- victim->ToPet()->AI()->AttackedBy(this);
-
if (damagetype != NODAMAGE)
{
// interrupting auras with AURA_INTERRUPT_FLAG_DAMAGE before checking !damage (absorbed damage breaks that type of auras)
@@ -5894,10 +5890,10 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
// Spells such as auto-shot and others handled in WorldSession::HandleCastSpellOpcode
if (GetTypeId() == TYPEID_PLAYER)
{
- Pet* playerPet = this->ToPlayer()->GetPet();
-
- if (playerPet && playerPet->IsAlive())
- playerPet->AI()->OwnerAttacked(victim);
+ for (Unit* controlled : m_Controlled)
+ if (Creature* cControlled = controlled->ToCreature())
+ if (cControlled->IsAIEnabled)
+ cControlled->AI()->OwnerAttacked(victim);
}
return true;
@@ -8682,12 +8678,7 @@ void Unit::CombatStart(Unit* target, bool initialAggro)
if (!target->IsInCombat() && target->GetTypeId() != TYPEID_PLAYER
&& !target->ToCreature()->HasReactState(REACT_PASSIVE) && target->ToCreature()->IsAIEnabled)
- {
- if (target->IsPet())
- target->ToCreature()->AI()->AttackedBy(this); // PetAI has special handler before AttackStart()
- else
- target->ToCreature()->AI()->AttackStart(this);
- }
+ target->ToCreature()->AI()->AttackStart(this);
SetInCombatWith(target);
target->SetInCombatWith(this);