TrinityCore
Loading...
Searching...
No Matches
Loot.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 Loot_h__
19#define Loot_h__
20
21#include "Define.h"
22#include "ConditionMgr.h"
23#include "ObjectGuid.h"
24#include "RefManager.h"
25#include "SharedDefines.h"
26#include <unordered_map>
27#include <vector>
28
29class Item;
30class LootStore;
31class Player;
32struct Loot;
33struct LootStoreItem;
34
35namespace WorldPackets
36{
37 namespace Loot
38 {
39 class LootResponse;
40 }
41}
42
51
62
63#define MAX_NR_LOOT_ITEMS 18
64// note: the client cannot show more than 16 items total
65#define MAX_NR_QUEST_ITEMS 32
66// unrelated to the number of quest items shown, just for reserve
67
76
87
89{
91
96 // ignored always by client
100
101 LOOT_FISHINGHOLE = 20, // unsupported by client, sending LOOT_FISHING instead
102 LOOT_INSIGNIA = 21, // unsupported by client, sending LOOT_CORPSE instead
103 LOOT_FISHING_JUNK = 22 // unsupported by client, sending LOOT_FISHING instead
105
107{
108 switch (lootType)
109 {
110 case LOOT_INSIGNIA:
111 return LOOT_SKINNING;
112 case LOOT_FISHINGHOLE:
114 return LOOT_FISHING;
115 default:
116 break;
117 }
118 return lootType;
119}
120
122{
123 LOOT_ERROR_DIDNT_KILL = 0, // You don't have permission to loot that corpse.
124 LOOT_ERROR_TOO_FAR = 4, // You are too far away to loot that corpse.
125 LOOT_ERROR_BAD_FACING = 5, // You must be facing the corpse to loot it.
126 LOOT_ERROR_LOCKED = 6, // Someone is already looting that corpse.
127 LOOT_ERROR_NOTSTANDING = 8, // You need to be standing up to loot something!
128 LOOT_ERROR_STUNNED = 9, // You can't loot anything while stunned!
129 LOOT_ERROR_PLAYER_NOT_FOUND = 10, // Player not found
130 LOOT_ERROR_PLAY_TIME_EXCEEDED = 11, // Maximum play time exceeded
131 LOOT_ERROR_MASTER_INV_FULL = 12, // That player's inventory is full
132 LOOT_ERROR_MASTER_UNIQUE_ITEM = 13, // Player has too many of that item already
133 LOOT_ERROR_MASTER_OTHER = 14, // Can't assign item to that player
134 LOOT_ERROR_ALREADY_PICKPOCKETED = 15, // Your target has already had its pockets picked
135 LOOT_ERROR_NOT_WHILE_SHAPESHIFTED = 16 // You can't do that while shapeshifted.
137
138// type of Loot Item in Loot View
140{
141 LOOT_SLOT_TYPE_ALLOW_LOOT = 0, // player can loot the item.
142 LOOT_SLOT_TYPE_ROLL_ONGOING = 1, // roll is ongoing. player cannot loot.
143 LOOT_SLOT_TYPE_MASTER = 2, // item can only be distributed by group loot master.
144 LOOT_SLOT_TYPE_LOCKED = 3, // item is shown in red. player cannot loot.
145 LOOT_SLOT_TYPE_OWNER = 4 // ignore binding confirmation and etc, for single player looting
147
149{
154 ConditionContainer conditions; // additional loot condition
156 ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
158 bool is_looted : 1;
159 bool is_blocked : 1;
160 bool freeforall : 1; // free for all
162 bool is_counted : 1;
163 bool needs_quest : 1; // quest drop
165
166 // Constructor, copies most fields from LootStoreItem, generates random count and random suffixes/properties
167 // Should be called for non-reference LootStoreItem entries only (reference = 0)
168 explicit LootItem(LootStoreItem const& li);
169
170 // Empty constructor for creating an empty LootItem to be filled in with DB data
171 LootItem() : itemid(0), itemIndex(0), randomPropertySeed(0), randomPropertyId(0), count(0), is_looted(false), is_blocked(false),
172 freeforall(false), is_underthreshold(false), is_counted(false), needs_quest(false), follow_loot_rules(false)
173 { };
174
175 // Basic checks for player/item compatibility - if false no chance to see the item in the loot
176 bool AllowedForPlayer(Player const* player, bool isGivenByMasterLooter, ObjectGuid ownerGuid) const;
177 bool AllowedForPlayer(Player const* player, bool isGivenByMasterLooter = false) const;
178 bool AllowedForPlayer(Player const* player, ObjectGuid ownerGuid) const;
179 void AddAllowedLooter(Player const* player);
180 GuidSet const& GetAllowedLooters() const { return allowedGUIDs; }
181};
182
184{
185 uint8 index; // position in quest_items or items;
187
189 : index(0), is_looted(false) { }
190
191 NotNormalLootItem(uint8 _index, bool _islooted = false)
192 : index(_index), is_looted(_islooted) { }
193};
194
195struct Loot;
196class LootTemplate;
197
198typedef std::vector<NotNormalLootItem> NotNormalLootItemList;
199typedef std::vector<LootItem> LootItemList;
200typedef std::unordered_map<ObjectGuid, NotNormalLootItemList*> NotNormalLootItemMap;
201
202class LootValidatorRef : public Reference<Loot, LootValidatorRef>
203{
204 public:
206 void targetObjectDestroyLink() override { }
207 void sourceObjectDestroyLink() override { }
208};
209
210//=====================================================
211
222
223//=====================================================
224
226{
227 NotNormalLootItemMap const& GetPlayerQuestItems() const { return PlayerQuestItems; }
228 NotNormalLootItemMap const& GetPlayerFFAItems() const { return PlayerFFAItems; }
229 NotNormalLootItemMap const& GetPlayerNonQuestNonFFAConditionalItems() const { return PlayerNonQuestNonFFAConditionalItems; }
230
231 std::vector<LootItem> items;
232 std::vector<LootItem> quest_items;
235 ObjectGuid roundRobinPlayer; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released.
237 LootType loot_type; // required for achievement system
238 uint8 maxDuplicates; // Max amount of items with the same entry that can drop (default is 1; on 25 man raid mode 3)
239
240 // GUIDLow of container that holds this loot (item_instance.entry)
241 // Only set for inventory items that can be right-click looted
243
244 Loot(uint32 _gold = 0);
245 ~Loot();
246
247 // if loot becomes invalid this reference is used to inform the listener
248 void addLootValidatorRef(LootValidatorRef* pLootValidatorRef)
249 {
250 i_LootValidatorRefManager.insertFirst(pLootValidatorRef);
251 }
252
253 void clear();
254
255 bool empty() const { return items.empty() && gold == 0; }
256 bool isLooted() const { return gold == 0 && unlootedCount == 0; }
257
258 void NotifyItemRemoved(uint8 lootIndex);
259 void NotifyQuestItemRemoved(uint8 questIndex);
260 void NotifyMoneyRemoved();
261 void AddLooter(ObjectGuid GUID) { PlayersLooting.insert(GUID); }
262 void RemoveLooter(ObjectGuid GUID) { PlayersLooting.erase(GUID); }
263
264 void generateMoneyLoot(uint32 minAmount, uint32 maxAmount);
265 bool FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError = false, uint16 lootMode = LOOT_MODE_DEFAULT);
266
267 // Inserts the item into the loot (called by LootTemplate processors)
268 void AddItem(LootStoreItem const & item);
269
270 LootItem* LootItemInSlot(uint32 lootslot, Player* player, NotNormalLootItem** qitem = nullptr, NotNormalLootItem** ffaitem = nullptr, NotNormalLootItem** conditem = nullptr);
271 uint32 GetMaxSlotInLootFor(Player* player) const;
272 bool hasItemForAll() const;
273 bool hasItemFor(Player const* player) const;
274 bool hasOverThresholdItem() const;
275
276 // Builds data for SMSG_LOOT_RESPONSE
277 void BuildLootResponse(WorldPackets::Loot::LootResponse& packet, Player const* viewer, PermissionTypes permission) const;
278
279private:
280 void FillNotNormalLootFor(Player* player, bool presentAtLooting);
281 NotNormalLootItemList* FillFFALoot(Player* player);
282 NotNormalLootItemList* FillQuestLoot(Player* player);
283 NotNormalLootItemList* FillNonQuestNonFFAConditionalLoot(Player* player, bool presentAtLooting);
284
289
290 // All rolls are registered here. They need to know, when the loot is not valid anymore
292};
293
294#endif // Loot_h__
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
LootType
Definition Loot.h:89
@ LOOT_PICKPOCKETING
Definition Loot.h:93
@ LOOT_MILLING
Definition Loot.h:99
@ LOOT_FISHING_JUNK
Definition Loot.h:103
@ LOOT_CORPSE
Definition Loot.h:92
@ LOOT_FISHING
Definition Loot.h:94
@ LOOT_INSIGNIA
Definition Loot.h:102
@ LOOT_DISENCHANTING
Definition Loot.h:95
@ LOOT_SKINNING
Definition Loot.h:97
@ LOOT_FISHINGHOLE
Definition Loot.h:101
@ LOOT_NONE
Definition Loot.h:90
@ LOOT_PROSPECTING
Definition Loot.h:98
PermissionTypes
Definition Loot.h:78
@ OWNER_PERMISSION
Definition Loot.h:84
@ ALL_PERMISSION
Definition Loot.h:79
@ RESTRICTED_PERMISSION
Definition Loot.h:82
@ NONE_PERMISSION
Definition Loot.h:85
@ ROUND_ROBIN_PERMISSION
Definition Loot.h:83
@ MASTER_PERMISSION
Definition Loot.h:81
@ GROUP_PERMISSION
Definition Loot.h:80
LootMethod
Definition Loot.h:69
@ NEED_BEFORE_GREED
Definition Loot.h:74
@ GROUP_LOOT
Definition Loot.h:73
@ MASTER_LOOT
Definition Loot.h:72
@ ROUND_ROBIN
Definition Loot.h:71
@ FREE_FOR_ALL
Definition Loot.h:70
RollMask
Definition Loot.h:53
@ ROLL_ALL_TYPE_NO_DISENCHANT
Definition Loot.h:59
@ ROLL_FLAG_TYPE_DISENCHANT
Definition Loot.h:57
@ ROLL_ALL_TYPE_MASK
Definition Loot.h:60
@ ROLL_FLAG_TYPE_GREED
Definition Loot.h:56
@ ROLL_FLAG_TYPE_PASS
Definition Loot.h:54
@ ROLL_FLAG_TYPE_NEED
Definition Loot.h:55
std::vector< LootItem > LootItemList
Definition Loot.h:199
constexpr LootType GetLootTypeForClient(LootType lootType)
Definition Loot.h:106
RollType
Definition Loot.h:44
@ MAX_ROLL_TYPE
Definition Loot.h:49
@ ROLL_PASS
Definition Loot.h:45
@ ROLL_GREED
Definition Loot.h:47
@ ROLL_NEED
Definition Loot.h:46
@ ROLL_DISENCHANT
Definition Loot.h:48
LootSlotType
Definition Loot.h:140
@ LOOT_SLOT_TYPE_MASTER
Definition Loot.h:143
@ LOOT_SLOT_TYPE_ROLL_ONGOING
Definition Loot.h:142
@ LOOT_SLOT_TYPE_ALLOW_LOOT
Definition Loot.h:141
@ LOOT_SLOT_TYPE_OWNER
Definition Loot.h:145
@ LOOT_SLOT_TYPE_LOCKED
Definition Loot.h:144
std::unordered_map< ObjectGuid, NotNormalLootItemList * > NotNormalLootItemMap
Definition Loot.h:200
std::vector< NotNormalLootItem > NotNormalLootItemList
Definition Loot.h:198
LootError
Definition Loot.h:122
@ LOOT_ERROR_TOO_FAR
Definition Loot.h:124
@ LOOT_ERROR_MASTER_OTHER
Definition Loot.h:133
@ LOOT_ERROR_BAD_FACING
Definition Loot.h:125
@ LOOT_ERROR_LOCKED
Definition Loot.h:126
@ LOOT_ERROR_MASTER_INV_FULL
Definition Loot.h:131
@ LOOT_ERROR_MASTER_UNIQUE_ITEM
Definition Loot.h:132
@ LOOT_ERROR_DIDNT_KILL
Definition Loot.h:123
@ LOOT_ERROR_PLAY_TIME_EXCEEDED
Definition Loot.h:130
@ LOOT_ERROR_NOTSTANDING
Definition Loot.h:127
@ LOOT_ERROR_NOT_WHILE_SHAPESHIFTED
Definition Loot.h:135
@ LOOT_ERROR_PLAYER_NOT_FOUND
Definition Loot.h:129
@ LOOT_ERROR_ALREADY_PICKPOCKETED
Definition Loot.h:134
@ LOOT_ERROR_STUNNED
Definition Loot.h:128
std::set< ObjectGuid > GuidSet
Definition ObjectGuid.h:260
@ LOOT_MODE_DEFAULT
Definition Item.h:62
LinkedListHead::Iterator< LootValidatorRef > iterator
Definition Loot.h:215
iterator begin()
Definition Loot.h:219
LootValidatorRef * getFirst()
Definition Loot.h:217
void sourceObjectDestroyLink() override
Definition Loot.h:207
void targetObjectDestroyLink() override
Definition Loot.h:206
Reference< TO, FROM > * getFirst()
Definition RefManager.h:32
uint32 itemid
Definition Loot.h:150
bool is_blocked
Definition Loot.h:159
ObjectGuid rollWinnerGUID
Definition Loot.h:156
bool needs_quest
Definition Loot.h:163
bool follow_loot_rules
Definition Loot.h:164
bool is_underthreshold
Definition Loot.h:161
GuidSet allowedGUIDs
Definition Loot.h:155
int32 randomPropertyId
Definition Loot.h:153
uint32 itemIndex
Definition Loot.h:151
uint32 randomPropertySeed
Definition Loot.h:152
uint8 count
Definition Loot.h:157
bool is_looted
Definition Loot.h:158
LootItem()
Definition Loot.h:171
GuidSet const & GetAllowedLooters() const
Definition Loot.h:180
ConditionContainer conditions
Definition Loot.h:154
bool freeforall
Definition Loot.h:160
bool is_counted
Definition Loot.h:162
Definition Loot.h:226
void AddLooter(ObjectGuid GUID)
Definition Loot.h:261
bool empty() const
Definition Loot.h:255
NotNormalLootItemMap const & GetPlayerQuestItems() const
Definition Loot.h:227
bool isLooted() const
Definition Loot.h:256
NotNormalLootItemMap PlayerFFAItems
Definition Loot.h:287
uint8 unlootedCount
Definition Loot.h:234
ObjectGuid roundRobinPlayer
Definition Loot.h:235
ObjectGuid lootOwnerGUID
Definition Loot.h:236
NotNormalLootItemMap PlayerNonQuestNonFFAConditionalItems
Definition Loot.h:288
GuidSet PlayersLooting
Definition Loot.h:285
uint32 containerID
Definition Loot.h:242
NotNormalLootItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition Loot.h:229
uint32 gold
Definition Loot.h:233
uint8 maxDuplicates
Definition Loot.h:238
std::vector< LootItem > items
Definition Loot.h:231
void RemoveLooter(ObjectGuid GUID)
Definition Loot.h:262
NotNormalLootItemMap PlayerQuestItems
Definition Loot.h:286
NotNormalLootItemMap const & GetPlayerFFAItems() const
Definition Loot.h:228
void addLootValidatorRef(LootValidatorRef *pLootValidatorRef)
Definition Loot.h:248
LootType loot_type
Definition Loot.h:237
std::vector< LootItem > quest_items
Definition Loot.h:232
LootValidatorRefManager i_LootValidatorRefManager
Definition Loot.h:291
NotNormalLootItem(uint8 _index, bool _islooted=false)
Definition Loot.h:191