From 10ad759653d34a5aea26316f617b0fe107c6b642 Mon Sep 17 00:00:00 2001 From: patou01 <2592673+patou01@users.noreply.github.com> Date: Thu, 16 Sep 2021 10:27:28 +0200 Subject: [PATCH] fix(Core/Unit): Improve pets behavior (#7836) --- src/server/game/Entities/Unit/Unit.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 4279d2d4b..7d593cd8c 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -12734,7 +12734,33 @@ void Unit::CombatStart(Unit* target, bool initialAggro) if (target->IsPet()) target->ToCreature()->AI()->AttackedBy(this); // PetAI has special handler before AttackStart() else + { target->ToCreature()->AI()->AttackStart(this); + // if the target is an NPC with a pet or minion, pet should react. + if (Unit* targetControlledUnit = target->GetFirstControlled()) + { + targetControlledUnit->SetInCombatWith(this); + SetInCombatWith(targetControlledUnit); + targetControlledUnit->AddThreat(this, 0.0f); + } + } + + // if unit has an owner, put owner in combat. + if (Unit* targetOwner = target->GetOwner()) + { + if (!(targetOwner->IsInCombatWith(this))) + { + /* warding off to not take over aggro for no reason + Using only AddThreat causes delay in attack */ + if (!targetOwner->IsInCombat() && targetOwner->IsAIEnabled) + { + targetOwner->ToCreature()->AI()->AttackStart(this); + } + targetOwner->SetInCombatWith(this); + SetInCombatWith(targetOwner); + targetOwner->AddThreat(this, 0.0f); + } + } } SetInCombatWith(target);