Merge pull request #82 from Olion17/develop21

Fixing crash at player leave map during loot roll
This commit is contained in:
Antz 2016-02-16 22:00:17 +00:00
commit 2acb9ffdd4
2 changed files with 72 additions and 61 deletions

View File

@ -1019,13 +1019,13 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
} }
// end of the roll // end of the roll
bool won = false;
if (roll->totalNeed > 0) if (roll->totalNeed > 0)
{ {
if (!roll->playerVote.empty()) if (!roll->playerVote.empty())
{ {
uint8 maxresul = 0; uint8 maxresul = 0;
ObjectGuid maxguid = (*roll->playerVote.begin()).first; ObjectGuid maxguid = (*roll->playerVote.begin()).first;
Player* player;
for (Roll::PlayerVote::const_iterator itr = roll->playerVote.begin(); itr != roll->playerVote.end(); ++itr) for (Roll::PlayerVote::const_iterator itr = roll->playerVote.begin(); itr != roll->playerVote.end(); ++itr)
{ {
@ -1040,10 +1040,14 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
maxresul = randomN; maxresul = randomN;
} }
} }
SendLootRollWon(maxguid, maxresul, ROLL_NEED, *roll);
player = sObjectMgr.GetPlayer(maxguid);
if (player && player->GetSession()) if (Player* player = sObjectMgr.GetPlayer(maxguid))
{
if (Object* object = player->GetMap()->GetWorldObject(roll->lootedTargetGUID))
{
SendLootRollWon(maxguid, maxresul, ROLL_NEED, *roll);
won = true;
if (player->GetSession())
{ {
ItemPosCountVec dest; ItemPosCountVec dest;
LootItem* item = &(roll->getLoot()->items[roll->itemSlot]); LootItem* item = &(roll->getLoot()->items[roll->itemSlot]);
@ -1056,12 +1060,10 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
Item* newitem = player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId); Item* newitem = player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId);
player->SendNewItem(newitem, uint32(item->count), false, false, true); player->SendNewItem(newitem, uint32(item->count), false, false, true);
Object * object = player->GetMap()->GetWorldObject(roll->lootedTargetGUID);
if (object->GetTypeId() == TYPEID_UNIT) if (object->GetTypeId() == TYPEID_UNIT)
{ {
/// Warn players about the loot status on the corpse. /// Warn players about the loot status on the corpse.
Creature * creature = player->GetMap()->GetCreature(roll->lootedTargetGUID); Creature * creature = object->ToCreature();
/// If creature has been fully looted, remove flag. /// If creature has been fully looted, remove flag.
if (creature->loot.isLooted()) if (creature->loot.isLooted())
{ {
@ -1078,13 +1080,15 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
} }
} }
} }
else if (roll->totalGreed > 0) }
}
if (!won && roll->totalGreed > 0)
{ {
if (!roll->playerVote.empty()) if (!roll->playerVote.empty())
{ {
uint8 maxresul = 0; uint8 maxresul = 0;
ObjectGuid maxguid = (*roll->playerVote.begin()).first; ObjectGuid maxguid = (*roll->playerVote.begin()).first;
Player* player;
RollVote rollvote = ROLL_PASS; // Fixed: Using uninitialized memory 'rollvote' RollVote rollvote = ROLL_PASS; // Fixed: Using uninitialized memory 'rollvote'
Roll::PlayerVote::iterator itr; Roll::PlayerVote::iterator itr;
@ -1101,10 +1105,14 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
maxresul = randomN; maxresul = randomN;
} }
} }
SendLootRollWon(maxguid, maxresul, ROLL_GREED, *roll);
player = sObjectMgr.GetPlayer(maxguid);
if (player && player->GetSession()) if (Player* player = sObjectMgr.GetPlayer(maxguid))
{
if (Object * object = player->GetMap()->GetWorldObject(roll->lootedTargetGUID))
{
SendLootRollWon(maxguid, maxresul, ROLL_GREED, *roll);
won = true;
if (player->GetSession())
{ {
ItemPosCountVec dest; ItemPosCountVec dest;
LootItem* item = &(roll->getLoot()->items[roll->itemSlot]); LootItem* item = &(roll->getLoot()->items[roll->itemSlot]);
@ -1116,12 +1124,10 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
--roll->getLoot()->unlootedCount; --roll->getLoot()->unlootedCount;
Item* newitem = player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId); Item* newitem = player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId);
player->SendNewItem(newitem, uint32(item->count), false, false, true); player->SendNewItem(newitem, uint32(item->count), false, false, true);
Object * object = player->GetMap()->GetWorldObject(roll->lootedTargetGUID);
if (object->GetTypeId() == TYPEID_UNIT) if (object->GetTypeId() == TYPEID_UNIT)
{ {
/// Warn players about the loot status on the corpse. /// Warn players about the loot status on the corpse.
Creature * creature = player->GetMap()->GetCreature(roll->lootedTargetGUID); Creature * creature = object->ToCreature();
/// If creature has been fully looted, remove flag. /// If creature has been fully looted, remove flag.
if (creature->loot.isLooted()) if (creature->loot.isLooted())
{ {
@ -1140,11 +1146,17 @@ void Group::CountTheRoll(Rolls::iterator& rollI)
} }
} }
} }
else }
}
if (!won)
{ {
SendLootAllPassed(*roll); SendLootAllPassed(*roll);
LootItem* item = &(roll->getLoot()->items[roll->itemSlot]); LootItem* item = &(roll->getLoot()->items[roll->itemSlot]);
if (item) { item->is_blocked = false; } if (item)
{
item->is_blocked = false;
}
} }
rollI = RollId.erase(rollI); rollI = RollId.erase(rollI);

View File

@ -385,7 +385,6 @@ class Group
} }
void SetTargetIcon(uint8 id, ObjectGuid targetGuid); void SetTargetIcon(uint8 id, ObjectGuid targetGuid);
uint16 InInstance();
bool InCombatToInstance(uint32 instanceId); bool InCombatToInstance(uint32 instanceId);
void ResetInstances(InstanceResetMethod method, Player* SendMsgTo); void ResetInstances(InstanceResetMethod method, Player* SendMsgTo);