TrinityCore
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 "ConditionMgr.h"
22#include "DBCEnums.h"
23#include "Define.h"
24#include "Duration.h"
25#include "ItemEnchantmentMgr.h"
26#include "ObjectGuid.h"
27#include "Optional.h"
28#include "SharedDefines.h"
29#include <memory>
30#include <unordered_map>
31#include <vector>
32
33constexpr Minutes LOOT_ROLL_TIMEOUT = 1min;
34
35class Group;
36class Item;
37class LootStore;
38class Map;
39class Player;
41struct Loot;
42struct LootStoreItem;
43
44namespace WorldPackets
45{
46 namespace Loot
47 {
48 struct LootItemData;
49 class LootResponse;
50 }
51}
52
54{
61};
62
63enum class RollVote
64{
65 Pass = 0,
66 Need = 1,
67 Greed = 2,
68 Disenchant = 3,
69 NotEmitedYet = 4,
70 NotValid = 5
71};
72
74{
80
83};
84
85#define MAX_NR_LOOT_ITEMS 18
86
88{
95};
96
98{
100
110
111 LOOT_FISHINGHOLE = 20, // unsupported by client, sending LOOT_FISHING instead
112 LOOT_INSIGNIA = 21, // unsupported by client, sending LOOT_CORPSE instead
113 LOOT_FISHING_JUNK = 22, // unsupported by client, sending LOOT_FISHING instead
116};
117
119{
120 switch (lootType)
121 {
122 case LOOT_PROSPECTING:
123 case LOOT_MILLING:
124 return LOOT_DISENCHANTING;
125 case LOOT_INSIGNIA:
126 return LOOT_SKINNING;
127 case LOOT_FISHINGHOLE:
129 return LOOT_FISHING;
130 default:
131 break;
132 }
133 return lootType;
134}
135
137{
138 LOOT_ERROR_DIDNT_KILL = 0, // You don't have permission to loot that corpse.
139 LOOT_ERROR_TOO_FAR = 4, // You are too far away to loot that corpse.
140 LOOT_ERROR_BAD_FACING = 5, // You must be facing the corpse to loot it.
141 LOOT_ERROR_LOCKED = 6, // Someone is already looting that corpse.
142 LOOT_ERROR_NOTSTANDING = 8, // You need to be standing up to loot something!
143 LOOT_ERROR_STUNNED = 9, // You can't loot anything while stunned!
144 LOOT_ERROR_PLAYER_NOT_FOUND = 10, // Player not found
145 LOOT_ERROR_PLAY_TIME_EXCEEDED = 11, // Maximum play time exceeded
146 LOOT_ERROR_MASTER_INV_FULL = 12, // That player's inventory is full
147 LOOT_ERROR_MASTER_UNIQUE_ITEM = 13, // Player has too many of that item already
148 LOOT_ERROR_MASTER_OTHER = 14, // Can't assign item to that player
149 LOOT_ERROR_ALREADY_PICKPOCKETED = 15, // Your target has already had its pockets picked
150 LOOT_ERROR_NOT_WHILE_SHAPESHIFTED = 16, // You can't do that while shapeshifted.
151 LOOT_ERROR_NO_LOOT = 17 // There is no loot.
153
154// type of Loot Item in Loot View
156{
157 LOOT_SLOT_TYPE_ALLOW_LOOT = 0, // player can loot the item.
158 LOOT_SLOT_TYPE_ROLL_ONGOING = 1, // roll is ongoing. player cannot loot.
159 LOOT_SLOT_TYPE_MASTER = 3, // item can only be distributed by group loot master.
160 LOOT_SLOT_TYPE_LOCKED = 2, // item is shown in red. player cannot loot.
161 LOOT_SLOT_TYPE_OWNER = 4 // ignore binding confirmation and etc, for single player looting
163
165{
166 None = 0,
167 UnusableByClass = 1, // Your class may not roll need on this item.
168 MaxUniqueItemCount = 2, // You already have the maximum amount of this item.
169 CannotBeDisenchanted = 3, // This item may not be disenchanted.
170 EnchantingSkillTooLow = 4, // You do not have an Enchanter of skill %d in your group.
171 NeedDisabled = 5, // Need rolls are disabled for this item.
172 OwnBetterItem = 6 // You already have a powerful version of this item.
173};
174
176{
180 std::vector<int32> BonusListIDs;
182 ConditionsReference conditions; // additional loot condition
184 ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
186 bool is_looted : 1;
187 bool is_blocked : 1;
188 bool freeforall : 1; // free for all
190 bool is_counted : 1;
191 bool needs_quest : 1; // quest drop
193
194 // Constructor, copies most fields from LootStoreItem, generates random count and random suffixes/properties
195 // Should be called for non-reference LootStoreItem entries only (reference = 0)
196 explicit LootItem(LootStoreItem const& li);
197
198 // Empty constructor for creating an empty LootItem to be filled in with DB data
199 LootItem() : itemid(0), LootListId(0), randomBonusListId(0), context(ItemContext::NONE), count(0), is_looted(false), is_blocked(false),
200 freeforall(false), is_underthreshold(false), is_counted(false), needs_quest(false), follow_loot_rules(false) { }
201
203 LootItem(LootItem&&) noexcept;
204 LootItem& operator=(LootItem const&);
205 LootItem& operator=(LootItem&&) noexcept;
207
208 // Basic checks for player/item compatibility - if false no chance to see the item in the loot - used only for loot generation
209 bool AllowedForPlayer(Player const* player, Loot const* loot) const;
210 static bool AllowedForPlayer(Player const* player, Loot const* loot, uint32 itemid, bool needs_quest, bool follow_loot_rules, bool strictUsabilityCheck,
211 ConditionsReference const& conditions);
212 void AddAllowedLooter(Player const* player);
213 GuidSet const& GetAllowedLooters() const { return allowedGUIDs; }
214 bool HasAllowedLooter(ObjectGuid const& looter) const;
215 Optional<LootSlotType> GetUiTypeForPlayer(Player const* player, Loot const& loot) const;
216};
217
219{
222
224 : LootListId(0), is_looted(false) { }
225
226 NotNormalLootItem(uint8 _index, bool _islooted = false)
227 : LootListId(_index), is_looted(_islooted) { }
228};
229
230typedef std::vector<NotNormalLootItem> NotNormalLootItemList;
231typedef std::vector<LootItem> LootItemList;
232typedef std::unordered_map<ObjectGuid, std::unique_ptr<NotNormalLootItemList>> NotNormalLootItemMap;
233
234//=====================================================
235
237{
241};
242
244{
245public:
246 using RollVoteMap = std::unordered_map<ObjectGuid, PlayerRollVote>;
247
248 LootRoll() : m_map(nullptr), m_isStarted(false), m_lootItem(nullptr), m_loot(nullptr), m_voteMask(), m_endTime(TimePoint::min()) { }
249 ~LootRoll();
250
251 LootRoll(LootRoll const&) = delete;
252 LootRoll(LootRoll&&) = delete;
253 LootRoll& operator=(LootRoll const&) = delete;
255
256 bool TryToStart(Map* map, Loot& loot, uint32 lootListId, uint16 enchantingSkill);
257 bool PlayerVote(Player* player, RollVote vote);
258 bool UpdateRoll();
259
260 bool IsLootItem(ObjectGuid const& lootObject, uint32 lootListId) const;
261
262private:
263 void SendStartRoll();
264 void SendAllPassed();
265 void SendRoll(ObjectGuid const& targetGuid, int32 rollNumber, RollVote rollType, Optional<ObjectGuid> const& rollWinner);
266 void SendLootRollWon(ObjectGuid const& targetGuid, int32 rollNumber, RollVote rollType);
267 void FillPacket(WorldPackets::Loot::LootItemData& lootItem) const;
268 void Finish(RollVoteMap::const_iterator winnerItr);
269 bool AllPlayerVoted(RollVoteMap::const_iterator& winnerItr);
278};
279
281{
282 NotNormalLootItemMap const& GetPlayerFFAItems() const { return PlayerFFAItems; }
283
284 std::vector<LootItem> items;
287 ObjectGuid roundRobinPlayer; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released.
288 LootType loot_type; // required for achievement system
289
290 explicit Loot(Map* map, ObjectGuid owner, LootType type, Group const* group);
291 ~Loot();
292
293 Loot(Loot const&) = delete;
294 Loot(Loot&&) = delete;
295 Loot& operator=(Loot const&) = delete;
296 Loot& operator=(Loot&&) = delete;
297
298 ObjectGuid const& GetGUID() const { return _guid; }
299 ObjectGuid const& GetOwnerGUID() const { return _owner; }
300 ItemContext GetItemContext() const { return _itemContext; }
301 void SetItemContext(ItemContext context) { _itemContext = context; }
302 LootMethod GetLootMethod() const { return _lootMethod; }
303 ObjectGuid const& GetLootMasterGUID() const { return _lootMaster; }
304 uint32 GetDungeonEncounterId() const { return _dungeonEncounterId; }
305 void SetDungeonEncounterId(uint32 dungeonEncounterId) { _dungeonEncounterId = dungeonEncounterId; }
306
307 bool isLooted() const { return gold == 0 && unlootedCount == 0; }
308 bool IsChanged() const { return _changed; }
309
310 void NotifyLootList(Map const* map) const;
311 void NotifyItemRemoved(uint8 lootListId, Map const* map);
312 void NotifyMoneyRemoved(Map const* map);
313 void OnLootOpened(Map* map, ObjectGuid looter);
314 void AddLooter(ObjectGuid GUID) { PlayersLooting.insert(GUID); }
315 void RemoveLooter(ObjectGuid GUID) { PlayersLooting.erase(GUID); }
316
317 bool HasAllowedLooter(ObjectGuid const& looter) const;
318
319 void generateMoneyLoot(uint32 minAmount, uint32 maxAmount);
320 bool FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError = false, uint16 lootMode = LOOT_MODE_DEFAULT, ItemContext context = ItemContext::NONE);
321 void FillNotNormalLootFor(Player const* player); // count unlooted items
322
323 // Inserts the item into the loot (called by LootTemplate processors)
324 void AddItem(LootStoreItem const& item);
325
326 bool AutoStore(Player* player, uint8 bag, uint8 slot, bool broadcast = false, bool createdByPlayer = false);
327
328 void LootMoney();
329 LootItem const* GetItemInSlot(uint32 lootListId) const;
330 LootItem* LootItemInSlot(uint32 lootListId, Player const* player, NotNormalLootItem** ffaItem = nullptr);
331 bool hasItemForAll() const;
332 bool hasItemFor(Player const* player) const;
333 bool hasOverThresholdItem() const;
334
335 // Builds data for SMSG_LOOT_RESPONSE
336 void BuildLootResponse(WorldPackets::Loot::LootResponse& packet, Player const* viewer) const;
337
338 void Update();
339
340private:
343
344 // Loot GUID
346 ObjectGuid _owner; // The WorldObject that holds this loot
349 std::unordered_map<uint32, LootRoll> _rolls; // used if an item is under rolling
352 bool _wasOpened; // true if at least one player received the loot content
355};
356
358{
359public:
361 {
366 };
367
368 typedef std::vector<ResultValue> OrderedStorage;
369
370 void Add(Item* item, uint8 count, LootType lootType, uint32 dungeonEncounterId);
371
372 OrderedStorage::const_iterator begin() const;
373 OrderedStorage::const_iterator end() const;
374
376 std::unordered_map<Item*, OrderedStorage::size_type> _byItem;
377};
378
379#endif // Loot_h__
ItemContext
Definition: DBCEnums.h:1063
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition: Duration.h:41
std::chrono::minutes Minutes
Minutes shorthand typedef.
Definition: Duration.h:35
uint32 ItemRandomBonusListId
LootType
Definition: Loot.h:98
@ LOOT_PICKPOCKETING
Definition: Loot.h:102
@ LOOT_MILLING
Definition: Loot.h:115
@ LOOT_FISHING_JUNK
Definition: Loot.h:113
@ LOOT_CHEST
Definition: Loot.h:108
@ LOOT_CORPSE
Definition: Loot.h:101
@ LOOT_FISHING
Definition: Loot.h:103
@ LOOT_GATHERING_NODE
Definition: Loot.h:107
@ LOOT_INSIGNIA
Definition: Loot.h:112
@ LOOT_DISENCHANTING
Definition: Loot.h:104
@ LOOT_CORPSE_PERSONAL
Definition: Loot.h:109
@ LOOT_SKINNING
Definition: Loot.h:106
@ LOOT_FISHINGHOLE
Definition: Loot.h:111
@ LOOT_NONE
Definition: Loot.h:99
@ LOOT_ITEM
Definition: Loot.h:105
@ LOOT_PROSPECTING
Definition: Loot.h:114
LootMethod
Definition: Loot.h:88
@ PERSONAL_LOOT
Definition: Loot.h:94
@ NEED_BEFORE_GREED
Definition: Loot.h:93
@ GROUP_LOOT
Definition: Loot.h:92
@ MASTER_LOOT
Definition: Loot.h:91
@ ROUND_ROBIN
Definition: Loot.h:90
@ FREE_FOR_ALL
Definition: Loot.h:89
std::unordered_map< ObjectGuid, std::unique_ptr< NotNormalLootItemList > > NotNormalLootItemMap
Definition: Loot.h:232
RollMask
Definition: Loot.h:74
@ ROLL_FLAG_TYPE_TRANSMOG
Definition: Loot.h:79
@ ROLL_ALL_TYPE_NO_DISENCHANT
Definition: Loot.h:81
@ ROLL_FLAG_TYPE_DISENCHANT
Definition: Loot.h:78
@ ROLL_ALL_TYPE_MASK
Definition: Loot.h:82
@ ROLL_FLAG_TYPE_GREED
Definition: Loot.h:77
@ ROLL_FLAG_TYPE_PASS
Definition: Loot.h:75
@ ROLL_FLAG_TYPE_NEED
Definition: Loot.h:76
LootRollIneligibilityReason
Definition: Loot.h:165
std::vector< LootItem > LootItemList
Definition: Loot.h:231
constexpr LootType GetLootTypeForClient(LootType lootType)
Definition: Loot.h:118
RollType
Definition: Loot.h:54
@ ROLL_TRANSMOG
Definition: Loot.h:59
@ MAX_ROLL_TYPE
Definition: Loot.h:60
@ ROLL_PASS
Definition: Loot.h:55
@ ROLL_GREED
Definition: Loot.h:57
@ ROLL_NEED
Definition: Loot.h:56
@ ROLL_DISENCHANT
Definition: Loot.h:58
LootSlotType
Definition: Loot.h:156
@ LOOT_SLOT_TYPE_MASTER
Definition: Loot.h:159
@ LOOT_SLOT_TYPE_ROLL_ONGOING
Definition: Loot.h:158
@ LOOT_SLOT_TYPE_ALLOW_LOOT
Definition: Loot.h:157
@ LOOT_SLOT_TYPE_OWNER
Definition: Loot.h:161
@ LOOT_SLOT_TYPE_LOCKED
Definition: Loot.h:160
std::vector< NotNormalLootItem > NotNormalLootItemList
Definition: Loot.h:230
LootError
Definition: Loot.h:137
@ LOOT_ERROR_TOO_FAR
Definition: Loot.h:139
@ LOOT_ERROR_NO_LOOT
Definition: Loot.h:151
@ LOOT_ERROR_MASTER_OTHER
Definition: Loot.h:148
@ LOOT_ERROR_BAD_FACING
Definition: Loot.h:140
@ LOOT_ERROR_LOCKED
Definition: Loot.h:141
@ LOOT_ERROR_MASTER_INV_FULL
Definition: Loot.h:146
@ LOOT_ERROR_MASTER_UNIQUE_ITEM
Definition: Loot.h:147
@ LOOT_ERROR_DIDNT_KILL
Definition: Loot.h:138
@ LOOT_ERROR_PLAY_TIME_EXCEEDED
Definition: Loot.h:145
@ LOOT_ERROR_NOTSTANDING
Definition: Loot.h:142
@ LOOT_ERROR_NOT_WHILE_SHAPESHIFTED
Definition: Loot.h:150
@ LOOT_ERROR_PLAYER_NOT_FOUND
Definition: Loot.h:144
@ LOOT_ERROR_ALREADY_PICKPOCKETED
Definition: Loot.h:149
@ LOOT_ERROR_STUNNED
Definition: Loot.h:143
RollVote
Definition: Loot.h:64
constexpr Minutes LOOT_ROLL_TIMEOUT
Definition: Loot.h:33
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:393
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
@ LOOT_MODE_DEFAULT
Definition: SharedDefines.h:77
OrderedStorage _byOrder
Definition: Loot.h:375
std::unordered_map< Item *, OrderedStorage::size_type > _byItem
Definition: Loot.h:376
std::vector< ResultValue > OrderedStorage
Definition: Loot.h:368
Definition: Group.h:197
Definition: Item.h:170
Definition: Loot.h:244
bool PlayerVote(Player *player, RollVote vote)
Definition: Loot.cpp:455
bool UpdateRoll()
Definition: Loot.cpp:499
LootRoll & operator=(LootRoll &&)=delete
TimePoint m_endTime
Definition: Loot.h:277
void Finish(RollVoteMap::const_iterator winnerItr)
Definition: Loot.cpp:576
bool AllPlayerVoted(RollVoteMap::const_iterator &winnerItr)
Check if all player have voted and return true in that case. Also return current winner.
Definition: Loot.cpp:521
bool TryToStart(Map *map, Loot &loot, uint32 lootListId, uint16 enchantingSkill)
Definition: Loot.cpp:399
bool m_isStarted
Definition: Loot.h:273
ItemDisenchantLootEntry const * GetItemDisenchantLoot() const
Definition: Loot.cpp:560
LootItem * m_lootItem
Definition: Loot.h:274
void SendStartRoll()
Definition: Loot.cpp:215
Loot * m_loot
Definition: Loot.h:275
bool IsLootItem(ObjectGuid const &lootObject, uint32 lootListId) const
Definition: Loot.cpp:511
RollVoteMap m_rollVoteMap
Definition: Loot.h:272
LootRoll()
Definition: Loot.h:248
~LootRoll()
Definition: Loot.cpp:379
RollMask m_voteMask
Definition: Loot.h:276
LootRoll(LootRoll &&)=delete
void SendLootRollWon(ObjectGuid const &targetGuid, int32 rollNumber, RollVote rollType)
Definition: Loot.cpp:318
Map * m_map
Definition: Loot.h:271
std::unordered_map< ObjectGuid, PlayerRollVote > RollVoteMap
Definition: Loot.h:246
void SendAllPassed()
Definition: Loot.cpp:255
LootRoll & operator=(LootRoll const &)=delete
void SendRoll(ObjectGuid const &targetGuid, int32 rollNumber, RollVote rollType, Optional< ObjectGuid > const &rollWinner)
Definition: Loot.cpp:278
void FillPacket(WorldPackets::Loot::LootItemData &lootItem) const
Definition: Loot.cpp:371
LootRoll(LootRoll const &)=delete
Definition: Map.h:189
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:90
uint32 dungeonEncounterId
Definition: Loot.h:365
Definition: Loot.h:176
std::vector< int32 > BonusListIDs
Definition: Loot.h:180
uint32 itemid
Definition: Loot.h:177
bool is_blocked
Definition: Loot.h:187
ObjectGuid rollWinnerGUID
Definition: Loot.h:184
bool needs_quest
Definition: Loot.h:191
bool follow_loot_rules
Definition: Loot.h:192
bool is_underthreshold
Definition: Loot.h:189
GuidSet allowedGUIDs
Definition: Loot.h:183
uint32 LootListId
Definition: Loot.h:178
uint8 count
Definition: Loot.h:185
bool is_looted
Definition: Loot.h:186
ItemRandomBonusListId randomBonusListId
Definition: Loot.h:179
ItemContext context
Definition: Loot.h:181
LootItem()
Definition: Loot.h:199
ConditionsReference conditions
Definition: Loot.h:182
bool freeforall
Definition: Loot.h:188
bool is_counted
Definition: Loot.h:190
LootItem(LootItem const &)
LootItem(LootItem &&) noexcept
Definition: Loot.h:281
Loot & operator=(Loot &&)=delete
ItemContext GetItemContext() const
Definition: Loot.h:300
bool _wasOpened
Definition: Loot.h:352
void AddLooter(ObjectGuid GUID)
Definition: Loot.h:314
ItemContext _itemContext
Definition: Loot.h:347
GuidUnorderedSet _allowedLooters
Definition: Loot.h:351
bool isLooted() const
Definition: Loot.h:307
NotNormalLootItemMap PlayerFFAItems
Definition: Loot.h:342
void SetItemContext(ItemContext context)
Definition: Loot.h:301
bool _changed
Definition: Loot.h:353
uint32 _dungeonEncounterId
Definition: Loot.h:354
LootMethod _lootMethod
Definition: Loot.h:348
uint8 unlootedCount
Definition: Loot.h:286
ObjectGuid roundRobinPlayer
Definition: Loot.h:287
ObjectGuid const & GetOwnerGUID() const
Definition: Loot.h:299
GuidSet PlayersLooting
Definition: Loot.h:341
Loot(Loot &&)=delete
uint32 gold
Definition: Loot.h:285
bool IsChanged() const
Definition: Loot.h:308
Loot & operator=(Loot const &)=delete
ObjectGuid const & GetGUID() const
Definition: Loot.h:298
void SetDungeonEncounterId(uint32 dungeonEncounterId)
Definition: Loot.h:305
std::vector< LootItem > items
Definition: Loot.h:284
void RemoveLooter(ObjectGuid GUID)
Definition: Loot.h:315
std::unordered_map< uint32, LootRoll > _rolls
Definition: Loot.h:349
ObjectGuid _owner
Definition: Loot.h:346
ObjectGuid _lootMaster
Definition: Loot.h:350
NotNormalLootItemMap const & GetPlayerFFAItems() const
Definition: Loot.h:282
ObjectGuid _guid
Definition: Loot.h:345
uint32 GetDungeonEncounterId() const
Definition: Loot.h:304
Loot(Loot const &)=delete
ObjectGuid const & GetLootMasterGUID() const
Definition: Loot.h:303
LootMethod GetLootMethod() const
Definition: Loot.h:302
LootType loot_type
Definition: Loot.h:288
NotNormalLootItem()
Definition: Loot.h:223
NotNormalLootItem(uint8 _index, bool _islooted=false)
Definition: Loot.h:226
uint8 LootListId
Definition: Loot.h:220
bool is_looted
Definition: Loot.h:221
uint8 RollNumber
Definition: Loot.h:240
RollVote Vote
Definition: Loot.h:239
PlayerRollVote()
Definition: Loot.h:238