feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -40,7 +40,7 @@ void LootItemStorage::LoadStorageFromDB()
{
Field* fields = result->Fetch();
StoredLootItemList& itemList = lootItemStore[fields[0].GetUInt32()];
StoredLootItemList& itemList = lootItemStore[ObjectGuid::Create<HighGuid::Item>(fields[0].GetUInt32())];
itemList.push_back(StoredLootItem(fields[1].GetUInt32(), fields[2].GetUInt32(), fields[3].GetInt32(), fields[4].GetUInt32()));
++count;
@@ -50,11 +50,12 @@ void LootItemStorage::LoadStorageFromDB()
LOG_INFO("server", " ");
}
void LootItemStorage::RemoveEntryFromDB(uint32 containerId, uint32 itemid, uint32 count)
void LootItemStorage::RemoveEntryFromDB(ObjectGuid containerGUID, uint32 itemid, uint32 count)
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEMCONTAINER_SINGLE_ITEM);
stmt->setUInt32(0, containerId);
stmt->setUInt32(0, containerGUID.GetCounter());
stmt->setUInt32(1, itemid);
stmt->setUInt32(2, count);
trans->Append(stmt);
@@ -64,16 +65,16 @@ void LootItemStorage::RemoveEntryFromDB(uint32 containerId, uint32 itemid, uint3
void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
{
if (lootItemStore.find(loot->containerId) != lootItemStore.end())
if (lootItemStore.find(loot->containerGUID) != lootItemStore.end())
{
LOG_INFO("misc", "LootItemStorage::AddNewStoredLoot (A1) - %u!", loot->containerId);
LOG_INFO("misc", "LootItemStorage::AddNewStoredLoot (A1) - %s!", loot->containerGUID.ToString().c_str());
return;
}
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = nullptr;
StoredLootItemList& itemList = lootItemStore[loot->containerId];
StoredLootItemList& itemList = lootItemStore[loot->containerGUID];
// Gold at first
if (loot->gold)
@@ -81,7 +82,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
itemList.push_back(StoredLootItem(0, loot->gold, 0, 0));
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
stmt->setUInt32(0, loot->containerId);
stmt->setUInt32(0, loot->containerGUID.GetCounter());
stmt->setUInt32(1, 0);
stmt->setUInt32(2, loot->gold);
stmt->setInt32(3, 0);
@@ -106,7 +107,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
itemList.push_back(StoredLootItem(li->itemid, li->count, li->randomPropertyId, li->randomSuffix));
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
stmt->setUInt32(0, loot->containerId);
stmt->setUInt32(0, loot->containerGUID.GetCounter());
stmt->setUInt32(1, li->itemid);
stmt->setUInt32(2, li->count);
stmt->setInt32 (3, li->randomPropertyId);
@@ -120,7 +121,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* /*player*/)
bool LootItemStorage::LoadStoredLoot(Item* item)
{
Loot* loot = &item->loot;
LootItemContainer::iterator itr = lootItemStore.find(loot->containerId);
LootItemContainer::iterator itr = lootItemStore.find(loot->containerGUID);
if (itr == lootItemStore.end())
return false;
@@ -145,7 +146,7 @@ bool LootItemStorage::LoadStoredLoot(Item* item)
li.needs_quest = false;
li.randomPropertyId = it2->randomPropertyId;
li.randomSuffix = it2->randomSuffix;
li.rollWinnerGUID = 0;
li.rollWinnerGUID = ObjectGuid::Empty;
loot->items.push_back(li);
loot->unlootedCount++;
@@ -156,9 +157,9 @@ bool LootItemStorage::LoadStoredLoot(Item* item)
return true;
}
void LootItemStorage::RemoveStoredLootItem(uint32 containerId, uint32 itemid, uint32 count, Loot* loot)
void LootItemStorage::RemoveStoredLootItem(ObjectGuid containerGUID, uint32 itemid, uint32 count, Loot* loot)
{
LootItemContainer::iterator itr = lootItemStore.find(containerId);
LootItemContainer::iterator itr = lootItemStore.find(containerGUID);
if (itr == lootItemStore.end())
return;
@@ -166,7 +167,7 @@ void LootItemStorage::RemoveStoredLootItem(uint32 containerId, uint32 itemid, ui
for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
if (it2->itemid == itemid && it2->count == count)
{
RemoveEntryFromDB(containerId, itemid, count);
RemoveEntryFromDB(containerGUID, itemid, count);
itemList.erase(it2);
break;
}
@@ -177,9 +178,9 @@ void LootItemStorage::RemoveStoredLootItem(uint32 containerId, uint32 itemid, ui
lootItemStore.erase(itr);
}
void LootItemStorage::RemoveStoredLootMoney(uint32 containerId, Loot* loot)
void LootItemStorage::RemoveStoredLootMoney(ObjectGuid containerGUID, Loot* loot)
{
LootItemContainer::iterator itr = lootItemStore.find(containerId);
LootItemContainer::iterator itr = lootItemStore.find(containerGUID);
if (itr == lootItemStore.end())
return;
@@ -187,7 +188,7 @@ void LootItemStorage::RemoveStoredLootMoney(uint32 containerId, Loot* loot)
for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
if (it2->itemid == 0)
{
RemoveEntryFromDB(containerId, 0, it2->count);
RemoveEntryFromDB(containerGUID, 0, it2->count);
itemList.erase(it2);
break;
}
@@ -198,13 +199,14 @@ void LootItemStorage::RemoveStoredLootMoney(uint32 containerId, Loot* loot)
lootItemStore.erase(itr);
}
void LootItemStorage::RemoveStoredLoot(uint32 containerId)
void LootItemStorage::RemoveStoredLoot(ObjectGuid containerGUID)
{
lootItemStore.erase(containerId);
lootItemStore.erase(containerGUID);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEMCONTAINER_CONTAINER);
stmt->setUInt32(0, containerId);
stmt->setUInt32(0, containerGUID.GetCounter());
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);

View File

@@ -24,7 +24,7 @@ struct StoredLootItem
};
typedef std::list<StoredLootItem> StoredLootItemList;
typedef std::unordered_map<uint32, StoredLootItemList> LootItemContainer;
typedef std::unordered_map<ObjectGuid, StoredLootItemList> LootItemContainer;
class LootItemStorage
{
@@ -36,14 +36,14 @@ public:
static LootItemStorage* instance();
void LoadStorageFromDB();
void RemoveEntryFromDB(uint32 containerId, uint32 itemid, uint32 count);
void RemoveEntryFromDB(ObjectGuid containerGUID, uint32 itemid, uint32 count);
void AddNewStoredLoot(Loot* loot, Player* player);
bool LoadStoredLoot(Item* item);
void RemoveStoredLootItem(uint32 containerId, uint32 itemid, uint32 count, Loot* loot);
void RemoveStoredLootMoney(uint32 containerId, Loot* loot);
void RemoveStoredLoot(uint32 containerId);
void RemoveStoredLootItem(ObjectGuid containerGUID, uint32 itemid, uint32 count, Loot* loot);
void RemoveStoredLootMoney(ObjectGuid containerGUID, Loot* loot);
void RemoveStoredLoot(ObjectGuid containerGUID);
private:
LootItemContainer lootItemStore;

View File

@@ -383,7 +383,7 @@ LootItem::LootItem(LootStoreItem const& li)
is_blocked = 0;
is_underthreshold = 0;
is_counted = 0;
rollWinnerGUID = 0;
rollWinnerGUID = ObjectGuid::Empty;
}
// Basic checks for player/item compatibility - if false no chance to see the item in the loot
@@ -444,9 +444,9 @@ bool LootItem::AllowedForPlayer(Player const* player, bool isGivenByMasterLooter
return true;
}
void LootItem::AddAllowedLooter(const Player* player)
void LootItem::AddAllowedLooter(Player const* player)
{
allowedGUIDs.insert(player->GetGUIDLow());
allowedGUIDs.insert(player->GetGUID());
}
//
@@ -532,17 +532,17 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo
void Loot::FillNotNormalLootFor(Player* player, bool presentAtLooting)
{
uint32 plguid = player->GetGUIDLow();
ObjectGuid playerGuid = player->GetGUID();
QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(plguid);
QuestItemMap::const_iterator qmapitr = PlayerQuestItems.find(playerGuid);
if (qmapitr == PlayerQuestItems.end())
FillQuestLoot(player);
qmapitr = PlayerFFAItems.find(plguid);
qmapitr = PlayerFFAItems.find(playerGuid);
if (qmapitr == PlayerFFAItems.end())
FillFFALoot(player);
qmapitr = PlayerNonQuestNonFFAConditionalItems.find(plguid);
qmapitr = PlayerNonQuestNonFFAConditionalItems.find(playerGuid);
if (qmapitr == PlayerNonQuestNonFFAConditionalItems.end())
FillNonQuestNonFFAConditionalLoot(player, presentAtLooting);
@@ -587,7 +587,7 @@ QuestItemList* Loot::FillFFALoot(Player* player)
return nullptr;
}
PlayerFFAItems[player->GetGUIDLow()] = ql;
PlayerFFAItems[player->GetGUID()] = ql;
return ql;
}
@@ -625,7 +625,7 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
return nullptr;
}
PlayerQuestItems[player->GetGUIDLow()] = ql;
PlayerQuestItems[player->GetGUID()] = ql;
return ql;
}
@@ -657,7 +657,7 @@ QuestItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player, bool pres
return nullptr;
}
PlayerNonQuestNonFFAConditionalItems[player->GetGUIDLow()] = ql;
PlayerNonQuestNonFFAConditionalItems[player->GetGUID()] = ql;
return ql;
}
@@ -708,7 +708,7 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex)
++i_next;
if (Player* player = ObjectAccessor::FindPlayer(*i))
{
QuestItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUID());
if (pq != PlayerQuestItems.end() && pq->second)
{
// find where/if the player has the given item in it's vector
@@ -748,7 +748,7 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem * *qit
if (lootSlot >= items.size())
{
uint32 questSlot = lootSlot - items.size();
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID());
if (itr != PlayerQuestItems.end() && questSlot < itr->second->size())
{
QuestItem* qitem2 = &itr->second->at(questSlot);
@@ -766,7 +766,7 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem * *qit
is_looted = item->is_looted;
if (item->freeforall)
{
QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator itr = PlayerFFAItems.find(player->GetGUID());
if (itr != PlayerFFAItems.end())
{
for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
@@ -782,7 +782,7 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem * *qit
}
else if (!item->conditions.empty())
{
QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator itr = PlayerNonQuestNonFFAConditionalItems.find(player->GetGUID());
if (itr != PlayerNonQuestNonFFAConditionalItems.end())
{
for (QuestItemList::const_iterator iter = itr->second->begin(); iter != itr->second->end(); ++iter)
@@ -808,7 +808,7 @@ LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem * *qit
uint32 Loot::GetMaxSlotInLootFor(Player* player) const
{
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator itr = PlayerQuestItems.find(player->GetGUID());
return items.size() + (itr != PlayerQuestItems.end() ? itr->second->size() : 0);
}
@@ -830,7 +830,7 @@ bool Loot::hasItemForAll() const
bool Loot::hasItemFor(Player* player) const
{
QuestItemMap const& lootPlayerQuestItems = GetPlayerQuestItems();
QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(player->GetGUID());
if (q_itr != lootPlayerQuestItems.end())
{
QuestItemList* q_list = q_itr->second;
@@ -843,7 +843,7 @@ bool Loot::hasItemFor(Player* player) const
}
QuestItemMap const& lootPlayerFFAItems = GetPlayerFFAItems();
QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(player->GetGUID());
if (ffa_itr != lootPlayerFFAItems.end())
{
QuestItemList* ffa_list = ffa_itr->second;
@@ -856,7 +856,7 @@ bool Loot::hasItemFor(Player* player) const
}
QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUIDLow());
QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(player->GetGUID());
if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
{
QuestItemList* conditional_list = nn_itr->second;
@@ -960,7 +960,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
else
continue;
}
else if (l.roundRobinPlayer == 0 || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
else if (!l.roundRobinPlayer || lv.viewer->GetGUID() == l.roundRobinPlayer || !l.items[i].is_underthreshold)
{
// no round robin owner or he has released the loot
// or it IS the round robin group owner
@@ -984,7 +984,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
{
if (!l.items[i].is_looted && !l.items[i].freeforall && l.items[i].conditions.empty() && l.items[i].AllowedForPlayer(lv.viewer))
{
if (l.roundRobinPlayer != 0 && lv.viewer->GetGUID() != l.roundRobinPlayer)
if (l.roundRobinPlayer && lv.viewer->GetGUID() != l.roundRobinPlayer)
// item shall not be displayed.
continue;
@@ -1020,7 +1020,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
LootSlotType partySlotType = lv.permission == MASTER_PERMISSION ? LOOT_SLOT_TYPE_MASTER : slotType;
QuestItemMap const& lootPlayerQuestItems = l.GetPlayerQuestItems();
QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(lv.viewer->GetGUIDLow());
QuestItemMap::const_iterator q_itr = lootPlayerQuestItems.find(lv.viewer->GetGUID());
if (q_itr != lootPlayerQuestItems.end())
{
QuestItemList* q_list = q_itr->second;
@@ -1063,7 +1063,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
}
QuestItemMap const& lootPlayerFFAItems = l.GetPlayerFFAItems();
QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(lv.viewer->GetGUIDLow());
QuestItemMap::const_iterator ffa_itr = lootPlayerFFAItems.find(lv.viewer->GetGUID());
if (ffa_itr != lootPlayerFFAItems.end())
{
QuestItemList* ffa_list = ffa_itr->second;
@@ -1082,7 +1082,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv)
}
QuestItemMap const& lootPlayerNonQuestNonFFAConditionalItems = l.GetPlayerNonQuestNonFFAConditionalItems();
QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(lv.viewer->GetGUIDLow());
QuestItemMap::const_iterator nn_itr = lootPlayerNonQuestNonFFAConditionalItems.find(lv.viewer->GetGUID());
if (nn_itr != lootPlayerNonQuestNonFFAConditionalItems.end())
{
QuestItemList* conditional_list = nn_itr->second;

View File

@@ -10,12 +10,14 @@
#include "ByteBuffer.h"
#include "ConditionMgr.h"
#include "ItemEnchantmentMgr.h"
#include "ObjectGuid.h"
#include "RefManager.h"
#include "SharedDefines.h"
#include <list>
#include <map>
#include <vector>
enum RollType
{
ROLL_PASS = 0,
@@ -135,7 +137,7 @@ struct LootStoreItem
// Checks correctness of values
};
typedef std::set<uint32> AllowedLooterSet;
typedef GuidSet AllowedLooterSet;
struct LootItem
{
@@ -144,7 +146,7 @@ struct LootItem
int32 randomPropertyId;
ConditionList conditions; // additional loot condition
AllowedLooterSet allowedGUIDs;
uint64 rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
uint8 count : 8;
bool is_looted : 1;
bool is_blocked : 1;
@@ -183,7 +185,7 @@ class LootTemplate;
typedef std::vector<QuestItem> QuestItemList;
typedef std::vector<LootItem> LootItemList;
typedef std::map<uint32, QuestItemList*> QuestItemMap;
typedef std::map<ObjectGuid, QuestItemList*> QuestItemMap;
typedef std::list<LootStoreItem*> LootStoreItemList;
typedef std::unordered_map<uint32, LootTemplate*> LootTemplateMap;
@@ -306,11 +308,11 @@ struct Loot
std::vector<LootItem> quest_items;
uint32 gold;
uint8 unlootedCount{0};
uint64 roundRobinPlayer{0}; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released.
LootType loot_type{LOOT_NONE}; // required for achievement system
ObjectGuid roundRobinPlayer; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released.
LootType loot_type{LOOT_NONE}; // required for achievement system
// GUIDLow of container that holds this loot (item_instance.entry), set for items that can be looted
uint32 containerId{0};
// GUID of container that holds this loot (item_instance.entry), set for items that can be looted
ObjectGuid containerGUID;
Loot(uint32 _gold = 0) : gold(_gold) { }
~Loot() { clear(); }
@@ -341,7 +343,7 @@ struct Loot
quest_items.clear();
gold = 0;
unlootedCount = 0;
roundRobinPlayer = 0;
roundRobinPlayer.Clear();
i_LootValidatorRefManager.clearReferences();
loot_type = LOOT_NONE;
}
@@ -352,8 +354,8 @@ struct Loot
void NotifyItemRemoved(uint8 lootIndex);
void NotifyQuestItemRemoved(uint8 questIndex);
void NotifyMoneyRemoved();
void AddLooter(uint64 GUID) { PlayersLooting.insert(GUID); }
void RemoveLooter(uint64 GUID) { PlayersLooting.erase(GUID); }
void AddLooter(ObjectGuid GUID) { PlayersLooting.insert(GUID); }
void RemoveLooter(ObjectGuid GUID) { PlayersLooting.erase(GUID); }
void generateMoneyLoot(uint32 minAmount, uint32 maxAmount);
bool FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError = false, uint16 lootMode = LOOT_MODE_DEFAULT);
@@ -373,7 +375,7 @@ private:
QuestItemList* FillQuestLoot(Player* player);
QuestItemList* FillNonQuestNonFFAConditionalLoot(Player* player, bool presentAtLooting);
typedef std::set<uint64> PlayersLootingSet;
typedef GuidSet PlayersLootingSet;
PlayersLootingSet PlayersLooting;
QuestItemMap PlayerQuestItems;
QuestItemMap PlayerFFAItems;