aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2018-08-23 23:46:52 +0200
committerShauren <shauren.trinity@gmail.com>2021-10-22 23:51:36 +0200
commit070bbb6707028d8c445c8e408d391f80df011d53 (patch)
tree7d3763bf853edfe259dc6da5dfac2347969d84b8
parente4e8c1c59c8b37216814526b4d2551f23934f465 (diff)
Core/Unit: Acquire GetControllingPlayer. Use to fix duel bugs.
(cherry picked from commit d2d9f470c388a80d395e9a49a860ceb0b7e27fd3)
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp22
-rw-r--r--src/server/game/Entities/Unit/Unit.h3
2 files changed, 17 insertions, 8 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index d4b032ef359..f46ec932614 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -768,7 +768,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
return 0;
// prevent kill only if killed in duel and killed by opponent or opponent controlled creature
- if (victim->ToPlayer()->duel->opponent == attacker || victim->ToPlayer()->duel->opponent->GetGUID() == attacker->GetOwnerGUID())
+ if (victim->ToPlayer()->duel->opponent == attacker->GetControllingPlayer())
damage = health - 1;
duel_hasEnded = true;
@@ -783,7 +783,7 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
return 0;
// prevent kill only if killed in duel and killed by opponent or opponent controlled creature
- if (victimRider->duel->opponent == attacker || victimRider->duel->opponent->GetGUID() == attacker->GetCharmerGUID())
+ if (victimRider->duel->opponent == attacker->GetControllingPlayer())
damage = health - 1;
duel_wasMounted = true;
@@ -5733,6 +5733,19 @@ void Unit::SetOwnerGUID(ObjectGuid owner)
player->SendDirectMessage(&packet);
}
+Player* Unit::GetControllingPlayer() const
+{
+ ObjectGuid guid = GetCharmerOrOwnerGUID();
+ if (!guid.IsEmpty())
+ {
+ if (Unit* master = ObjectAccessor::GetUnit(*this, guid))
+ return master->GetControllingPlayer();
+ return nullptr;
+ }
+ else
+ return const_cast<Player*>(ToPlayer());
+}
+
Unit* Unit::GetCharmer() const
{
ObjectGuid charmerGUID = GetCharmerGUID();
@@ -9744,11 +9757,6 @@ void Unit::TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, AuraApplicationProc
SetCantProc(false);
}
-ObjectGuid Unit::GetCharmerOrOwnerGUID() const
-{
- return !GetCharmerGUID().IsEmpty() ? GetCharmerGUID() : GetOwnerGUID();
-}
-
///----------Pet responses methods-----------------
void Unit::SendPetActionFeedback(PetActionFeedback msg, uint32 spellId)
{
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index df0e080915b..78251ef831d 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -1247,7 +1247,8 @@ class TC_GAME_API Unit : public WorldObject
void SetDemonCreatorGUID(ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::DemonCreator), guid); }
bool IsControlledByPlayer() const { return m_ControlledByPlayer; }
- ObjectGuid GetCharmerOrOwnerGUID() const override;
+ Player* GetControllingPlayer() const;
+ ObjectGuid GetCharmerOrOwnerGUID() const override { return IsCharmed() ? GetCharmerGUID() : GetOwnerGUID(); }
bool IsCharmedOwnedByPlayerOrPlayer() const { return GetCharmerOrOwnerOrOwnGUID().IsPlayer(); }
Guardian* GetGuardianPet() const;