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
24{
25}

◆ ~LootItemStorage()

LootItemStorage::~LootItemStorage ( )
private
28{
29}

Member Function Documentation

◆ AddNewStoredLoot()

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

References instance().

Referenced by instance().

◆ LoadStorageFromDB()

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

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

◆ LoadStoredLoot()

bool LootItemStorage::LoadStoredLoot ( Item item,
Player player 
)
163{
164 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item->GetEntry());
165 if (!proto)
166 {
167 return false;
168 }
169
170 Loot* loot = &item->loot;
171 LootItemContainer::iterator itr = lootItemStore.find(loot->containerGUID);
172 if (itr == lootItemStore.end())
173 return false;
174
175 StoredLootItemList& itemList = itr->second;
176 for (StoredLootItemList::iterator it2 = itemList.begin(); it2 != itemList.end(); ++it2)
177 {
178 if (it2->itemid == 0)
179 {
180 loot->gold = it2->count;
181 continue;
182 }
183
184 if (LootTemplate const* lt = LootTemplates_Item.GetLootFor(item->GetEntry()))
185 {
186 LootItem li;
187 li.itemid = it2->itemid;
188 li.itemIndex = it2->itemIndex;
189 li.count = it2->count;
190 li.follow_loot_rules = it2->follow_loot_rules;
191 li.freeforall = it2->freeforall;
192 li.is_blocked = it2->is_blocked;
193 li.is_counted = it2->is_counted;
194 li.is_underthreshold = it2->is_underthreshold;
195 li.is_looted = false;
196 li.needs_quest = it2->needs_quest;
197 li.randomPropertyId = it2->randomPropertyId;
198 li.randomSuffix = it2->randomSuffix;
200 li.groupid = 0;
201
202 // Copy the extra loot conditions from the item in the loot template
203 lt->CopyConditions(&li, it2->conditionLootId);
204
205 if (li.needs_quest)
206 {
207 loot->quest_items.push_back(li);
208 }
209 else
210 {
211 loot->items.push_back(li);
212 }
213
214 // non-conditional one-player only items are counted here,
215 // free for all items are counted in FillFFALoot(),
216 // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
217 if ((!li.needs_quest && li.conditions.empty() && !(proto->Flags & ITEM_FLAG_MULTI_DROP)) || li.is_counted)
218 {
219 ++loot->unlootedCount;
220 }
221 }
222 }
223
224 if (loot->unlootedCount)
225 {
226 loot->FillNotNormalLootFor(player);
227 }
228
229 // Mark the item if it has loot so it won't be generated again on open
230 item->m_lootGenerated = true;
231 return true;
232}
@ ITEM_FLAG_MULTI_DROP
Definition: ItemTemplate.h:159
LootStore LootTemplates_Item("item_loot_template", "item entry", true)
bool m_lootGenerated
Definition: Item.h:312
Loot loot
Definition: Item.h:311
uint32 Flags
Definition: ItemTemplate.h:636
uint32 GetEntry() const
Definition: Object.h:109
static ObjectGuid const Empty
Definition: ObjectGuid.h:122
Definition: LootMgr.h:155
uint32 itemid
Definition: LootMgr.h:156
bool is_blocked
Definition: LootMgr.h:165
uint8 groupid
Definition: LootMgr.h:171
ObjectGuid rollWinnerGUID
Definition: LootMgr.h:162
bool needs_quest
Definition: LootMgr.h:169
bool follow_loot_rules
Definition: LootMgr.h:170
bool is_underthreshold
Definition: LootMgr.h:167
int32 randomPropertyId
Definition: LootMgr.h:159
uint32 itemIndex
Definition: LootMgr.h:157
uint8 count
Definition: LootMgr.h:163
bool is_looted
Definition: LootMgr.h:164
ConditionList conditions
Definition: LootMgr.h:160
bool freeforall
Definition: LootMgr.h:166
uint32 randomSuffix
Definition: LootMgr.h:158
bool is_counted
Definition: LootMgr.h:168
LootTemplate const * GetLootFor(uint32 loot_id) const
Definition: LootMgr.cpp:246
Definition: LootMgr.h:245
Definition: LootMgr.h:313
void FillNotNormalLootFor(Player *player)
Definition: LootMgr.cpp:609
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(), ItemTemplate::Flags, LootItem::follow_loot_rules, LootItem::freeforall, Object::GetEntry(), LootStore::GetLootFor(), Loot::gold, LootItem::groupid, 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 
)
68{
69 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
70
72 stmt->SetData(0, containerGUID.GetCounter());
73 stmt->SetData(1, itemid);
74 stmt->SetData(2, count);
75 stmt->SetData(3, itemIndex);
76 trans->Append(stmt);
77
78 CharacterDatabase.CommitTransaction(trans);
79}
@ CHAR_DEL_ITEMCONTAINER_SINGLE_ITEM
Definition: CharacterDatabase.h:486

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

Referenced by RemoveStoredLootItem(), and RemoveStoredLootMoney().

◆ RemoveStoredLoot()

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

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

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

◆ RemoveStoredLootMoney()

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

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

Member Data Documentation

◆ lootItemStore