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 "SharedDefines.h"
25#include <list>
26#include <vector>
27
28class LootStore;
29class LootTemplate;
30class Player;
31struct Loot;
32struct LootItem;
33
35{
36 uint32 itemid; // id of the item
37 uint32 reference; // referenced TemplateleId
38 float chance; // chance to drop for both quest and non-quest items, chance to be used for refs
40 bool needs_quest; // quest drop (quest is required for item to drop)
42 uint8 mincount; // mincount for drop items
43 uint8 maxcount; // max drop count for the item mincount or Ref multiplicator
44 ConditionContainer conditions; // additional loot condition
45
46 // Constructor
47 // displayid is filled in IsValid() which must be called after
48 LootStoreItem(uint32 _itemid, uint32 _reference, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, int32 _mincount, uint8 _maxcount)
49 : itemid(_itemid), reference(_reference), chance(_chance), lootmode(_lootmode),
50 needs_quest(_needs_quest), groupid(_groupid), mincount(_mincount), maxcount(_maxcount)
51 { }
52
53 bool Roll(bool rate) const; // Checks if the entry takes it's chance (at loot generation)
54 bool IsValid(LootStore const& store, uint32 entry) const;
55 // Checks correctness of values
56};
57
58typedef std::list<LootStoreItem*> LootStoreItemList;
59typedef std::unordered_map<uint32, LootTemplate*> LootTemplateMap;
60
61typedef std::set<uint32> LootIdSet;
62
64{
65 public:
66 explicit LootStore(char const* name, char const* entryName, bool ratesAllowed)
67 : m_name(name), m_entryName(entryName), m_ratesAllowed(ratesAllowed) { }
68
69 virtual ~LootStore() { Clear(); }
70
71 void Verify() const;
72
73 uint32 LoadAndCollectLootIds(LootIdSet& ids_set);
74 void CheckLootRefs(LootIdSet* ref_set = nullptr) const; // check existence reference and remove it from ref_set
75 void ReportUnusedIds(LootIdSet const& ids_set) const;
76 void ReportNonExistingId(uint32 lootId, char const* ownerType, uint32 ownerId) const;
77
78 bool HaveLootFor(uint32 loot_id) const { return m_LootTemplates.find(loot_id) != m_LootTemplates.end(); }
79 bool HaveQuestLootFor(uint32 loot_id) const;
80 bool HaveQuestLootForPlayer(uint32 loot_id, Player const* player) const;
81
82 LootTemplate const* GetLootFor(uint32 loot_id) const;
83 void ResetConditions();
84 LootTemplate* GetLootForConditionFill(uint32 loot_id);
85
86 char const* GetName() const { return m_name; }
87 char const* GetEntryName() const { return m_entryName; }
88 bool IsRatesAllowed() const { return m_ratesAllowed; }
89 protected:
90 uint32 LoadLootTable();
91 void Clear();
92 private:
94 char const* m_name;
95 char const* m_entryName;
97};
98
100{
101 class LootGroup; // A set of loot definitions for items (refs are not allowed inside)
102 typedef std::vector<LootGroup*> LootGroups;
103
104 public:
107
108 // Adds an entry to the group (at loading stage)
109 void AddEntry(LootStoreItem* item);
110 // Rolls for every item in the template and adds the rolled items the the loot
111 void Process(Loot& loot, bool rate, uint16 lootMode, uint8 groupId = 0) const;
112 void CopyConditions(ConditionContainer const& conditions);
113 void CopyConditions(LootItem* li) const;
114
115 // True if template includes at least 1 quest drop entry
116 bool HasQuestDrop(uint8 groupId = 0) const;
117 // True if template includes at least 1 quest drop for an active quest of the player
118 bool HasQuestDropForPlayer(Player const* player, uint8 groupId = 0) const;
119
120 // Checks integrity of the template
121 void Verify(LootStore const& store, uint32 Id) const;
122 void CheckLootRefs(LootTemplateMap const& store, LootIdSet* ref_set) const;
123 bool addConditionItem(Condition* cond);
124 bool isReference(uint32 id);
125
126 private:
127 LootStoreItemList Entries; // not grouped only
128 LootGroups Groups; // groups have own (optimised) processing, grouped entries go there
129
130 // Objects of this class must never be copied, we are storing pointers in container
131 LootTemplate(LootTemplate const&) = delete;
133};
134
135//=====================================================
136
149
160
163
165
166#endif
std::vector< Condition * > ConditionContainer
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
TC_GAME_API void LoadLootTemplates_Skinning()
Definition LootMgr.cpp:1047
TC_GAME_API LootStore LootTemplates_Reference
TC_GAME_API void LoadLootTemplates_Creature()
Definition LootMgr.cpp:780
TC_GAME_API void LoadLootTemplates_Milling()
Definition LootMgr.cpp:931
TC_GAME_API void LoadLootTemplates_Disenchant()
Definition LootMgr.cpp:817
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:873
TC_GAME_API LootStore LootTemplates_Skinning
TC_GAME_API void LoadLootTemplates_Pickpocketing()
Definition LootMgr.cpp:960
TC_GAME_API LootStore LootTemplates_Fishing
TC_GAME_API void LoadLootTemplates_Prospecting()
Definition LootMgr.cpp:994
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:59
TC_GAME_API void LoadLootTemplates_Mail()
Definition LootMgr.cpp:1023
TC_GAME_API LootStore LootTemplates_Creature
TC_GAME_API void LoadLootTables()
Definition LootMgr.cpp:1149
TC_GAME_API LootStore LootTemplates_Mail
std::set< uint32 > LootIdSet
Definition LootMgr.h:61
std::list< LootStoreItem * > LootStoreItemList
Definition LootMgr.h:58
TC_GAME_API void LoadLootTemplates_Item()
Definition LootMgr.cpp:907
TC_GAME_API void LoadLootTemplates_Fishing()
Definition LootMgr.cpp:850
TC_GAME_API void LoadLootTemplates_Reference()
Definition LootMgr.cpp:1121
TC_GAME_API LootStore LootTemplates_Milling
TC_GAME_API void LoadLootTemplates_Spell()
Definition LootMgr.cpp:1081
char const * m_entryName
Definition LootMgr.h:95
LootTemplateMap m_LootTemplates
Definition LootMgr.h:93
virtual ~LootStore()
Definition LootMgr.h:69
char const * GetEntryName() const
Definition LootMgr.h:87
LootStore(char const *name, char const *entryName, bool ratesAllowed)
Definition LootMgr.h:66
bool m_ratesAllowed
Definition LootMgr.h:96
bool IsRatesAllowed() const
Definition LootMgr.h:88
char const * m_name
Definition LootMgr.h:94
bool HaveLootFor(uint32 loot_id) const
Definition LootMgr.h:78
char const * GetName() const
Definition LootMgr.h:86
LootStoreItemList Entries
Definition LootMgr.h:127
LootTemplate(LootTemplate const &)=delete
std::vector< LootGroup * > LootGroups
Definition LootMgr.h:102
LootGroups Groups
Definition LootMgr.h:128
LootTemplate & operator=(LootTemplate const &)=delete
Definition Group.h:130
float chance
Definition LootMgr.h:38
ConditionContainer conditions
Definition LootMgr.h:44
bool needs_quest
Definition LootMgr.h:40
uint32 itemid
Definition LootMgr.h:36
uint32 reference
Definition LootMgr.h:37
uint8 maxcount
Definition LootMgr.h:43
uint16 lootmode
Definition LootMgr.h:39
uint8 groupid
Definition LootMgr.h:41
uint8 mincount
Definition LootMgr.h:42
LootStoreItem(uint32 _itemid, uint32 _reference, float _chance, bool _needs_quest, uint16 _lootmode, uint8 _groupid, int32 _mincount, uint8 _maxcount)
Definition LootMgr.h:48
Definition Loot.h:207