28#include <unordered_map>
32 std::unordered_map<uint32, StoredLootContainer> _lootItemStore;
36FFA(lootItem.freeforall), Blocked(lootItem.is_blocked), Counted(lootItem.is_counted), UnderThreshold(lootItem.is_underthreshold),
37NeedsQuest(lootItem.needs_quest), RandomPropertyId(lootItem.randomPropertyId), RandomSuffix(lootItem.randomSuffix)
49 static std::shared_mutex _lock;
56 _lootItemStore.clear();
66 Field* fields = result->Fetch();
69 auto itr = _lootItemStore.find(key);
70 if (itr == _lootItemStore.end())
73 std::tie(itr, added) = _lootItemStore.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(key));
96 }
while (result->NextRow());
101 TC_LOG_INFO(
"server.loading",
">> Loaded 0 stored item loots");
110 Field* fields = result->Fetch();
113 auto itr = _lootItemStore.find(key);
114 if (itr == _lootItemStore.end())
117 std::tie(itr, added) = _lootItemStore.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(key));
123 storedContainer.
AddMoney(fields[1].GetUInt32(), trans);
126 }
while (result->NextRow());
131 TC_LOG_INFO(
"server.loading",
">> Loaded 0 stored item money");
141 std::shared_lock<std::shared_mutex> lock(*
GetLock());
144 if (itr == _lootItemStore.end())
147 container = &itr->second;
155 for (
auto const& storedItemPair : container->
GetLootItems())
158 li.
itemid = storedItemPair.first;
159 li.
count = storedItemPair.second.Count;
160 li.
itemIndex = storedItemPair.second.ItemIndex;
163 li.
is_blocked = storedItemPair.second.Blocked;
164 li.
is_counted = storedItemPair.second.Counted;
171 lt->CopyConditions(&li);
178 loot->
items.push_back(li);
193 std::unique_lock<std::shared_mutex> lock(*
GetLock());
195 auto itr = _lootItemStore.find(containerId);
196 if (itr == _lootItemStore.end())
199 itr->second.RemoveMoney();
206 std::unique_lock<std::shared_mutex> lock(*
GetLock());
207 _lootItemStore.erase(containerId);
225 std::unique_lock<std::shared_mutex> lock(*
GetLock());
227 auto itr = _lootItemStore.find(containerId);
228 if (itr == _lootItemStore.end())
231 itr->second.RemoveItem(itemId, count, itemIndex);
242 std::shared_lock<std::shared_mutex> lock(*
GetLock());
245 if (itr != _lootItemStore.end())
284 std::unique_lock<std::shared_mutex> lock(*
GetLock());
285 _lootItemStore.emplace(loot->
containerID, std::move(container));
291 _lootItems.emplace(std::piecewise_construct, std::forward_as_tuple(lootItem.
itemid), std::forward_as_tuple(lootItem));
342 for (
auto itr = bounds.first; itr != bounds.second; ++itr)
344 if (itr->second.Count == count)
@ CHAR_DEL_ITEMCONTAINER_MONEY
@ CHAR_DEL_ITEMCONTAINER_ITEM
@ CHAR_DEL_ITEMCONTAINER_ITEMS
@ CHAR_SEL_ITEMCONTAINER_ITEMS
@ CHAR_INS_ITEMCONTAINER_ITEMS
@ CHAR_INS_ITEMCONTAINER_MONEY
@ CHAR_SEL_ITEMCONTAINER_MONEY
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
LootStore LootTemplates_Item("item_loot_template", "item entry", true)
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Class used to access individual fields of database query result.
void AddNewStoredLoot(Loot *loot, Player *player)
static LootItemStorage * instance()
void RemoveStoredLootItemForContainer(uint32 containerId, uint32 itemId, uint32 count, uint32 itemIndex)
static std::shared_mutex * GetLock()
void RemoveStoredLootForContainer(uint32 containerId)
void RemoveStoredMoneyForContainer(uint32 containerId)
bool LoadStoredLoot(Item *item, Player *player)
LootTemplate const * GetLootFor(uint32 loot_id) const
std::string ToString() const
static ObjectGuid GetGUID(Object const *o)
void setUInt32(uint8 index, uint32 value)
void setBool(uint8 index, bool value)
void setInt32(uint8 index, int32 value)
void RemoveItem(uint32 itemId, uint32 count, uint32 itemIndex)
void AddLootItem(LootItem const &lootItem, CharacterDatabaseTransaction trans)
StoredLootItemContainer _lootItems
uint32 const _containerId
void AddMoney(uint32 money, CharacterDatabaseTransaction trans)
StoredLootItemContainer const & GetLootItems() const
bool IsCurrencyToken() const
void AddAllowedLooter(Player const *player)
std::vector< LootItem > items
StoredLootItem(LootItem const &lootItem)