TrinityCore
Loading...
Searching...
No Matches
LootMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_LOOTMGR_H
19#define TRINITY_LOOTMGR_H
20
21#include "Define.h"
22#include "ConditionMgr.h"
23#include "ObjectGuid.h"
24#include <memory>
25#include <set>
26#include <unordered_map>
27#include <vector>
28
29class LootStore;
30class LootTemplate;
31class Player;
32struct Loot;
33struct LootItem;
35enum LootType : uint8;
36enum class ItemContext : uint8;
37
39{
40 enum class Type : int8
41 {
42 Item = 0,
43 Reference = 1,
44 Currency = 2,
45 TrackingQuest = 3,
46 };
47
48 uint32 itemid; // id of the item
50 float chance; // chance to drop for both quest and non-quest items, chance to be used for refs
52 bool needs_quest; // quest drop (quest is required for item to drop)
54 uint8 mincount; // mincount for drop items
55 uint8 maxcount; // max drop count for the item mincount or Ref multiplicator
56 ConditionsReference conditions; // additional loot condition
57
58 // Constructor
59 LootStoreItem(uint32 _itemid, Type _type, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, uint8 _mincount, uint8 _maxcount)
60 : itemid(_itemid), type(_type), chance(_chance), lootmode(_lootmode),
61 needs_quest(_needs_quest), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
62 { }
63
64 bool Roll(bool rate) const; // Checks if the entry takes it's chance (at loot generation)
65 bool IsValid(LootStore const& store, uint32 entry) const; // Checks correctness of values
66};
67
68typedef std::vector<std::unique_ptr<LootStoreItem>> LootStoreItemList;
69typedef std::unordered_map<uint32, std::unique_ptr<LootTemplate>> LootTemplateMap;
70
71typedef std::set<uint32> LootIdSet;
72
74{
75 public:
76 explicit LootStore(char const* name, char const* entryName, bool ratesAllowed);
77
78 LootStore(LootStore const&) = delete;
79 LootStore(LootStore&&) noexcept;
80 LootStore& operator=(LootStore const&) = delete;
81 LootStore& operator=(LootStore&&) noexcept;
82
84
85 void Verify() const;
86
87 uint32 LoadAndCollectLootIds(LootIdSet& lootIdSet);
88 void CheckLootRefs(LootIdSet* ref_set = nullptr) const; // check existence reference and remove it from ref_set
89 void ReportUnusedIds(LootIdSet const& lootIdSet) const;
90 void ReportNonExistingId(uint32 lootId, char const* ownerType, uint32 ownerId) const;
91
92 bool HaveLootFor(uint32 loot_id) const { return m_LootTemplates.contains(loot_id); }
93 bool HaveQuestLootFor(uint32 loot_id) const;
94 bool HaveQuestLootForPlayer(uint32 loot_id, Player const* player) const;
95
96 LootTemplate const* GetLootFor(uint32 loot_id) const;
97 LootTemplate* GetLootForConditionFill(uint32 loot_id);
98
99 char const* GetName() const { return m_name; }
100 char const* GetEntryName() const { return m_entryName; }
101 bool IsRatesAllowed() const { return m_ratesAllowed; }
102 protected:
103 uint32 LoadLootTable();
104 void Clear();
105 private:
107 char const* m_name;
108 char const* m_entryName;
110};
111
113{
114 class LootGroup; // A set of loot definitions for items (refs are not allowed inside)
115 typedef std::vector<std::unique_ptr<LootGroup>> LootGroups;
116
117 public:
119
120 LootTemplate(LootTemplate const&) = delete;
122 LootTemplate& operator=(LootTemplate const&) = delete;
123 LootTemplate& operator=(LootTemplate&&) noexcept;
124
126
127 // Adds an entry to the group (at loading stage)
128 void AddEntry(LootStoreItem* item);
129 // Rolls for every item in the template and adds the rolled items the the loot
130 void Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId, Player const* personalLooter = nullptr) const;
131 void ProcessPersonalLoot(std::unordered_map<Player*, std::unique_ptr<Loot>>& personalLoot, bool rate, uint16 lootMode) const;
132 void CopyConditions(LootItem* li) const;
133
134 // True if template includes at least 1 drop for the player
135 bool HasDropForPlayer(Player const* player, uint8 groupId = 0, bool strictUsabilityCheck = false) const;
136 // True if template includes at least 1 quest drop entry
137 bool HasQuestDrop(LootTemplateMap const& store, uint8 groupId = 0) const;
138 // True if template includes at least 1 quest drop for an active quest of the player
139 bool HasQuestDropForPlayer(LootTemplateMap const& store, Player const* player, uint8 groupId = 0) const;
140
141 // Checks integrity of the template
142 void Verify(LootStore const& store, uint32 Id) const;
143 void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
144 bool LinkConditions(ConditionId const& id, ConditionsReference reference);
145
146 private:
147 LootStoreItemList Entries; // not grouped only
148 LootGroups Groups; // groups have own (optimised) processing, grouped entries go there
149};
150
151std::unordered_map<ObjectGuid, std::unique_ptr<Loot>> GenerateDungeonEncounterPersonalLoot(uint32 dungeonEncounterId,
152 uint32 lootId, LootStore const& store, LootType type, WorldObject const* lootOwner,
153 uint32 minMoney, uint32 maxMoney,
154 uint16 lootMode, MapDifficultyEntry const* mapDifficulty,
155 std::vector<Player*> const& tappers);
156
157//=====================================================
158
171
182
185
187
188#endif
ItemContext
Definition DBCEnums.h:1315
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int8_t int8
Definition Define.h:152
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
void LoadLootTemplates_Pickpocketing()
Definition LootMgr.cpp:1272
LootStore LootTemplates_Spell("spell_loot_template", "spell id (random item creating)", false)
LootStore LootTemplates_Skinning("skinning_loot_template", "creature skinning id", true)
void LoadLootTemplates_Spell()
Definition LootMgr.cpp:1393
void LoadLootTemplates_Milling()
Definition LootMgr.cpp:1247
LootStore LootTemplates_Gameobject("gameobject_loot_template", "gameobject entry", true)
void LoadLootTemplates_Gameobject()
Definition LootMgr.cpp:1176
void LoadLootTemplates_Creature()
Definition LootMgr.cpp:1072
LootStore LootTemplates_Item("item_loot_template", "item entry", true)
LootStore LootTemplates_Milling("milling_loot_template", "item entry (herb)", true)
LootStore LootTemplates_Reference("reference_loot_template", "reference id", false)
LootStore LootTemplates_Disenchant("disenchant_loot_template", "item disenchant id", true)
LootStore LootTemplates_Prospecting("prospecting_loot_template", "item entry (ore)", true)
void LoadLootTemplates_Fishing()
Definition LootMgr.cpp:1154
void LoadLootTables()
Definition LootMgr.cpp:1461
void LoadLootTemplates_Reference()
Definition LootMgr.cpp:1433
LootStore LootTemplates_Creature("creature_loot_template", "creature entry", true)
void LoadLootTemplates_Prospecting()
Definition LootMgr.cpp:1309
LootStore LootTemplates_Pickpocketing("pickpocketing_loot_template", "creature pickpocket lootid", true)
void LoadLootTemplates_Mail()
Definition LootMgr.cpp:1334
void LoadLootTemplates_Disenchant()
Definition LootMgr.cpp:1112
void LoadLootTemplates_Item()
Definition LootMgr.cpp:1222
std::unordered_map< ObjectGuid, std::unique_ptr< Loot > > GenerateDungeonEncounterPersonalLoot(uint32 dungeonEncounterId, uint32 lootId, LootStore const &store, LootType type, WorldObject const *lootOwner, uint32 minMoney, uint32 maxMoney, uint16 lootMode, MapDifficultyEntry const *mapDifficulty, std::vector< Player * > const &tappers)
Definition LootMgr.cpp:1037
LootStore LootTemplates_Mail("mail_loot_template", "mail template id", false)
void LoadLootTemplates_Skinning()
Definition LootMgr.cpp:1356
LootStore LootTemplates_Fishing("fishing_loot_template", "area id", true)
std::vector< std::unique_ptr< LootStoreItem > > LootStoreItemList
Definition LootMgr.h:68
std::unordered_map< uint32, std::unique_ptr< LootTemplate > > LootTemplateMap
Definition LootMgr.h:69
std::set< uint32 > LootIdSet
Definition LootMgr.h:71
LootType
Definition Loot.h:99
Definition Item.h:179
LootStore(LootStore const &)=delete
char const * m_entryName
Definition LootMgr.h:108
LootTemplateMap m_LootTemplates
Definition LootMgr.h:106
char const * GetEntryName() const
Definition LootMgr.h:100
bool m_ratesAllowed
Definition LootMgr.h:109
bool IsRatesAllowed() const
Definition LootMgr.h:101
char const * m_name
Definition LootMgr.h:107
LootStore(LootStore &&) noexcept
char const * GetName() const
Definition LootMgr.h:99
LootTemplate(LootTemplate &&) noexcept
std::vector< std::unique_ptr< LootGroup > > LootGroups
Definition LootMgr.h:115
LootTemplate(LootTemplate const &)=delete
STL namespace.
float chance
Definition LootMgr.h:50
ConditionsReference conditions
Definition LootMgr.h:56
bool needs_quest
Definition LootMgr.h:52
uint32 itemid
Definition LootMgr.h:48
uint8 maxcount
Definition LootMgr.h:55
uint16 lootmode
Definition LootMgr.h:51
uint8 groupid
Definition LootMgr.h:53
uint8 mincount
Definition LootMgr.h:54
LootStoreItem(uint32 _itemid, Type _type, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, uint8 _mincount, uint8 _maxcount)
Definition LootMgr.h:59
Definition Loot.h:286