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