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