AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
LootItemStorage Class Reference

#include "LootItemStorage.h"

Public Member Functions

void LoadStorageFromDB ()
 
void RemoveEntryFromDB (ObjectGuid containerGUID, uint32 itemid, uint32 count, uint32 itemIndex)
 
void AddNewStoredLoot (Loot *loot, Player *player)
 
bool LoadStoredLoot (Item *item, Player *player)
 
void RemoveStoredLootItem (ObjectGuid containerGUID, uint32 itemid, uint32 count, Loot *loot, uint32 itemIndex)
 
void RemoveStoredLootMoney (ObjectGuid containerGUID, Loot *loot)
 
void RemoveStoredLoot (ObjectGuid containerGUID)
 

Static Public Member Functions

static LootItemStorageinstance ()
 

Private Member Functions

 LootItemStorage ()
 
 ~LootItemStorage ()
 

Private Attributes

LootItemContainer lootItemStore
 

Detailed Description

Constructor & Destructor Documentation

◆ LootItemStorage()

LootItemStorage::LootItemStorage ( )
private
26{
27}

◆ ~LootItemStorage()

LootItemStorage::~LootItemStorage ( )
private
30{
31}

Member Function Documentation

◆ AddNewStoredLoot()

void LootItemStorage::AddNewStoredLoot ( Loot loot,
Player player 
)
84{
85 if (lootItemStore.find(loot->containerGUID) != lootItemStore.end())
86 {
87 LOG_INFO("misc", "LootItemStorage::AddNewStoredLoot (A1) - {}!", loot->containerGUID.ToString());
88 return;
89 }
90
91 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
93
95
96 // Gold at first
97 if (loot->gold)
98 {
99 itemList.emplace_back(0, 0, loot->gold, 0, 0, false, false, false, false, false, false, 0);
100
101 uint8 index = 0;
102 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
103 stmt->SetData(index++, loot->containerGUID.GetCounter());
104 stmt->SetData(index++, 0);
105 stmt->SetData(index++, 0);
106 stmt->SetData(index++, loot->gold);
107 stmt->SetData(index++, 0);
108 stmt->SetData(index++, 0);
109 stmt->SetData(index++, false);
110 stmt->SetData(index++, false);
111 stmt->SetData(index++, false);
112 stmt->SetData(index++, false);
113 stmt->SetData(index++, false);
114 stmt->SetData(index++, false);
115 stmt->SetData(index++, 0);
116 trans->Append(stmt);
117 }
118
119 // And normal items
120 if (!loot->isLooted())
121 for (LootItemList::const_iterator li = loot->items.begin(); li != loot->items.end(); li++)
122 {
123 // Even if an item is not available for a specific player, it doesn't mean that
124 // we are not able to trade this container to another player that is able to loot that item
125 // if we don't save it then the item will be lost at player re-login.
126 //if (!li->AllowedForPlayer(player))
127 // continue;
128
129 ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(li->itemid);
130 if (!itemTemplate || itemTemplate->IsCurrencyToken())
131 continue;
132
133 uint32 conditionLootId = 0;
134 if (!li->conditions.empty())
135 {
136 conditionLootId = li->conditions.front()->SourceGroup;
137 }
138
139 itemList.emplace_back(li->itemid, li->itemIndex, li->count, li->randomPropertyId, li->randomSuffix, li->follow_loot_rules, li->freeforall, li->is_blocked, li->is_counted,
140 li->is_underthreshold, li->needs_quest, conditionLootId);
141
142 uint8 index = 0;
143 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_SINGLE_ITEM);
144 stmt->SetData(index++, loot->containerGUID.GetCounter());
145 stmt->SetData(index++, li->itemid);
146 stmt->SetData(index++, li->itemIndex);
147 stmt->SetData(index++, li->count);
148 stmt->SetData (index++, li->randomPropertyId);
149 stmt->SetData(index++, li->randomSuffix);
150 stmt->SetData(index++, li->follow_loot_rules);
151 stmt->SetData(index++, li->freeforall);
152 stmt->SetData(index++, li->is_blocked);
153 stmt->SetData(index++, li->is_counted);
154 stmt->SetData(index++, li->is_underthreshold);
155 stmt->SetData(index++, li->needs_quest);
156 stmt->SetData(index++, conditionLootId);
157
158 trans->Append(stmt);
159 }
160
161 CharacterDatabase.CommitTransaction(trans);
162}
@ CHAR_INS_ITEMCONTAINER_SINGLE_ITEM
Definition CharacterDatabase.h:492
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition DatabaseEnvFwd.h:69
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
#define LOG_INFO(filterType__,...)
Definition Log.h:165
std::list< StoredLootItem > StoredLootItemList
Definition LootItemStorage.h:47
#define sObjectMgr
Definition ObjectMgr.h:1636
LootItemContainer lootItemStore
Definition LootItemStorage.h:70
LowType GetCounter() const
Definition ObjectGuid.h:145
std::string ToString() const
Definition ObjectGuid.cpp:47
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
Definition ItemTemplate.h:619
bool IsCurrencyToken() const
Definition ItemTemplate.h:727
ObjectGuid containerGUID
Definition LootMgr.h:329
bool isLooted() const
Definition LootMgr.h:368
uint32 gold
Definition LootMgr.h:322
std::vector< LootItem > items
Definition LootMgr.h:320

References CHAR_INS_ITEMCONTAINER_SINGLE_ITEM, CharacterDatabase, Loot::containerGUID, ObjectGuid::GetCounter(), Loot::gold, ItemTemplate::IsCurrencyToken(), Loot::isLooted(), Loot::items, LOG_INFO, lootItemStore, PreparedStatementBase::SetData(), sObjectMgr, and ObjectGuid::ToString().

◆ instance()

LootItemStorage * LootItemStorage::instance ( )
static
34{
36 return &instance;
37}
Definition LootItemStorage.h:51
static LootItemStorage * instance()
Definition LootItemStorage.cpp:33

References instance().

Referenced by instance().

◆ LoadStorageFromDB()

void LootItemStorage::LoadStorageFromDB ( )
40{
41 uint32 oldMSTime = getMSTime();
42 lootItemStore.clear();
43
45 PreparedQueryResult result = CharacterDatabase.Query(stmt);
46 if (!result)
47 {
48 LOG_WARN("server.loading", ">> Loaded 0 stored items!");
49 LOG_INFO("server.loading", " ");
50 return;
51 }
52
53 uint32 count = 0;
54 do
55 {
56 Field* fields = result->Fetch();
57
58 StoredLootItemList& itemList = lootItemStore[ObjectGuid::Create<HighGuid::Item>(fields[0].Get<uint32>())];
59 itemList.emplace_back(fields[1].Get<uint32>(), fields[2].Get<uint32>(), fields[3].Get<uint32>(), fields[4].Get<int32>(), fields[5].Get<uint32>(), fields[6].Get<bool>(),
60 fields[7].Get<bool>(), fields[8].Get<bool>(), fields[9].Get<bool>(), fields[10].Get<bool>(), fields[11].Get<bool>(), fields[12].Get<uint32>());
61
62 ++count;
63 } while (result->NextRow());
64
65 LOG_INFO("server.loading", ">> Loaded {} stored items in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
66 LOG_INFO("server.loading", " ");
67}
@ CHAR_SEL_ITEMCONTAINER_ITEMS
Definition CharacterDatabase.h:490
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
#define LOG_WARN(filterType__,...)
Definition Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
Class used to access individual fields of database query result.
Definition Field.h:98

References CHAR_SEL_ITEMCONTAINER_ITEMS, CharacterDatabase, getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, LOG_WARN, and lootItemStore.

◆ LoadStoredLoot()

bool LootItemStorage::LoadStoredLoot ( Item item,
Player player 
)
165{
166 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->GetEntry());
167 if (!proto)
168 {
169 return false;
170 }
171
172 Loot* loot = &item->loot;
173 LootItemContainer::iterator itr = lootItemStore.find(loot->containerGUID);
174 if (itr == lootItemStore.end())
175 return false;
176
177 StoredLootItemList& itemList = itr->second;
178 for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
179 {
180 if (it2->itemid == 0)
181 {
182 loot->gold = it2->count;
183 continue;
184 }
185
186 if (LootTemplate const* lt = LootTemplates_Item.GetLootFor(item->GetEntry()))
187 {
188 LootItem li;
189 li.itemid = it2->itemid;
190 li.itemIndex = it2->itemIndex;
191 li.count = it2->count;
192 li.follow_loot_rules = it2->follow_loot_rules;
193 li.freeforall = it2->freeforall;
194 li.is_blocked = it2->is_blocked;
195 li.is_counted = it2->is_counted;
196 li.is_underthreshold = it2->is_underthreshold;
197 li.is_looted = false;
198 li.needs_quest = it2->needs_quest;
199 li.randomPropertyId = it2->randomPropertyId;
200 li.randomSuffix = it2->randomSuffix;
202 li.groupid = 0;
203
204 // Copy the extra loot conditions from the item in the loot template
205 lt->CopyConditions(&li, it2->conditionLootId);
206
207 if (li.needs_quest)
208 {
209 loot->quest_items.push_back(li);
210 }
211 else
212 {
213 loot->items.push_back(li);
214 }
215
216 // non-conditional one-player only items are counted here,
217 // free for all items are counted in FillFFALoot(),
218 // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
219 if ((!li.needs_quest && li.conditions.empty() && !proto->HasFlag(ITEM_FLAG_MULTI_DROP)) || li.is_counted)
220 {
221 ++loot->unlootedCount;
222 }
223 }
224 }
225
226 if (loot->unlootedCount)
227 {
228 loot->FillNotNormalLootFor(player);
229 }
230
231 // Mark the item if it has loot so it won't be generated again on open
232 item->m_lootGenerated = true;
233 return true;
234}
@ ITEM_FLAG_MULTI_DROP
Definition ItemTemplate.h:158
LootStore LootTemplates_Item("item_loot_template", "item entry", true)
bool m_lootGenerated
Definition Item.h:321
Loot loot
Definition Item.h:320
LootTemplate const * GetLootFor(uint32 loot_id) const
Definition LootMgr.cpp:247
Definition LootMgr.h:245
static ObjectGuid const Empty
Definition ObjectGuid.h:120
uint32 GetEntry() const
Definition Object.h:115
bool HasFlag(ItemFlags flag) const
Definition ItemTemplate.h:827
Definition LootMgr.h:154
uint32 itemid
Definition LootMgr.h:155
bool is_blocked
Definition LootMgr.h:164
uint8 groupid
Definition LootMgr.h:170
ObjectGuid rollWinnerGUID
Definition LootMgr.h:161
bool needs_quest
Definition LootMgr.h:168
bool follow_loot_rules
Definition LootMgr.h:169
bool is_underthreshold
Definition LootMgr.h:166
int32 randomPropertyId
Definition LootMgr.h:158
uint32 itemIndex
Definition LootMgr.h:156
uint8 count
Definition LootMgr.h:162
bool is_looted
Definition LootMgr.h:163
ConditionList conditions
Definition LootMgr.h:159
bool freeforall
Definition LootMgr.h:165
uint32 randomSuffix
Definition LootMgr.h:157
bool is_counted
Definition LootMgr.h:167
Definition LootMgr.h:313
void FillNotNormalLootFor(Player *player)
Definition LootMgr.cpp:626
uint8 unlootedCount
Definition LootMgr.h:323
std::vector< LootItem > quest_items
Definition LootMgr.h:321

References LootItem::conditions, Loot::containerGUID, LootItem::count, ObjectGuid::Empty, Loot::FillNotNormalLootFor(), LootItem::follow_loot_rules, LootItem::freeforall, Object::GetEntry(), LootStore::GetLootFor(), Loot::gold, LootItem::groupid, ItemTemplate::HasFlag(), LootItem::is_blocked, LootItem::is_counted, LootItem::is_looted, LootItem::is_underthreshold, ITEM_FLAG_MULTI_DROP, LootItem::itemid, LootItem::itemIndex, Loot::items, Item::loot, lootItemStore, LootTemplates_Item, Item::m_lootGenerated, LootItem::needs_quest, Loot::quest_items, LootItem::randomPropertyId, LootItem::randomSuffix, LootItem::rollWinnerGUID, sObjectMgr, and Loot::unlootedCount.

◆ RemoveEntryFromDB()

void LootItemStorage::RemoveEntryFromDB ( ObjectGuid  containerGUID,
uint32  itemid,
uint32  count,
uint32  itemIndex 
)
70{
71 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
72
74 stmt->SetData(0, containerGUID.GetCounter());
75 stmt->SetData(1, itemid);
76 stmt->SetData(2, count);
77 stmt->SetData(3, itemIndex);
78 trans->Append(stmt);
79
80 CharacterDatabase.CommitTransaction(trans);
81}
@ CHAR_DEL_ITEMCONTAINER_SINGLE_ITEM
Definition CharacterDatabase.h:491

References CHAR_DEL_ITEMCONTAINER_SINGLE_ITEM, CharacterDatabase, ObjectGuid::GetCounter(), and PreparedStatementBase::SetData().

Referenced by RemoveStoredLootItem(), and RemoveStoredLootMoney().

◆ RemoveStoredLoot()

void LootItemStorage::RemoveStoredLoot ( ObjectGuid  containerGUID)
279{
280 lootItemStore.erase(containerGUID);
281
282 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
283
285 stmt->SetData(0, containerGUID.GetCounter());
286 trans->Append(stmt);
287
288 CharacterDatabase.CommitTransaction(trans);
289}
@ CHAR_DEL_ITEMCONTAINER_CONTAINER
Definition CharacterDatabase.h:493

References CHAR_DEL_ITEMCONTAINER_CONTAINER, CharacterDatabase, ObjectGuid::GetCounter(), lootItemStore, and PreparedStatementBase::SetData().

◆ RemoveStoredLootItem()

void LootItemStorage::RemoveStoredLootItem ( ObjectGuid  containerGUID,
uint32  itemid,
uint32  count,
Loot loot,
uint32  itemIndex 
)
237{
238 LootItemContainer::iterator itr = lootItemStore.find(containerGUID);
239 if (itr == lootItemStore.end())
240 return;
241
242 StoredLootItemList& itemList = itr->second;
243 for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
244 if (it2->itemid == itemid && it2->count == count)
245 {
246 RemoveEntryFromDB(containerGUID, itemid, count, itemIndex);
247 itemList.erase(it2);
248 break;
249 }
250
251 // loot with empty itemList but unlootedCount > 0
252 // must be deleted manually by the player or traded
253 if (!loot->unlootedCount && !loot->gold)
254 lootItemStore.erase(itr);
255}
void RemoveEntryFromDB(ObjectGuid containerGUID, uint32 itemid, uint32 count, uint32 itemIndex)
Definition LootItemStorage.cpp:69

References Loot::gold, lootItemStore, RemoveEntryFromDB(), and Loot::unlootedCount.

◆ RemoveStoredLootMoney()

void LootItemStorage::RemoveStoredLootMoney ( ObjectGuid  containerGUID,
Loot loot 
)
258{
259 LootItemContainer::iterator itr = lootItemStore.find(containerGUID);
260 if (itr == lootItemStore.end())
261 return;
262
263 StoredLootItemList& itemList = itr->second;
264 for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
265 if (it2->itemid == 0)
266 {
267 RemoveEntryFromDB(containerGUID, 0, it2->count, 0);
268 itemList.erase(it2);
269 break;
270 }
271
272 // loot with empty itemList but unlootedCount > 0
273 // must be deleted manually by the player or traded
274 if (!loot->unlootedCount)
275 lootItemStore.erase(itr);
276}

References lootItemStore, RemoveEntryFromDB(), and Loot::unlootedCount.

Member Data Documentation

◆ lootItemStore


The documentation for this class was generated from the following files: