TrinityCore
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 <list>
25#include <memory>
26#include <set>
27#include <unordered_map>
28#include <vector>
29
30class LootStore;
31class LootTemplate;
32class Player;
33struct Loot;
34struct LootItem;
36enum LootType : uint8;
37enum class ItemContext : uint8;
38
40{
41 uint32 itemid; // id of the item
42 uint32 reference; // referenced TemplateleId
43 float chance; // chance to drop for both quest and non-quest items, chance to be used for refs
45 bool needs_quest; // quest drop (quest is required for item to drop)
47 uint8 mincount; // mincount for drop items
48 uint8 maxcount; // max drop count for the item mincount or Ref multiplicator
49 ConditionsReference conditions; // additional loot condition
50
51 // Constructor
52 // displayid is filled in IsValid() which must be called after
53 LootStoreItem(uint32 _itemid, uint32 _reference, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, uint8 _mincount, uint8 _maxcount)
54 : itemid(_itemid), reference(_reference), chance(_chance), lootmode(_lootmode),
55 needs_quest(_needs_quest), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
56 { }
57
58 bool Roll(bool rate) const; // Checks if the entry takes it's chance (at loot generation)
59 bool IsValid(LootStore const& store, uint32 entry) const; // Checks correctness of values
60};
61
62typedef std::list<LootStoreItem*> LootStoreItemList;
63typedef std::unordered_map<uint32, LootTemplate*> LootTemplateMap;
64
65typedef std::set<uint32> LootIdSet;
66
68{
69 public:
70 explicit LootStore(char const* name, char const* entryName, bool ratesAllowed)
71 : m_name(name), m_entryName(entryName), m_ratesAllowed(ratesAllowed) { }
72
73 virtual ~LootStore() { Clear(); }
74
75 void Verify() const;
76
77 uint32 LoadAndCollectLootIds(LootIdSet& ids_set);
78 void CheckLootRefs(LootIdSet* ref_set = nullptr) const; // check existence reference and remove it from ref_set
79 void ReportUnusedIds(LootIdSet const& ids_set) const;
80 void ReportNonExistingId(uint32 lootId) const;
81 void ReportNonExistingId(uint32 lootId, char const* ownerType, uint32 ownerId) const;
82
83 bool HaveLootFor(uint32 loot_id) const { return m_LootTemplates.find(loot_id) != m_LootTemplates.end(); }
84 bool HaveQuestLootFor(uint32 loot_id) const;
85 bool HaveQuestLootForPlayer(uint32 loot_id, Player const* player) const;
86
87 LootTemplate const* GetLootFor(uint32 loot_id) const;
88 LootTemplate* GetLootForConditionFill(uint32 loot_id);
89
90 char const* GetName() const { return m_name; }
91 char const* GetEntryName() const { return m_entryName; }
92 bool IsRatesAllowed() const { return m_ratesAllowed; }
93 protected:
94 uint32 LoadLootTable();
95 void Clear();
96 private:
98 char const* m_name;
99 char const* m_entryName;
101};
102
104{
105 class LootGroup; // A set of loot definitions for items (refs are not allowed inside)
106 typedef std::vector<LootGroup*> LootGroups;
107
108 public:
111
112 // Adds an entry to the group (at loading stage)
113 void AddEntry(LootStoreItem* item);
114 // Rolls for every item in the template and adds the rolled items the the loot
115 void Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId, Player const* personalLooter = nullptr) const;
116 void ProcessPersonalLoot(std::unordered_map<Player*, std::unique_ptr<Loot>>& personalLoot, bool rate, uint16 lootMode) const;
117 void CopyConditions(LootItem* li) const;
118
119 // True if template includes at least 1 drop for the player
120 bool HasDropForPlayer(Player const* player, uint8 groupId = 0, bool strictUsabilityCheck = false) const;
121 // True if template includes at least 1 quest drop entry
122 bool HasQuestDrop(LootTemplateMap const& store, uint8 groupId = 0) const;
123 // True if template includes at least 1 quest drop for an active quest of the player
124 bool HasQuestDropForPlayer(LootTemplateMap const& store, Player const* player, uint8 groupId = 0) const;
125
126 // Checks integrity of the template
127 void Verify(LootStore const& store, uint32 Id) const;
128 void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
129 bool LinkConditions(ConditionId const& id, ConditionsReference reference);
130 bool isReference(uint32 id);
131
132 private:
133 LootStoreItemList Entries; // not grouped only
134 LootGroups Groups; // groups have own (optimised) processing, grouped entries go there
135
136 // Objects of this class must never be copied, we are storing pointers in container
137 LootTemplate(LootTemplate const&) = delete;
139};
140
141std::unordered_map<ObjectGuid, std::unique_ptr<Loot>> GenerateDungeonEncounterPersonalLoot(uint32 dungeonEncounterId,
142 uint32 lootId, LootStore const& store, LootType type, WorldObject const* lootOwner,
143 uint32 minMoney, uint32 maxMoney,
144 uint16 lootMode, MapDifficultyEntry const* mapDifficulty,
145 std::vector<Player*> const& tappers);
146
147//=====================================================
148
161
172
175
177
178#endif
ItemContext
Definition: DBCEnums.h:1063
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
TC_GAME_API void LoadLootTemplates_Skinning()
Definition: LootMgr.cpp:1231
TC_GAME_API LootStore LootTemplates_Reference
TC_GAME_API void LoadLootTemplates_Creature()
Definition: LootMgr.cpp:949
TC_GAME_API void LoadLootTemplates_Milling()
Definition: LootMgr.cpp:1112
TC_GAME_API void LoadLootTemplates_Disenchant()
Definition: LootMgr.cpp:989
TC_GAME_API LootStore LootTemplates_Gameobject
TC_GAME_API LootStore LootTemplates_Item
TC_GAME_API LootStore LootTemplates_Prospecting
TC_GAME_API void LoadLootTemplates_Gameobject()
Definition: LootMgr.cpp:1042
TC_GAME_API LootStore LootTemplates_Skinning
TC_GAME_API void LoadLootTemplates_Pickpocketing()
Definition: LootMgr.cpp:1141
TC_GAME_API LootStore LootTemplates_Fishing
TC_GAME_API void LoadLootTemplates_Prospecting()
Definition: LootMgr.cpp:1178
TC_GAME_API LootStore LootTemplates_Disenchant
TC_GAME_API LootStore LootTemplates_Pickpocketing
TC_GAME_API LootStore LootTemplates_Spell
std::unordered_map< uint32, LootTemplate * > LootTemplateMap
Definition: LootMgr.h:63
TC_GAME_API void LoadLootTemplates_Mail()
Definition: LootMgr.cpp:1207
TC_GAME_API LootStore LootTemplates_Creature
TC_GAME_API void LoadLootTables()
Definition: LootMgr.cpp:1337
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:914
TC_GAME_API LootStore LootTemplates_Mail
std::set< uint32 > LootIdSet
Definition: LootMgr.h:65
std::list< LootStoreItem * > LootStoreItemList
Definition: LootMgr.h:62
TC_GAME_API void LoadLootTemplates_Item()
Definition: LootMgr.cpp:1088
TC_GAME_API void LoadLootTemplates_Fishing()
Definition: LootMgr.cpp:1019
TC_GAME_API void LoadLootTemplates_Reference()
Definition: LootMgr.cpp:1309
TC_GAME_API LootStore LootTemplates_Milling
TC_GAME_API void LoadLootTemplates_Spell()
Definition: LootMgr.cpp:1268
LootType
Definition: Loot.h:98
char const * m_entryName
Definition: LootMgr.h:99
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:97
virtual ~LootStore()
Definition: LootMgr.h:73
char const * GetEntryName() const
Definition: LootMgr.h:91
LootStore(char const *name, char const *entryName, bool ratesAllowed)
Definition: LootMgr.h:70
bool m_ratesAllowed
Definition: LootMgr.h:100
bool IsRatesAllowed() const
Definition: LootMgr.h:92
char const * m_name
Definition: LootMgr.h:98
bool HaveLootFor(uint32 loot_id) const
Definition: LootMgr.h:83
char const * GetName() const
Definition: LootMgr.h:90
LootTemplate()
Definition: LootMgr.h:109
LootStoreItemList Entries
Definition: LootMgr.h:133
LootTemplate(LootTemplate const &)=delete
std::vector< LootGroup * > LootGroups
Definition: LootMgr.h:106
LootGroups Groups
Definition: LootMgr.h:134
LootTemplate & operator=(LootTemplate const &)=delete
Definition: Loot.h:176
float chance
Definition: LootMgr.h:43
LootStoreItem(uint32 _itemid, uint32 _reference, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, uint8 _mincount, uint8 _maxcount)
Definition: LootMgr.h:53
ConditionsReference conditions
Definition: LootMgr.h:49
bool needs_quest
Definition: LootMgr.h:45
uint32 itemid
Definition: LootMgr.h:41
uint32 reference
Definition: LootMgr.h:42
uint8 maxcount
Definition: LootMgr.h:48
uint16 lootmode
Definition: LootMgr.h:44
uint8 groupid
Definition: LootMgr.h:46
uint8 mincount
Definition: LootMgr.h:47
Definition: Loot.h:281