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
25 #include "Policies/Singleton.h"
26 #include "ItemPrototype.h"
27 #include "ByteBuffer.h"
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
65 int32 questChanceOrGroup
;
67 bool is_ffa
; // free for all
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; }
85 bool is_ffa
; // free for all
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
; }
102 uint8 index
; // position in quest_items;
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
;
119 std::set
<Player
*> PlayersLooting
;
120 QuestItemMap PlayerQuestItems
;
121 std::vector
<LootItem
> items
;
122 std::vector
<LootItem
> quest_items
;
127 Loot(uint32 _gold
= 0) : gold(_gold
), unlootedCount(0), released(false) {}
132 items
.clear(); gold
= 0; PlayersLooting
.clear();
133 for (QuestItemMap::iterator itr
= PlayerQuestItems
.begin(); itr
!= PlayerQuestItems
.end(); ++itr
)
135 PlayerQuestItems
.clear();
139 bool empty() const { return items
.empty() && gold
== 0; }
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
); }
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
);