From 1aaa949fffc7d5fd706e40279203f9ab1e28cde4 Mon Sep 17 00:00:00 2001 From: robinsch Date: Sun, 23 Aug 2020 17:36:12 +0200 Subject: [PATCH] Core/Unit: Fixed race condition when loot recipient is in different map --- src/server/game/Entities/Unit/Unit.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index e5ceb19618..250f8730fe 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -11482,8 +11482,30 @@ void Unit::Kill(Unit* victim, bool durabilityLoss) creature->SetLootRecipient(nullptr); } - if (isRewardAllowed && creature && creature->GetLootRecipient()) - player = creature->GetLootRecipient(); + if (isRewardAllowed && creature) + { + if (Player* lootRecipient = creature->GetLootRecipient()) + { + // Loot recipient can be in a different map + if (!creature->IsInMap(lootRecipient)) + { + if (Group* group = creature->GetLootRecipientGroup()) + { + for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) + { + Player* member = itr->GetSource(); + if (!member || !creature->IsInMap(member)) + continue; + + player = member; + break; + } + } + } + else + player = creature->GetLootRecipient(); + } + } // Exploit fix if (creature && creature->IsPet() && creature->GetOwnerOrCreatorGUID().IsPlayer())