29#include <unordered_map>
33 std::unordered_map<uint64, StoredLootContainer> _lootItemStore;
37FFA(lootItem.freeforall), Blocked(lootItem.is_blocked), Counted(lootItem.is_counted), UnderThreshold(lootItem.is_underthreshold),
38NeedsQuest(lootItem.needs_quest), RandomBonusListId(lootItem.randomBonusListId), Context(lootItem.context), BonusListIDs(lootItem.BonusListIDs)
50 static std::shared_mutex _lock;
57 _lootItemStore.clear();
67 Field* fields = result->Fetch();
84 for (std::string_view bonusList :
Trinity::Tokenize(fields[12].GetStringView(),
' ',
false))
91 }
while (result->NextRow());
96 TC_LOG_INFO(
"server.loading",
">> Loaded 0 stored item loots");
105 Field* fields = result->Fetch();
109 storedContainer.
AddMoney(fields[1].GetUInt32(), trans);
112 }
while (result->NextRow());
117 TC_LOG_INFO(
"server.loading",
">> Loaded 0 stored item money");
126 std::shared_lock<std::shared_mutex> lock(*
GetLock());
129 if (itr == _lootItemStore.end())
132 container = &itr->second;
141 for (
auto const& storedItemPair : container->
GetLootItems())
144 li.
itemid = storedItemPair.first;
145 li.
count = storedItemPair.second.Count;
146 li.
LootListId = storedItemPair.second.ItemIndex;
149 li.
is_blocked = storedItemPair.second.Blocked;
150 li.
is_counted = storedItemPair.second.Counted;
154 li.
context = storedItemPair.second.Context;
158 lt->CopyConditions(&li);
165 loot->
items.push_back(li);
172 if (!loot->
items.empty())
174 std::sort(loot->
items.begin(), loot->
items.end(), [](
LootItem const& left,
LootItem const& right) { return left.LootListId < right.LootListId; });
178 while (loot->
items.size() <= loot->
items.back().LootListId)
180 if (loot->
items[lootListId].LootListId != lootListId)
182 auto li = loot->
items.emplace(loot->
items.begin() + lootListId);
183 li->LootListId = lootListId;
184 li->is_looted =
true;
200 std::unique_lock<std::shared_mutex> lock(*
GetLock());
202 auto itr = _lootItemStore.find(containerId);
203 if (itr == _lootItemStore.end())
206 itr->second.RemoveMoney();
213 std::unique_lock<std::shared_mutex> lock(*
GetLock());
214 _lootItemStore.erase(containerId);
232 std::unique_lock<std::shared_mutex> lock(*
GetLock());
234 auto itr = _lootItemStore.find(containerId);
235 if (itr == _lootItemStore.end())
238 itr->second.RemoveItem(itemId, count, itemIndex);
249 std::shared_lock<std::shared_mutex> lock(*
GetLock());
251 auto itr = _lootItemStore.find(containerId);
252 if (itr != _lootItemStore.end())
254 TC_LOG_ERROR(
"misc",
"Trying to store item loot by player: {} for container id: {} that is already in storage!", player->
GetGUID().
ToString(), containerId);
291 std::unique_lock<std::shared_mutex> lock(*
GetLock());
292 _lootItemStore.emplace(containerId, std::move(container));
298 _lootItems.emplace(std::piecewise_construct, std::forward_as_tuple(lootItem.
itemid), std::forward_as_tuple(lootItem));
317 std::ostringstream bonusListIDs;
319 bonusListIDs << bonusListID <<
' ';
352 for (
auto itr = bounds.first; itr != bounds.second; ++itr)
354 if (itr->second.ItemIndex == itemIndex)
@ 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)
std::optional< T > Optional
Optional helper class to wrap optional values within.
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Class used to access individual fields of database query result.
std::unique_ptr< Loot > m_loot
void RemoveStoredLootItemForContainer(uint64 containerId, uint32 itemId, uint32 count, uint32 itemIndex)
static LootItemStorage * instance()
void RemoveStoredMoneyForContainer(uint64 containerId)
void AddNewStoredLoot(uint64 containerId, Loot *loot, Player *player)
static std::shared_mutex * GetLock()
bool LoadStoredLoot(Item *item, Player *player)
void RemoveStoredLootForContainer(uint64 containerId)
LootTemplate const * GetLootFor(uint32 loot_id) const
LowType GetCounter() const
std::string ToString() const
static ObjectGuid GetGUID(Object const *o)
void setInt32(const uint8 index, const int32 value)
void setUInt8(const uint8 index, const uint8 value)
void setBool(const uint8 index, const bool value)
void setUInt32(const uint8 index, const uint32 value)
void setString(const uint8 index, const std::string &value)
void setUInt64(const uint8 index, const uint64 value)
void RemoveItem(uint32 itemId, uint32 count, uint32 itemIndex)
void AddLootItem(LootItem const &lootItem, CharacterDatabaseTransaction trans)
StoredLootItemContainer _lootItems
uint64 const _containerId
void AddMoney(uint32 money, CharacterDatabaseTransaction trans)
StoredLootItemContainer const & GetLootItems() const
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
size_t Count(ContainerMapList< TypeList< H, T > > const &elements, SPECIFIC_TYPE *fake)
bool IsCurrencyToken() const
std::vector< int32 > BonusListIDs
void AddAllowedLooter(Player const *player)
bool AllowedForPlayer(Player const *player, Loot const *loot) const
ItemRandomBonusListId randomBonusListId
std::vector< LootItem > items
StoredLootItem(LootItem const &lootItem)