[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / LootMgr.h
blob21dca5e47a3766a9befe76de531c14ff38848a6d
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_LOOTMGR_H
20 #define MANGOS_LOOTMGR_H
22 #include <list>
23 #include <vector>
24 #include "Common.h"
25 #include "Policies/Singleton.h"
26 #include "ItemPrototype.h"
27 #include "ByteBuffer.h"
28 #include "Util.h"
30 #define ROLL_PASS 0
31 #define ROLL_NEED 1
32 #define ROLL_GREED 2
34 #define MAX_NR_LOOT_ITEMS 16
35 // note: the client cannot show more than 16 items total
36 #define MAX_NR_QUEST_ITEMS 32
37 // unrelated to the number of quest items shown, just for reserve
39 enum LootMethod
41 FREE_FOR_ALL = 0,
42 ROUND_ROBIN = 1,
43 MASTER_LOOT = 2,
44 GROUP_LOOT = 3,
45 NEED_BEFORE_GREED = 4
48 enum PermissionTypes
50 ALL_PERMISSION =0,
51 GROUP_PERMISSION =1,
52 NONE_PERMISSION =3
55 using std::vector;
56 using std::list;
58 class Player;
60 struct LootStoreItem
62 uint32 itemid;
63 uint32 displayid;
64 float chance;
65 int32 questChanceOrGroup;
66 uint8 maxcount;
67 bool is_ffa; // free for all
69 LootStoreItem()
70 : itemid(0), displayid(0), chance(0), questChanceOrGroup(0), maxcount(1), is_ffa(true) {}
72 LootStoreItem(uint32 _itemid, uint32 _displayid, float _chance, int32 _questChanceOrGroup, bool _isffa = true, uint8 _maxcount = 1)
73 : itemid(_itemid), displayid(_displayid), chance(_chance), questChanceOrGroup(_questChanceOrGroup), maxcount(_maxcount), is_ffa(_isffa) {}
75 int32 GetGroupId() const { return -questChanceOrGroup -1; }
78 struct LootItem
80 uint32 itemid;
81 uint32 displayid;
82 uint8 count;
83 bool is_looted;
84 bool is_blocked;
85 bool is_ffa; // free for all
87 LootItem()
88 : itemid(0), displayid(0), count(1), is_looted(true), is_blocked(false), is_ffa(true) {}
90 LootItem(uint32 _itemid, uint32 _displayid, bool _isffa, uint8 _count = 1)
91 : itemid(_itemid), displayid(_displayid), count(_count), is_looted(false), is_blocked(false), is_ffa(_isffa) {}
93 LootItem(LootStoreItem const& li,uint8 _count)
94 : itemid(li.itemid), displayid(li.displayid), count(_count), is_looted(false), is_blocked(false), is_ffa(li.is_ffa) {}
96 static bool looted(LootItem &itm) { return itm.is_looted; }
97 static bool not_looted(LootItem &itm) { return !itm.is_looted; }
100 struct QuestItem
102 uint8 index; // position in quest_items;
103 bool is_looted;
105 QuestItem()
106 : index(0), is_looted(false) {}
108 QuestItem(uint8 _index, bool _islooted = false)
109 : index(_index), is_looted(_islooted) {}
112 typedef std::vector<QuestItem> QuestItemList;
113 typedef std::map<Player *, QuestItemList *> QuestItemMap;
114 typedef vector<LootStoreItem> LootStoreItemList;
115 typedef HM_NAMESPACE::hash_map<uint32, LootStoreItemList > LootStore;
117 struct Loot
119 std::set<Player*> PlayersLooting;
120 QuestItemMap PlayerQuestItems;
121 std::vector<LootItem> items;
122 std::vector<LootItem> quest_items;
123 uint32 gold;
124 uint8 unlootedCount;
125 bool released;
127 Loot(uint32 _gold = 0) : gold(_gold), unlootedCount(0), released(false) {}
128 ~Loot() { clear(); }
130 void clear()
132 items.clear(); gold = 0; PlayersLooting.clear();
133 for (QuestItemMap::iterator itr = PlayerQuestItems.begin(); itr != PlayerQuestItems.end(); ++itr)
134 delete itr->second;
135 PlayerQuestItems.clear();
136 quest_items.clear();
139 bool empty() const { return items.empty() && gold == 0; }
140 bool isLooted();
141 void NotifyItemRemoved(uint8 lootIndex);
142 void NotifyQuestItemRemoved(uint8 questIndex);
143 void NotifyMoneyRemoved();
144 void AddLooter(Player *player) { PlayersLooting.insert(player); }
145 void RemoveLooter(Player *player) { PlayersLooting.erase(player); }
148 struct LootView
150 Loot &loot;
151 QuestItemList *qlist;
152 PermissionTypes permission;
153 LootView(Loot &_loot, QuestItemList *_qlist, PermissionTypes _permission = ALL_PERMISSION)
154 : loot(_loot), qlist(_qlist), permission(_permission) {}
157 extern LootStore LootTemplates_Creature;
158 extern LootStore LootTemplates_Fishing;
159 extern LootStore LootTemplates_Gameobject;
160 extern LootStore LootTemplates_Item;
161 extern LootStore LootTemplates_Pickpocketing;
162 extern LootStore LootTemplates_Skinning;
164 QuestItemList* FillQuestLoot(Player* player, Loot *loot);
165 void FillLoot(Player* player,Loot *loot, uint32 loot_id, LootStore& store);
166 void LoadLootTables();
168 ByteBuffer& operator<<(ByteBuffer& b, LootItem const& li);
169 ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv);
170 #endif