[9584] Continue fix loot roll packets and related code.

* Propertly send itemSlot field and use it with looted target for roll selection.
* Remove references to NumberOfPlayers useless data send in args
* Fixed long existed bug with roll show when single player from group can roll item.
* Fixed possible crash at player leave group while item roll
* Fixed wrong item amount in stack in rolls inreasult use non-initilized field as info source.
* Remove unused item guid field from Roll and not lost for nothing item guids for this.

Thanks for help in research to TOM_RUS and j4r0d.
This commit is contained in:
VladimirMangos 2010-03-15 00:52:49 +03:00
parent 996a523302
commit 6bfa8d81c6
4 changed files with 75 additions and 62 deletions

View file

@ -449,7 +449,7 @@ void Group::SendLootStartRoll(uint32 CountDown, const Roll &r)
{ {
WorldPacket data(SMSG_LOOT_START_ROLL, (8+4+4+4+4+4+4+1)); WorldPacket data(SMSG_LOOT_START_ROLL, (8+4+4+4+4+4+4+1));
data << r.lootedTargetGUID; // creature guid what we're looting data << r.lootedTargetGUID; // creature guid what we're looting
data << uint32(r.totalPlayersRolling); // maybe the number of players rolling for it, or item slot in loot data << uint32(r.itemSlot); // item slot in loot
data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for
data << uint32(r.itemRandomSuffix); // randomSuffix data << uint32(r.itemRandomSuffix); // randomSuffix
data << uint32(r.itemRandomPropId); // item random property ID data << uint32(r.itemRandomPropId); // item random property ID
@ -472,7 +472,7 @@ void Group::SendLootRoll(ObjectGuid const& targetGuid, uint8 rollNumber, uint8 r
{ {
WorldPacket data(SMSG_LOOT_ROLL, (8+4+8+4+4+4+1+1+1)); WorldPacket data(SMSG_LOOT_ROLL, (8+4+8+4+4+4+1+1+1));
data << r.lootedTargetGUID; // creature guid what we're looting data << r.lootedTargetGUID; // creature guid what we're looting
data << uint32(0); // unknown, maybe amount of players, or item slot in loot data << uint32(r.itemSlot); // unknown, maybe amount of players, or item slot in loot
data << targetGuid; data << targetGuid;
data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for
data << uint32(r.itemRandomSuffix); // randomSuffix data << uint32(r.itemRandomSuffix); // randomSuffix
@ -496,7 +496,7 @@ void Group::SendLootRollWon(ObjectGuid const& targetGuid, uint8 rollNumber, uint
{ {
WorldPacket data(SMSG_LOOT_ROLL_WON, (8+4+4+4+4+8+1+1)); WorldPacket data(SMSG_LOOT_ROLL_WON, (8+4+4+4+4+8+1+1));
data << r.lootedTargetGUID; // creature guid what we're looting data << r.lootedTargetGUID; // creature guid what we're looting
data << uint32(0); // unknown, maybe amount of players, or item slot in loot data << uint32(r.itemSlot); // item slot in loot
data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for data << uint32(r.itemid); // the itemEntryId for the item that shall be rolled for
data << uint32(r.itemRandomSuffix); // randomSuffix data << uint32(r.itemRandomSuffix); // randomSuffix
data << uint32(r.itemRandomPropId); // Item random property data << uint32(r.itemRandomPropId); // Item random property
@ -515,11 +515,11 @@ void Group::SendLootRollWon(ObjectGuid const& targetGuid, uint8 rollNumber, uint
} }
} }
void Group::SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r) void Group::SendLootAllPassed(Roll const& r)
{ {
WorldPacket data(SMSG_LOOT_ALL_PASSED, (8+4+4+4+4)); WorldPacket data(SMSG_LOOT_ALL_PASSED, (8+4+4+4+4));
data << r.lootedTargetGUID; // creature guid what we're looting data << r.lootedTargetGUID; // creature guid what we're looting
data << uint32(NumberOfPlayers); // The number of players rolling for it, or item slot in loot data << uint32(r.itemSlot); // item slot in loot
data << uint32(r.itemid); // The itemEntryId for the item that shall be rolled for data << uint32(r.itemid); // The itemEntryId for the item that shall be rolled for
data << uint32(r.itemRandomPropId); // Item random property ID data << uint32(r.itemRandomPropId); // Item random property ID
data << uint32(r.itemRandomSuffix); // Item random suffix ID data << uint32(r.itemRandomSuffix); // Item random suffix ID
@ -555,8 +555,7 @@ void Group::GroupLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creatu
//roll for over-threshold item if it's one-player loot //roll for over-threshold item if it's one-player loot
if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall) if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall)
{ {
uint64 newitemGUID = MAKE_NEW_GUID(sObjectMgr.GenerateLowGuid(HIGHGUID_ITEM), 0, HIGHGUID_ITEM); Roll* r=new Roll(creature->GetGUID(),*i);
Roll* r=new Roll(newitemGUID,creature->GetGUID(),*i);
//a vector is filled with only near party members //a vector is filled with only near party members
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next()) for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
@ -574,17 +573,28 @@ void Group::GroupLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creatu
} }
} }
if (r->totalPlayersRolling > 0) // has looters
{
r->setLoot(loot); r->setLoot(loot);
r->itemSlot = itemSlot; r->itemSlot = itemSlot;
if (r->totalPlayersRolling == 1) // single looter
r->playerVote.begin()->second = NEED;
else
{
group->SendLootStartRoll(60000, *r); group->SendLootStartRoll(60000, *r);
loot->items[itemSlot].is_blocked = true; loot->items[itemSlot].is_blocked = true;
creature->m_groupLootTimer = 60000; creature->m_groupLootTimer = 60000;
creature->m_groupLootId = GetId(); creature->m_groupLootId = GetId();
}
RollId.push_back(r); RollId.push_back(r);
} }
else // no looters??
delete r;
}
else else
i->is_underthreshold = 1; i->is_underthreshold = 1;
} }
@ -604,8 +614,7 @@ void Group::NeedBeforeGreed(ObjectGuid const& playerGUID, Loot *loot, Creature *
//only roll for one-player items, not for ones everyone can get //only roll for one-player items, not for ones everyone can get
if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall) if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall)
{ {
uint64 newitemGUID = MAKE_NEW_GUID(sObjectMgr.GenerateLowGuid(HIGHGUID_ITEM), 0, HIGHGUID_ITEM); Roll* r=new Roll(creature->GetGUID(),*i);
Roll* r=new Roll(newitemGUID,creature->GetGUID(),*i);
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next()) for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{ {
@ -623,22 +632,24 @@ void Group::NeedBeforeGreed(ObjectGuid const& playerGUID, Loot *loot, Creature *
} }
} }
if (r->totalPlayersRolling > 0) if (r->totalPlayersRolling > 0) // has looters
{ {
r->setLoot(loot); r->setLoot(loot);
r->itemSlot = itemSlot; r->itemSlot = itemSlot;
if (r->totalPlayersRolling == 1) // single looter
r->playerVote.begin()->second = NEED;
else
{
group->SendLootStartRoll(60000, *r); group->SendLootStartRoll(60000, *r);
loot->items[itemSlot].is_blocked = true; loot->items[itemSlot].is_blocked = true;
}
RollId.push_back(r); RollId.push_back(r);
} }
else else // no looters??
{
delete r; delete r;
} }
}
else else
i->is_underthreshold = 1; i->is_underthreshold = 1;
} }
@ -680,21 +691,31 @@ void Group::MasterLoot(ObjectGuid const& playerGUID, Loot* /*loot*/, Creature *c
} }
} }
void Group::CountRollVote(ObjectGuid const& playerGUID, ObjectGuid const& itemGuid, uint32 numberOfPlayers, uint8 choise) void Group::CountRollVote(ObjectGuid const& playerGUID, ObjectGuid const& lootedTarget, uint32 itemSlot, uint8 choise)
{ {
Rolls::iterator rollI = GetRoll(itemGuid); Rolls::iterator rollI = RollId.begin();
for (; rollI != RollId.end(); ++rollI)
if ((*rollI)->isValid() && (*rollI)->lootedTargetGUID == lootedTarget && (*rollI)->itemSlot == itemSlot)
break;
if (rollI == RollId.end()) if (rollI == RollId.end())
return; return;
CountRollVote(playerGUID, rollI, choise);
}
bool Group::CountRollVote(ObjectGuid const& playerGUID, Rolls::iterator& rollI, uint8 choise)
{
Roll* roll = *rollI; Roll* roll = *rollI;
Roll::PlayerVote::iterator itr = roll->playerVote.find(playerGUID.GetMaxCounter()); Roll::PlayerVote::iterator itr = roll->playerVote.find(playerGUID.GetRawValue());
// this condition means that player joins to the party after roll begins // this condition means that player joins to the party after roll begins
if (itr == roll->playerVote.end()) if (itr == roll->playerVote.end())
return; return false;
if (roll->getLoot()) if (roll->getLoot())
if (roll->getLoot()->items.empty()) if (roll->getLoot()->items.empty())
return; return false;
switch (choise) switch (choise)
{ {
@ -729,8 +750,11 @@ void Group::CountRollVote(ObjectGuid const& playerGUID, ObjectGuid const& itemGu
} }
if (roll->totalPass + roll->totalNeed + roll->totalGreed >= roll->totalPlayersRolling) if (roll->totalPass + roll->totalNeed + roll->totalGreed >= roll->totalPlayersRolling)
{ {
CountTheRoll(rollI, numberOfPlayers); CountTheRoll(rollI);
return true;
} }
return false;
} }
//called when roll timer expires //called when roll timer expires
@ -741,18 +765,17 @@ void Group::EndRoll()
{ {
//need more testing here, if rolls disappear //need more testing here, if rolls disappear
itr = RollId.begin(); itr = RollId.begin();
CountTheRoll(itr, GetMembersCount()); //i don't have to edit player votes, who didn't vote ... he will pass CountTheRoll(itr); //i don't have to edit player votes, who didn't vote ... he will pass
} }
} }
void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers) void Group::CountTheRoll(Rolls::iterator& rollI)
{ {
Roll* roll = *rollI; Roll* roll = *rollI;
if(!roll->isValid()) // is loot already deleted ? if(!roll->isValid()) // is loot already deleted ?
{ {
RollId.erase(rollI); rollI = RollId.erase(rollI);
delete roll; delete roll;
return;
} }
//end of the roll //end of the roll
if (roll->totalNeed > 0) if (roll->totalNeed > 0)
@ -865,11 +888,11 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
} }
else else
{ {
SendLootAllPassed(NumberOfPlayers, *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;
} }
RollId.erase(rollI); rollI = RollId.erase(rollI);
delete roll; delete roll;
} }
@ -1222,7 +1245,7 @@ void Group::_setLeader(const uint64 &guid)
void Group::_removeRolls(const uint64 &guid) void Group::_removeRolls(const uint64 &guid)
{ {
for (Rolls::iterator it = RollId.begin(); it < RollId.end(); ++it) for (Rolls::iterator it = RollId.begin(); it < RollId.end(); )
{ {
Roll* roll = *it; Roll* roll = *it;
Roll::PlayerVote::iterator itr2 = roll->playerVote.find(guid); Roll::PlayerVote::iterator itr2 = roll->playerVote.find(guid);
@ -1240,7 +1263,8 @@ void Group::_removeRolls(const uint64 &guid)
roll->playerVote.erase(itr2); roll->playerVote.erase(itr2);
CountRollVote(guid, roll->itemGUID, GetMembersCount()-1, MAX_ROLL_TYPE); if (!CountRollVote(guid, it, MAX_ROLL_TYPE))
++it;
} }
} }

View file

@ -104,15 +104,14 @@ class InstanceSave;
class Roll : public LootValidatorRef class Roll : public LootValidatorRef
{ {
public: public:
Roll(ObjectGuid _itemGuid, ObjectGuid _lootedTragetGuid, LootItem const& li) Roll(ObjectGuid _lootedTragetGuid, LootItem const& li)
: itemGUID(_itemGuid), lootedTargetGUID(_lootedTragetGuid), itemid(li.itemid), itemRandomPropId(li.randomPropertyId), itemRandomSuffix(li.randomSuffix), : lootedTargetGUID(_lootedTragetGuid), itemid(li.itemid), itemRandomPropId(li.randomPropertyId), itemRandomSuffix(li.randomSuffix),
totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {} itemCount(li.count), totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {}
~Roll() { } ~Roll() { }
void setLoot(Loot *pLoot) { link(pLoot, this); } void setLoot(Loot *pLoot) { link(pLoot, this); }
Loot *getLoot() { return getTarget(); } Loot *getLoot() { return getTarget(); }
void targetObjectBuildLink(); void targetObjectBuildLink();
ObjectGuid itemGUID;
ObjectGuid lootedTargetGUID; ObjectGuid lootedTargetGUID;
uint32 itemid; uint32 itemid;
int32 itemRandomPropId; int32 itemRandomPropId;
@ -316,24 +315,11 @@ class MANGOS_DLL_SPEC Group
void SendLootStartRoll(uint32 CountDown, const Roll &r); void SendLootStartRoll(uint32 CountDown, const Roll &r);
void SendLootRoll(ObjectGuid const& targetGuid, uint8 rollNumber, uint8 rollType, const Roll &r); void SendLootRoll(ObjectGuid const& targetGuid, uint8 rollNumber, uint8 rollType, const Roll &r);
void SendLootRollWon(ObjectGuid const& targetGuid, uint8 rollNumber, uint8 rollType, const Roll &r); void SendLootRollWon(ObjectGuid const& targetGuid, uint8 rollNumber, uint8 rollType, const Roll &r);
void SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r); void SendLootAllPassed(const Roll &r);
void GroupLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creature); void GroupLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creature);
void NeedBeforeGreed(ObjectGuid const& playerGUID, Loot *loot, Creature *creature); void NeedBeforeGreed(ObjectGuid const& playerGUID, Loot *loot, Creature *creature);
void MasterLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creature); void MasterLoot(ObjectGuid const& playerGUID, Loot *loot, Creature *creature);
Rolls::iterator GetRoll(ObjectGuid const& Guid) void CountRollVote(ObjectGuid const& playerGUID, ObjectGuid const& lootedTarget, uint32 itemSlot, uint8 choise);
{
Rolls::iterator iter;
for (iter=RollId.begin(); iter != RollId.end(); ++iter)
{
if ((*iter)->itemGUID == Guid && (*iter)->isValid())
{
return iter;
}
}
return RollId.end();
}
void CountTheRoll(Rolls::iterator roll, uint32 NumberOfPlayers);
void CountRollVote(ObjectGuid const& playerGUID, ObjectGuid const& itemGuid, uint32 numberOfPlayers, uint8 choise);
void EndRoll(); void EndRoll();
void LinkMember(GroupReference *pRef) { m_memberMgr.insertFirst(pRef); } void LinkMember(GroupReference *pRef) { m_memberMgr.insertFirst(pRef); }
@ -404,6 +390,9 @@ class MANGOS_DLL_SPEC Group
--m_subGroupsCounts[subgroup]; --m_subGroupsCounts[subgroup];
} }
void CountTheRoll(Rolls::iterator& roll); // iterator update to next, in CountRollVote if true
bool CountRollVote(ObjectGuid const& playerGUID, Rolls::iterator& roll, uint8 choise);
uint32 m_Id; // 0 for not created or BG groups uint32 m_Id; // 0 for not created or BG groups
MemberSlotList m_memberSlots; MemberSlotList m_memberSlots;
GroupRefManager m_memberMgr; GroupRefManager m_memberMgr;

View file

@ -369,11 +369,11 @@ void WorldSession::HandleLootMethodOpcode( WorldPacket & recv_data )
void WorldSession::HandleLootRoll( WorldPacket &recv_data ) void WorldSession::HandleLootRoll( WorldPacket &recv_data )
{ {
uint64 Guid; ObjectGuid lootedTarget;
uint32 NumberOfPlayers; uint32 itemSlot;
uint8 rollType; uint8 rollType;
recv_data >> Guid; //guid of the item rolled recv_data >> lootedTarget; //guid of the item rolled
recv_data >> NumberOfPlayers; recv_data >> itemSlot;
recv_data >> rollType; recv_data >> rollType;
//sLog.outDebug("WORLD RECIEVE CMSG_LOOT_ROLL, From:%u, Numberofplayers:%u, rollType:%u", (uint32)Guid, NumberOfPlayers, rollType); //sLog.outDebug("WORLD RECIEVE CMSG_LOOT_ROLL, From:%u, Numberofplayers:%u, rollType:%u", (uint32)Guid, NumberOfPlayers, rollType);
@ -383,7 +383,7 @@ void WorldSession::HandleLootRoll( WorldPacket &recv_data )
return; return;
// everything's fine, do it // everything's fine, do it
group->CountRollVote(GetPlayer()->GetGUID(), Guid, NumberOfPlayers, rollType); group->CountRollVote(GetPlayer()->GetObjectGuid(), lootedTarget, itemSlot, rollType);
switch (rollType) switch (rollType)
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9583" #define REVISION_NR "9584"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__