[11454] Use ObjectGuid in class Loot

This commit is contained in:
VladimirMangos 2011-05-09 19:09:45 +04:00
parent 706c97c943
commit b647835469
5 changed files with 66 additions and 62 deletions

View file

@ -495,7 +495,7 @@ void WorldSession::DoLootRelease(ObjectGuid lguid)
} }
//Player is not looking at loot list, he doesn't need to see updates on the loot list //Player is not looking at loot list, he doesn't need to see updates on the loot list
loot->RemoveLooter(player->GetGUID()); loot->RemoveLooter(player->GetObjectGuid());
} }
void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data ) void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data )

View file

@ -422,8 +422,8 @@ void Loot::AddItem(LootStoreItem const & item)
{ {
if (item.needs_quest) // Quest drop if (item.needs_quest) // Quest drop
{ {
if (quest_items.size() < MAX_NR_QUEST_ITEMS) if (m_questItems.size() < MAX_NR_QUEST_ITEMS)
quest_items.push_back(LootItem(item)); m_questItems.push_back(LootItem(item));
} }
else if (items.size() < MAX_NR_LOOT_ITEMS) // Non-quest drop else if (items.size() < MAX_NR_LOOT_ITEMS) // Non-quest drop
{ {
@ -458,7 +458,7 @@ bool Loot::FillLoot(uint32 loot_id, LootStore const& store, Player* loot_owner,
} }
items.reserve(MAX_NR_LOOT_ITEMS); items.reserve(MAX_NR_LOOT_ITEMS);
quest_items.reserve(MAX_NR_QUEST_ITEMS); m_questItems.reserve(MAX_NR_QUEST_ITEMS);
tab->Process(*this, store,store.IsRatesAllowed ()); // Processing is done there, callback via Loot::AddItem() tab->Process(*this, store,store.IsRatesAllowed ()); // Processing is done there, callback via Loot::AddItem()
@ -481,16 +481,16 @@ void Loot::FillNotNormalLootFor(Player* pl)
{ {
uint32 plguid = pl->GetGUIDLow(); uint32 plguid = pl->GetGUIDLow();
QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(plguid); QuestItemMap::const_iterator qmapitr = m_playerQuestItems.find(plguid);
if (qmapitr == PlayerQuestItems.end()) if (qmapitr == m_playerQuestItems.end())
FillQuestLoot(pl); FillQuestLoot(pl);
qmapitr = PlayerFFAItems.find(plguid); qmapitr = m_playerFFAItems.find(plguid);
if (qmapitr == PlayerFFAItems.end()) if (qmapitr == m_playerFFAItems.end())
FillFFALoot(pl); FillFFALoot(pl);
qmapitr = PlayerNonQuestNonFFAConditionalItems.find(plguid); qmapitr = m_playerNonQuestNonFFAConditionalItems.find(plguid);
if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end()) if (qmapitr == m_playerNonQuestNonFFAConditionalItems.end())
FillNonQuestNonFFAConditionalLoot(pl); FillNonQuestNonFFAConditionalLoot(pl);
} }
@ -513,7 +513,7 @@ QuestItemList* Loot::FillFFALoot(Player* player)
return NULL; return NULL;
} }
PlayerFFAItems[player->GetGUIDLow()] = ql; m_playerFFAItems[player->GetGUIDLow()] = ql;
return ql; return ql;
} }
@ -522,9 +522,9 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
if (items.size() == MAX_NR_LOOT_ITEMS) return NULL; if (items.size() == MAX_NR_LOOT_ITEMS) return NULL;
QuestItemList *ql = new QuestItemList(); QuestItemList *ql = new QuestItemList();
for(uint8 i = 0; i < quest_items.size(); ++i) for(uint8 i = 0; i < m_questItems.size(); ++i)
{ {
LootItem &item = quest_items[i]; LootItem &item = m_questItems[i];
if(!item.is_looted && item.AllowedForPlayer(player) ) if(!item.is_looted && item.AllowedForPlayer(player) )
{ {
ql->push_back(QuestItem(i)); ql->push_back(QuestItem(i));
@ -548,7 +548,7 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
return NULL; return NULL;
} }
PlayerQuestItems[player->GetGUIDLow()] = ql; m_playerQuestItems[player->GetGUIDLow()] = ql;
return ql; return ql;
} }
@ -575,7 +575,7 @@ QuestItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player)
return NULL; return NULL;
} }
PlayerNonQuestNonFFAConditionalItems[player->GetGUIDLow()] = ql; m_playerNonQuestNonFFAConditionalItems[player->GetGUIDLow()] = ql;
return ql; return ql;
} }
@ -585,30 +585,30 @@ void Loot::NotifyItemRemoved(uint8 lootIndex)
{ {
// notify all players that are looting this that the item was removed // notify all players that are looting this that the item was removed
// convert the index to the slot the player sees // convert the index to the slot the player sees
std::set<uint64>::iterator i_next; PlayersLooting::iterator i_next;
for(std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) for (PlayersLooting::iterator i = m_playersLooting.begin(); i != m_playersLooting.end(); i = i_next)
{ {
i_next = i; i_next = i;
++i_next; ++i_next;
if(Player* pl = ObjectAccessor::FindPlayer(*i)) if (Player* pl = ObjectAccessor::FindPlayer(*i))
pl->SendNotifyLootItemRemoved(lootIndex); pl->SendNotifyLootItemRemoved(lootIndex);
else else
PlayersLooting.erase(i); m_playersLooting.erase(i);
} }
} }
void Loot::NotifyMoneyRemoved() void Loot::NotifyMoneyRemoved()
{ {
// notify all players that are looting this that the money was removed // notify all players that are looting this that the money was removed
std::set<uint64>::iterator i_next; PlayersLooting::iterator i_next;
for(std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) for (PlayersLooting::iterator i = m_playersLooting.begin(); i != m_playersLooting.end(); i = i_next)
{ {
i_next = i; i_next = i;
++i_next; ++i_next;
if(Player* pl = ObjectAccessor::FindPlayer(*i)) if (Player* pl = ObjectAccessor::FindPlayer(*i))
pl->SendNotifyLootMoneyRemoved(); pl->SendNotifyLootMoneyRemoved();
else else
PlayersLooting.erase(i); m_playersLooting.erase(i);
} }
} }
@ -619,15 +619,15 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex)
// (other questitems can be looted by each group member) // (other questitems can be looted by each group member)
// bit inefficient but isnt called often // bit inefficient but isnt called often
std::set<uint64>::iterator i_next; PlayersLooting::iterator i_next;
for(std::set<uint64>::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) for (PlayersLooting::iterator i = m_playersLooting.begin(); i != m_playersLooting.end(); i = i_next)
{ {
i_next = i; i_next = i;
++i_next; ++i_next;
if(Player* pl = ObjectAccessor::FindPlayer(*i)) if (Player* pl = ObjectAccessor::FindPlayer(*i))
{ {
QuestItemMap::const_iterator pq = PlayerQuestItems.find(pl->GetGUIDLow()); QuestItemMap::const_iterator pq = m_playerQuestItems.find(pl->GetGUIDLow());
if (pq != PlayerQuestItems.end() && pq->second) if (pq != m_playerQuestItems.end() && pq->second)
{ {
// find where/if the player has the given item in it's vector // find where/if the player has the given item in it's vector
QuestItemList& pql = *pq->second; QuestItemList& pql = *pq->second;
@ -642,7 +642,7 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex)
} }
} }
else else
PlayersLooting.erase(i); m_playersLooting.erase(i);
} }
} }
@ -666,13 +666,13 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite
if (lootSlot >= items.size()) if (lootSlot >= items.size())
{ {
uint32 questSlot = lootSlot - items.size(); uint32 questSlot = lootSlot - items.size();
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow()); QuestItemMap::const_iterator itr = m_playerQuestItems.find(player->GetGUIDLow());
if (itr != PlayerQuestItems.end() && questSlot < itr->second->size()) if (itr != m_playerQuestItems.end() && questSlot < itr->second->size())
{ {
QuestItem *qitem2 = &itr->second->at(questSlot); QuestItem *qitem2 = &itr->second->at(questSlot);
if(qitem) if(qitem)
*qitem = qitem2; *qitem = qitem2;
item = &quest_items[qitem2->index]; item = &m_questItems[qitem2->index];
is_looted = qitem2->is_looted; is_looted = qitem2->is_looted;
} }
} }
@ -682,8 +682,8 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite
is_looted = item->is_looted; is_looted = item->is_looted;
if(item->freeforall) if(item->freeforall)
{ {
QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUIDLow()); QuestItemMap::const_iterator itr = m_playerFFAItems.find(player->GetGUIDLow());
if (itr != PlayerFFAItems.end()) if (itr != m_playerFFAItems.end())
{ {
for(QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter) for(QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
if(iter->index==lootSlot) if(iter->index==lootSlot)
@ -698,8 +698,8 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite
} }
else if(item->conditionId) else if(item->conditionId)
{ {
QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow()); QuestItemMap::const_iterator itr = m_playerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
if (itr != PlayerNonQuestNonFFAConditionalItems.end()) if (itr != m_playerNonQuestNonFFAConditionalItems.end())
{ {
for(QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter) for(QuestItemList::const_iterator iter=itr->second->begin(); iter!= itr->second->end(); ++iter)
{ {
@ -724,8 +724,8 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem **qite
uint32 Loot::GetMaxSlotInLootFor(Player* player) const uint32 Loot::GetMaxSlotInLootFor(Player* player) const
{ {
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow()); QuestItemMap::const_iterator itr = m_playerQuestItems.find(player->GetGUIDLow());
return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0); return items.size() + (itr != m_playerQuestItems.end() ? itr->second->size() : 0);
} }
ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li) ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li)
@ -802,7 +802,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
QuestItemList *q_list = q_itr->second; QuestItemList *q_list = q_itr->second;
for (QuestItemList::const_iterator qi = q_list->begin() ; qi != q_list->end(); ++qi) for (QuestItemList::const_iterator qi = q_list->begin() ; qi != q_list->end(); ++qi)
{ {
LootItem &item = l.quest_items[qi->index]; LootItem &item = l.m_questItems[qi->index];
if (!qi->is_looted && !item.is_looted) if (!qi->is_looted && !item.is_looted)
{ {
b << uint8(l.items.size() + (qi - q_list->begin())); b << uint8(l.items.size() + (qi - q_list->begin()));

View file

@ -21,6 +21,7 @@
#include "ItemEnchantmentMgr.h" #include "ItemEnchantmentMgr.h"
#include "ByteBuffer.h" #include "ByteBuffer.h"
#include "ObjectGuid.h"
#include "Utilities/LinkedReference/RefManager.h" #include "Utilities/LinkedReference/RefManager.h"
#include <map> #include <map>
@ -235,9 +236,9 @@ struct Loot
{ {
friend ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv); friend ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv);
QuestItemMap const& GetPlayerQuestItems() const { return PlayerQuestItems; } QuestItemMap const& GetPlayerQuestItems() const { return m_playerQuestItems; }
QuestItemMap const& GetPlayerFFAItems() const { return PlayerFFAItems; } QuestItemMap const& GetPlayerFFAItems() const { return m_playerFFAItems; }
QuestItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return PlayerNonQuestNonFFAConditionalItems; } QuestItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return m_playerNonQuestNonFFAConditionalItems; }
LootItemList items; LootItemList items;
uint32 gold; uint32 gold;
@ -250,30 +251,30 @@ struct Loot
// if loot becomes invalid this reference is used to inform the listener // if loot becomes invalid this reference is used to inform the listener
void addLootValidatorRef(LootValidatorRef* pLootValidatorRef) void addLootValidatorRef(LootValidatorRef* pLootValidatorRef)
{ {
i_LootValidatorRefManager.insertFirst(pLootValidatorRef); m_LootValidatorRefManager.insertFirst(pLootValidatorRef);
} }
// void clear(); // void clear();
void clear() void clear()
{ {
for (QuestItemMap::const_iterator itr = PlayerQuestItems.begin(); itr != PlayerQuestItems.end(); ++itr) for (QuestItemMap::const_iterator itr = m_playerQuestItems.begin(); itr != m_playerQuestItems.end(); ++itr)
delete itr->second; delete itr->second;
PlayerQuestItems.clear(); m_playerQuestItems.clear();
for (QuestItemMap::const_iterator itr = PlayerFFAItems.begin(); itr != PlayerFFAItems.end(); ++itr) for (QuestItemMap::const_iterator itr = m_playerFFAItems.begin(); itr != m_playerFFAItems.end(); ++itr)
delete itr->second; delete itr->second;
PlayerFFAItems.clear(); m_playerFFAItems.clear();
for (QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.begin(); itr != PlayerNonQuestNonFFAConditionalItems.end(); ++itr) for (QuestItemMap::const_iterator itr = m_playerNonQuestNonFFAConditionalItems.begin(); itr != m_playerNonQuestNonFFAConditionalItems.end(); ++itr)
delete itr->second; delete itr->second;
PlayerNonQuestNonFFAConditionalItems.clear(); m_playerNonQuestNonFFAConditionalItems.clear();
PlayersLooting.clear(); m_playersLooting.clear();
items.clear(); items.clear();
quest_items.clear(); m_questItems.clear();
gold = 0; gold = 0;
unlootedCount = 0; unlootedCount = 0;
i_LootValidatorRefManager.clearReferences(); m_LootValidatorRefManager.clearReferences();
} }
bool empty() const { return items.empty() && gold == 0; } bool empty() const { return items.empty() && gold == 0; }
@ -282,8 +283,8 @@ struct Loot
void NotifyItemRemoved(uint8 lootIndex); void NotifyItemRemoved(uint8 lootIndex);
void NotifyQuestItemRemoved(uint8 questIndex); void NotifyQuestItemRemoved(uint8 questIndex);
void NotifyMoneyRemoved(); void NotifyMoneyRemoved();
void AddLooter(uint64 GUID) { PlayersLooting.insert(GUID); } void AddLooter(ObjectGuid guid) { m_playersLooting.insert(guid); }
void RemoveLooter(uint64 GUID) { PlayersLooting.erase(GUID); } void RemoveLooter(ObjectGuid guid) { m_playersLooting.erase(guid); }
void generateMoneyLoot(uint32 minAmount, uint32 maxAmount); void generateMoneyLoot(uint32 minAmount, uint32 maxAmount);
bool FillLoot(uint32 loot_id, LootStore const& store, Player* loot_owner, bool personal, bool noEmptyError = false); bool FillLoot(uint32 loot_id, LootStore const& store, Player* loot_owner, bool personal, bool noEmptyError = false);
@ -300,14 +301,17 @@ struct Loot
QuestItemList* FillQuestLoot(Player* player); QuestItemList* FillQuestLoot(Player* player);
QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player); QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player);
LootItemList quest_items; LootItemList m_questItems;
std::set<uint64> PlayersLooting;
QuestItemMap PlayerQuestItems; typedef std::set<ObjectGuid> PlayersLooting;
QuestItemMap PlayerFFAItems; PlayersLooting m_playersLooting;
QuestItemMap PlayerNonQuestNonFFAConditionalItems;
QuestItemMap m_playerQuestItems;
QuestItemMap m_playerFFAItems;
QuestItemMap m_playerNonQuestNonFFAConditionalItems;
// All rolls are registered here. They need to know, when the loot is not valid anymore // All rolls are registered here. They need to know, when the loot is not valid anymore
LootValidatorRefManager i_LootValidatorRefManager; LootValidatorRefManager m_LootValidatorRefManager;
}; };
struct LootView struct LootView

View file

@ -8253,7 +8253,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type)
// add 'this' player as one of the players that are looting 'loot' // add 'this' player as one of the players that are looting 'loot'
if (permission != NONE_PERMISSION) if (permission != NONE_PERMISSION)
loot->AddLooter(GetGUID()); loot->AddLooter(GetObjectGuid());
if (loot_type == LOOT_CORPSE && !guid.IsItem()) if (loot_type == LOOT_CORPSE && !guid.IsItem())
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING);

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 "11453" #define REVISION_NR "11454"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__