aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/database/Database/Implementation/CharacterDatabase.cpp6
-rw-r--r--src/server/game/Entities/Player/Player.cpp2
-rw-r--r--src/server/game/Loot/Loot.cpp1
-rw-r--r--src/server/game/Loot/Loot.h3
-rw-r--r--src/server/game/Loot/LootItemStorage.cpp44
-rw-r--r--src/server/game/Loot/LootItemStorage.h4
6 files changed, 33 insertions, 27 deletions
diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp
index 2109f964f1a..00210cc626c 100644
--- a/src/server/database/Database/Implementation/CharacterDatabase.cpp
+++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp
@@ -540,10 +540,10 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_DEL_CHAR_FISHINGSTEPS, "DELETE FROM character_fishingsteps WHERE guid = ?", CONNECTION_ASYNC);
// Items that hold loot or money
- PrepareStatement(CHAR_SEL_ITEMCONTAINER_ITEMS, "SELECT container_id, item_id, item_count, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix FROM item_loot_items", CONNECTION_SYNCH);
+ PrepareStatement(CHAR_SEL_ITEMCONTAINER_ITEMS, "SELECT container_id, item_id, item_count, item_index, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix FROM item_loot_items", CONNECTION_SYNCH);
PrepareStatement(CHAR_DEL_ITEMCONTAINER_ITEMS, "DELETE FROM item_loot_items WHERE container_id = ?", CONNECTION_ASYNC);
- PrepareStatement(CHAR_DEL_ITEMCONTAINER_ITEM, "DELETE FROM item_loot_items WHERE container_id = ? AND item_id = ? AND item_count = ?", CONNECTION_ASYNC);
- PrepareStatement(CHAR_INS_ITEMCONTAINER_ITEMS, "INSERT INTO item_loot_items (container_id, item_id, item_count, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
+ PrepareStatement(CHAR_DEL_ITEMCONTAINER_ITEM, "DELETE FROM item_loot_items WHERE container_id = ? AND item_id = ? AND item_count = ? AND item_index = ?", CONNECTION_ASYNC);
+ PrepareStatement(CHAR_INS_ITEMCONTAINER_ITEMS, "INSERT INTO item_loot_items (container_id, item_id, item_count, item_index, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_ITEMCONTAINER_MONEY, "SELECT container_id, money FROM item_loot_money", CONNECTION_SYNCH);
PrepareStatement(CHAR_DEL_ITEMCONTAINER_MONEY, "DELETE FROM item_loot_money WHERE container_id = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_ITEMCONTAINER_MONEY, "INSERT INTO item_loot_money (container_id, money) VALUES (?, ?)", CONNECTION_ASYNC);
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 0d82a489ad8..e1be438e018 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -24909,7 +24909,7 @@ void Player::StoreLootItem(uint8 lootSlot, Loot* loot)
// LootItem is being removed (looted) from the container, delete it from the DB.
if (loot->containerID > 0)
- sLootItemStorage->RemoveStoredLootItemForContainer(loot->containerID, item->itemid, item->count);
+ sLootItemStorage->RemoveStoredLootItemForContainer(loot->containerID, item->itemid, item->count, item->itemIndex);
}
else
diff --git a/src/server/game/Loot/Loot.cpp b/src/server/game/Loot/Loot.cpp
index ffd28eace61..4138936385a 100644
--- a/src/server/game/Loot/Loot.cpp
+++ b/src/server/game/Loot/Loot.cpp
@@ -151,6 +151,7 @@ void Loot::AddItem(LootStoreItem const& item)
{
LootItem generatedLoot(item);
generatedLoot.count = std::min(count, proto->GetMaxStackSize());
+ generatedLoot.itemIndex = lootItems.size();
lootItems.push_back(generatedLoot);
count -= proto->GetMaxStackSize();
diff --git a/src/server/game/Loot/Loot.h b/src/server/game/Loot/Loot.h
index 8012b01866f..2b618b97287 100644
--- a/src/server/game/Loot/Loot.h
+++ b/src/server/game/Loot/Loot.h
@@ -125,6 +125,7 @@ enum LootSlotType
struct TC_GAME_API LootItem
{
uint32 itemid;
+ uint32 itemIndex;
uint32 randomSuffix;
int32 randomPropertyId;
ConditionContainer conditions; // additional loot condition
@@ -144,7 +145,7 @@ struct TC_GAME_API LootItem
explicit LootItem(LootStoreItem const& li);
// Empty constructor for creating an empty LootItem to be filled in with DB data
- LootItem() : itemid(0), randomSuffix(0), randomPropertyId(0), count(0), is_looted(false), is_blocked(false),
+ LootItem() : itemid(0), itemIndex(0), randomSuffix(0), randomPropertyId(0), count(0), is_looted(false), is_blocked(false),
freeforall(false), is_underthreshold(false), is_counted(false), needs_quest(false), follow_loot_rules(false)
{ };
diff --git a/src/server/game/Loot/LootItemStorage.cpp b/src/server/game/Loot/LootItemStorage.cpp
index e3b1979cf65..36f3c3a12ad 100644
--- a/src/server/game/Loot/LootItemStorage.cpp
+++ b/src/server/game/Loot/LootItemStorage.cpp
@@ -80,14 +80,15 @@ void LootItemStorage::LoadStorageFromDB()
LootItem lootItem;
lootItem.itemid = fields[1].GetUInt32();
lootItem.count = fields[2].GetUInt32();
- lootItem.follow_loot_rules = fields[3].GetBool();
- lootItem.freeforall = fields[4].GetBool();
- lootItem.is_blocked = fields[5].GetBool();
- lootItem.is_counted = fields[6].GetBool();
- lootItem.is_underthreshold = fields[7].GetBool();
- lootItem.needs_quest = fields[8].GetBool();
- lootItem.randomPropertyId = fields[9].GetInt32();
- lootItem.randomSuffix = fields[10].GetUInt32();
+ lootItem.itemIndex = fields[3].GetUInt32();
+ lootItem.follow_loot_rules = fields[4].GetBool();
+ lootItem.freeforall = fields[5].GetBool();
+ lootItem.is_blocked = fields[6].GetBool();
+ lootItem.is_counted = fields[7].GetBool();
+ lootItem.is_underthreshold = fields[8].GetBool();
+ lootItem.needs_quest = fields[9].GetBool();
+ lootItem.randomPropertyId = fields[10].GetInt32();
+ lootItem.randomSuffix = fields[11].GetUInt32();
storedContainer.AddLootItem(lootItem, trans);
@@ -217,7 +218,7 @@ void LootItemStorage::RemoveStoredLootForContainer(uint32 containerId)
CharacterDatabase.CommitTransaction(trans);
}
-void LootItemStorage::RemoveStoredLootItemForContainer(uint32 containerId, uint32 itemId, uint32 count)
+void LootItemStorage::RemoveStoredLootItemForContainer(uint32 containerId, uint32 itemId, uint32 count, uint32 itemIndex)
{
// write
std::unique_lock<std::shared_mutex> lock(*GetLock());
@@ -226,7 +227,7 @@ void LootItemStorage::RemoveStoredLootItemForContainer(uint32 containerId, uint3
if (itr == _lootItemStore.end())
return;
- itr->second.RemoveItem(itemId, count);
+ itr->second.RemoveItem(itemId, count, itemIndex);
}
void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
@@ -292,18 +293,20 @@ void StoredLootContainer::AddLootItem(LootItem const& lootItem, CharacterDatabas
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEMCONTAINER_ITEMS);
- // container_id, item_id, item_count, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix
+ // container_id, item_id, item_count, item_index, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix
stmt->setUInt32(0, _containerId);
stmt->setUInt32(1, lootItem.itemid);
stmt->setUInt32(2, lootItem.count);
- stmt->setBool(3, lootItem.follow_loot_rules);
- stmt->setBool(4, lootItem.freeforall);
- stmt->setBool(5, lootItem.is_blocked);
- stmt->setBool(6, lootItem.is_counted);
- stmt->setBool(7, lootItem.is_underthreshold);
- stmt->setBool(8, lootItem.needs_quest);
- stmt->setInt32(9, lootItem.randomPropertyId);
- stmt->setUInt32(10, lootItem.randomSuffix);
+ stmt->setUInt32(3, lootItem.itemIndex);
+ stmt->setBool(4, lootItem.follow_loot_rules);
+ stmt->setBool(5, lootItem.freeforall);
+ stmt->setBool(6, lootItem.is_blocked);
+ stmt->setBool(7, lootItem.is_counted);
+ stmt->setBool(8, lootItem.is_underthreshold);
+ stmt->setBool(9, lootItem.needs_quest);
+ stmt->setInt32(10, lootItem.randomPropertyId);
+ stmt->setUInt32(11, lootItem.randomSuffix);
+
trans->Append(stmt);
}
@@ -332,7 +335,7 @@ void StoredLootContainer::RemoveMoney()
CharacterDatabase.Execute(stmt);
}
-void StoredLootContainer::RemoveItem(uint32 itemId, uint32 count)
+void StoredLootContainer::RemoveItem(uint32 itemId, uint32 count, uint32 itemIndex)
{
auto bounds = _lootItems.equal_range(itemId);
for (auto itr = bounds.first; itr != bounds.second; ++itr)
@@ -349,5 +352,6 @@ void StoredLootContainer::RemoveItem(uint32 itemId, uint32 count)
stmt->setUInt32(0, _containerId);
stmt->setUInt32(1, itemId);
stmt->setUInt32(2, count);
+ stmt->setUInt32(3, itemIndex);
CharacterDatabase.Execute(stmt);
}
diff --git a/src/server/game/Loot/LootItemStorage.h b/src/server/game/Loot/LootItemStorage.h
index 13e0e3e6cdc..d3903721e4c 100644
--- a/src/server/game/Loot/LootItemStorage.h
+++ b/src/server/game/Loot/LootItemStorage.h
@@ -56,7 +56,7 @@ class StoredLootContainer
void AddMoney(uint32 money, CharacterDatabaseTransaction trans);
void RemoveMoney();
- void RemoveItem(uint32 itemId, uint32 count);
+ void RemoveItem(uint32 itemId, uint32 count, uint32 itemIndex);
uint32 GetContainer() const { return _containerId; }
uint32 GetMoney() const { return _money; }
@@ -78,7 +78,7 @@ class LootItemStorage
bool LoadStoredLoot(Item* item, Player* player);
void RemoveStoredMoneyForContainer(uint32 containerId);
void RemoveStoredLootForContainer(uint32 containerId);
- void RemoveStoredLootItemForContainer(uint32 containerId, uint32 itemId, uint32 count);
+ void RemoveStoredLootItemForContainer(uint32 containerId, uint32 itemId, uint32 count, uint32 itemIndex);
void AddNewStoredLoot(Loot* loot, Player* player);
private: