diff options
| author | MrSmite <mrsmite@att.net> | 2012-12-14 00:46:36 -0500 |
|---|---|---|
| committer | MrSmite <mrsmite@att.net> | 2012-12-15 00:06:32 -0500 |
| commit | 04f08d26a72ab29b11fc2aaef65bc54078cc2086 (patch) | |
| tree | 23beab0b3ebbdb661fec8c7015d0acd1cb6f8b50 /src/server/game/Loot | |
| parent | 1f869ce3a52f2df27b004386d2aaf989254276ff (diff) | |
Implements saving of loot (items / money) contained inside lootable inventory items.
* Unlooted items / money persist across player sessions
* Loot inside items is tied to the item rather than the player so if trading
partially looted items becomes possible, this implementation will still work
* New tables added:
characters_database.sql (first time users)
characters_create_item_loot.sql (existing users)
Implementation Can be tested with:
Watertight Trunk [21113]
Bulging Sack of Gems [25422]
Fat Sack of Coins [11937]
Closes #2048
Diffstat (limited to 'src/server/game/Loot')
| -rw-r--r-- | src/server/game/Loot/LootMgr.cpp | 41 | ||||
| -rw-r--r-- | src/server/game/Loot/LootMgr.h | 16 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index ef3d2b9fbd6..098fcc657b3 100644 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -334,6 +334,7 @@ LootItem::LootItem(LootStoreItem const& li) is_blocked = 0; is_underthreshold = 0; is_counted = 0; + canSave = true; } // Basic checks for player/item compatibility - if false no chance to see the item in the loot @@ -654,6 +655,33 @@ void Loot::generateMoneyLoot(uint32 minAmount, uint32 maxAmount) } } +void Loot::DeleteLootItemFromContainerItemDB(uint32 itemID) +{ + // Deletes a single item associated with an openable item from the DB + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEMCONTAINER_ITEM); + stmt->setUInt32(0, containerID); + stmt->setUInt32(1, itemID); + CharacterDatabase.Execute(stmt); + + // Mark the item looted to prevent resaving + for (LootItemList::iterator _itr = items.begin(); _itr != items.end(); _itr++) + { + if (!_itr->itemid == itemID) + continue; + + _itr->canSave = true; + break; + } +} + +void Loot::DeleteLootMoneyFromContainerItemDB() +{ + // Deletes money loot associated with an openable item from the DB + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEMCONTAINER_MONEY); + stmt->setUInt32(0, containerID); + CharacterDatabase.Execute(stmt); +} + LootItem* Loot::LootItemInSlot(uint32 lootSlot, Player* player, QuestItem* *qitem, QuestItem* *ffaitem, QuestItem* *conditem) { LootItem* item = NULL; @@ -1239,6 +1267,19 @@ void LootTemplate::CopyConditions(ConditionList conditions) i->CopyConditions(conditions); } +void LootTemplate::CopyConditions(LootItem* li) const +{ + // Copies the conditions list from a template item to a LootItem + for (LootStoreItemList::const_iterator _iter = Entries.begin(); _iter != Entries.end(); ++_iter) + { + if (!_iter->itemid == li->itemid) + continue; + + li->conditions = _iter->conditions; + break; + } +} + // Rolls for every item in the template and adds the rolled items the the loot void LootTemplate::Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId) const { diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index 45fc5c7983c..cfa5d370e3b 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -141,14 +141,17 @@ struct LootItem bool is_counted : 1; bool needs_quest : 1; // quest drop bool follow_loot_rules : 1; + bool canSave; // Constructor, copies most fields from LootStoreItem, generates random count and random suffixes/properties // Should be called for non-reference LootStoreItem entries only (mincountOrRef > 0) explicit LootItem(LootStoreItem const& li); + // Empty constructor for creating an empty LootItem to be filled in with DB data + LootItem() : canSave(true){}; + // Basic checks for player/item compatibility - if false no chance to see the item in the loot bool AllowedForPlayer(Player const* player) const; - void AddAllowedLooter(Player const* player); const AllowedLooterSet & GetAllowedLooters() const { return allowedGUIDs; } }; @@ -223,6 +226,7 @@ class LootTemplate // Rolls for every item in the template and adds the rolled items the the loot void Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId = 0) const; void CopyConditions(ConditionList conditions); + void CopyConditions(LootItem* li) const; // True if template includes at least 1 quest drop entry bool HasQuestDrop(LootTemplateMap const& store, uint8 groupId = 0) const; @@ -286,10 +290,18 @@ struct Loot uint8 unlootedCount; uint64 roundRobinPlayer; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released. LootType loot_type; // required for achievement system + + // GUIDLow of container that holds this loot (item_instance.entry) + // Only set for inventory items that can be right-click looted + uint32 containerID; - Loot(uint32 _gold = 0) : gold(_gold), unlootedCount(0), loot_type(LOOT_CORPSE) {} + Loot(uint32 _gold = 0) : gold(_gold), unlootedCount(0), loot_type(LOOT_CORPSE), containerID(0) {} ~Loot() { clear(); } + // For deleting items at loot removal since there is no backward interface to the Item() + void DeleteLootItemFromContainerItemDB(uint32 itemID); + void DeleteLootMoneyFromContainerItemDB(); + // if loot becomes invalid this reference is used to inform the listener void addLootValidatorRef(LootValidatorRef* pLootValidatorRef) { |
