1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef TRINITYCORE_GROUP_H |
---|
22 | #define TRINITYCORE_GROUP_H |
---|
23 | |
---|
24 | #include "GroupReference.h" |
---|
25 | #include "GroupRefManager.h" |
---|
26 | #include "LootMgr.h" |
---|
27 | |
---|
28 | #include <map> |
---|
29 | #include <vector> |
---|
30 | |
---|
31 | #define MAXGROUPSIZE 5 |
---|
32 | #define MAXRAIDSIZE 40 |
---|
33 | #define TARGETICONCOUNT 8 |
---|
34 | |
---|
35 | enum RollVote |
---|
36 | { |
---|
37 | PASS = 0, |
---|
38 | NEED = 1, |
---|
39 | GREED = 2, |
---|
40 | NOT_EMITED_YET = 3, |
---|
41 | NOT_VALID = 4 |
---|
42 | }; |
---|
43 | |
---|
44 | enum GroupMemberOnlineStatus |
---|
45 | { |
---|
46 | MEMBER_STATUS_OFFLINE = 0x0000, |
---|
47 | MEMBER_STATUS_ONLINE = 0x0001, |
---|
48 | MEMBER_STATUS_PVP = 0x0002, |
---|
49 | MEMBER_STATUS_UNK0 = 0x0004, // dead? (health=0) |
---|
50 | MEMBER_STATUS_UNK1 = 0x0008, // ghost? (health=1) |
---|
51 | MEMBER_STATUS_UNK2 = 0x0010, // never seen |
---|
52 | MEMBER_STATUS_UNK3 = 0x0020, // never seen |
---|
53 | MEMBER_STATUS_UNK4 = 0x0040, // appears with dead and ghost flags |
---|
54 | MEMBER_STATUS_UNK5 = 0x0080, // never seen |
---|
55 | }; |
---|
56 | |
---|
57 | enum GroupType |
---|
58 | { |
---|
59 | GROUPTYPE_NORMAL = 0, |
---|
60 | GROUPTYPE_RAID = 1 |
---|
61 | }; |
---|
62 | |
---|
63 | class BattleGround; |
---|
64 | |
---|
65 | enum GroupUpdateFlags |
---|
66 | { |
---|
67 | GROUP_UPDATE_FLAG_NONE = 0x00000000, // nothing |
---|
68 | GROUP_UPDATE_FLAG_STATUS = 0x00000001, // uint16, flags |
---|
69 | GROUP_UPDATE_FLAG_CUR_HP = 0x00000002, // uint16 |
---|
70 | GROUP_UPDATE_FLAG_MAX_HP = 0x00000004, // uint16 |
---|
71 | GROUP_UPDATE_FLAG_POWER_TYPE = 0x00000008, // uint8 |
---|
72 | GROUP_UPDATE_FLAG_CUR_POWER = 0x00000010, // uint16 |
---|
73 | GROUP_UPDATE_FLAG_MAX_POWER = 0x00000020, // uint16 |
---|
74 | GROUP_UPDATE_FLAG_LEVEL = 0x00000040, // uint16 |
---|
75 | GROUP_UPDATE_FLAG_ZONE = 0x00000080, // uint16 |
---|
76 | GROUP_UPDATE_FLAG_POSITION = 0x00000100, // uint16, uint16 |
---|
77 | GROUP_UPDATE_FLAG_AURAS = 0x00000200, // uint64 mask, for each bit set uint16 spellid + uint8 unk |
---|
78 | GROUP_UPDATE_FLAG_PET_GUID = 0x00000400, // uint64 pet guid |
---|
79 | GROUP_UPDATE_FLAG_PET_NAME = 0x00000800, // pet name, NULL terminated string |
---|
80 | GROUP_UPDATE_FLAG_PET_MODEL_ID = 0x00001000, // uint16, model id |
---|
81 | GROUP_UPDATE_FLAG_PET_CUR_HP = 0x00002000, // uint16 pet cur health |
---|
82 | GROUP_UPDATE_FLAG_PET_MAX_HP = 0x00004000, // uint16 pet max health |
---|
83 | GROUP_UPDATE_FLAG_PET_POWER_TYPE = 0x00008000, // uint8 pet power type |
---|
84 | GROUP_UPDATE_FLAG_PET_CUR_POWER = 0x00010000, // uint16 pet cur power |
---|
85 | GROUP_UPDATE_FLAG_PET_MAX_POWER = 0x00020000, // uint16 pet max power |
---|
86 | GROUP_UPDATE_FLAG_PET_AURAS = 0x00040000, // uint64 mask, for each bit set uint16 spellid + uint8 unk, pet auras... |
---|
87 | GROUP_UPDATE_PET = 0x0007FC00, // all pet flags |
---|
88 | GROUP_UPDATE_FULL = 0x0007FFFF, // all known flags |
---|
89 | }; |
---|
90 | |
---|
91 | #define GROUP_UPDATE_FLAGS_COUNT 20 |
---|
92 | // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19 |
---|
93 | static const uint8 GroupUpdateLength[GROUP_UPDATE_FLAGS_COUNT] = { 0, 2, 2, 2, 1, 2, 2, 2, 2, 4, 8, 8, 1, 2, 2, 2, 1, 2, 2, 8}; |
---|
94 | |
---|
95 | class InstanceSave; |
---|
96 | |
---|
97 | class Roll : public LootValidatorRef |
---|
98 | { |
---|
99 | public: |
---|
100 | Roll(uint64 _guid, LootItem const& li) |
---|
101 | : itemGUID(_guid), itemid(li.itemid), itemRandomPropId(li.randomPropertyId), itemRandomSuffix(li.randomSuffix), |
---|
102 | totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {} |
---|
103 | ~Roll() { } |
---|
104 | void setLoot(Loot *pLoot) { link(pLoot, this); } |
---|
105 | Loot *getLoot() { return getTarget(); } |
---|
106 | void targetObjectBuildLink(); |
---|
107 | |
---|
108 | uint64 itemGUID; |
---|
109 | uint32 itemid; |
---|
110 | int32 itemRandomPropId; |
---|
111 | uint32 itemRandomSuffix; |
---|
112 | typedef std::map<uint64, RollVote> PlayerVote; |
---|
113 | PlayerVote playerVote; //vote position correspond with player position (in group) |
---|
114 | uint8 totalPlayersRolling; |
---|
115 | uint8 totalNeed; |
---|
116 | uint8 totalGreed; |
---|
117 | uint8 totalPass; |
---|
118 | uint8 itemSlot; |
---|
119 | }; |
---|
120 | |
---|
121 | struct InstanceGroupBind |
---|
122 | { |
---|
123 | InstanceSave *save; |
---|
124 | bool perm; |
---|
125 | /* permanent InstanceGroupBinds exist iff the leader has a permanent |
---|
126 | PlayerInstanceBind for the same instance. */ |
---|
127 | InstanceGroupBind() : save(NULL), perm(false) {} |
---|
128 | }; |
---|
129 | |
---|
130 | /** request member stats checken **/ |
---|
131 | /** todo: uninvite people that not accepted invite **/ |
---|
132 | class TRINITY_DLL_SPEC Group |
---|
133 | { |
---|
134 | public: |
---|
135 | struct MemberSlot |
---|
136 | { |
---|
137 | uint64 guid; |
---|
138 | std::string name; |
---|
139 | uint8 group; |
---|
140 | bool assistant; |
---|
141 | }; |
---|
142 | typedef std::list<MemberSlot> MemberSlotList; |
---|
143 | typedef MemberSlotList::const_iterator member_citerator; |
---|
144 | |
---|
145 | typedef HM_NAMESPACE::hash_map< uint32 /*mapId*/, InstanceGroupBind> BoundInstancesMap; |
---|
146 | protected: |
---|
147 | typedef MemberSlotList::iterator member_witerator; |
---|
148 | typedef std::set<uint64> InvitesList; |
---|
149 | |
---|
150 | typedef std::vector<Roll*> Rolls; |
---|
151 | |
---|
152 | public: |
---|
153 | Group(); |
---|
154 | ~Group(); |
---|
155 | |
---|
156 | // group manipulation methods |
---|
157 | bool Create(const uint64 &guid, const char * name); |
---|
158 | bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result = NULL, bool loadMembers = true); |
---|
159 | bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant); |
---|
160 | bool AddInvite(Player *player); |
---|
161 | uint32 RemoveInvite(Player *player); |
---|
162 | void RemoveAllInvites(); |
---|
163 | bool AddLeaderInvite(Player *player); |
---|
164 | bool AddMember(const uint64 &guid, const char* name); |
---|
165 | // method: 0=just remove, 1=kick |
---|
166 | uint32 RemoveMember(const uint64 &guid, const uint8 &method); |
---|
167 | void ChangeLeader(const uint64 &guid); |
---|
168 | void SetLootMethod(LootMethod method) { m_lootMethod = method; } |
---|
169 | void SetLooterGuid(const uint64 &guid) { m_looterGuid = guid; } |
---|
170 | void UpdateLooterGuid( Creature* creature, bool ifneed = false ); |
---|
171 | void SetLootThreshold(ItemQualities threshold) { m_lootThreshold = threshold; } |
---|
172 | void Disband(bool hideDestroy=false); |
---|
173 | |
---|
174 | // properties accessories |
---|
175 | bool IsFull() const { return (m_groupType==GROUPTYPE_NORMAL) ? (m_memberSlots.size()>=MAXGROUPSIZE) : (m_memberSlots.size()>=MAXRAIDSIZE); } |
---|
176 | bool isRaidGroup() const { return m_groupType==GROUPTYPE_RAID; } |
---|
177 | bool isBGGroup() const { return m_bgGroup != NULL; } |
---|
178 | bool IsCreated() const { return GetMembersCount() > 0; } |
---|
179 | const uint64& GetLeaderGUID() const { return m_leaderGuid; } |
---|
180 | const char * GetLeaderName() const { return m_leaderName.c_str(); } |
---|
181 | LootMethod GetLootMethod() const { return m_lootMethod; } |
---|
182 | const uint64& GetLooterGuid() const { return m_looterGuid; } |
---|
183 | ItemQualities GetLootThreshold() const { return m_lootThreshold; } |
---|
184 | |
---|
185 | // member manipulation methods |
---|
186 | bool IsMember(const uint64& guid) const { return _getMemberCSlot(guid) != m_memberSlots.end(); } |
---|
187 | bool IsLeader(const uint64& guid) const { return (GetLeaderGUID() == guid); } |
---|
188 | bool IsAssistant(uint64 guid) const |
---|
189 | { |
---|
190 | member_citerator mslot = _getMemberCSlot(guid); |
---|
191 | if(mslot==m_memberSlots.end()) |
---|
192 | return false; |
---|
193 | |
---|
194 | return mslot->assistant; |
---|
195 | } |
---|
196 | |
---|
197 | bool SameSubGroup(uint64 guid1,const uint64& guid2) const |
---|
198 | { |
---|
199 | member_citerator mslot2 = _getMemberCSlot(guid2); |
---|
200 | if(mslot2==m_memberSlots.end()) |
---|
201 | return false; |
---|
202 | |
---|
203 | return SameSubGroup(guid1,&*mslot2); |
---|
204 | } |
---|
205 | |
---|
206 | bool SameSubGroup(uint64 guid1, MemberSlot const* slot2) const |
---|
207 | { |
---|
208 | member_citerator mslot1 = _getMemberCSlot(guid1); |
---|
209 | if(mslot1==m_memberSlots.end() || !slot2) |
---|
210 | return false; |
---|
211 | |
---|
212 | return (mslot1->group==slot2->group); |
---|
213 | } |
---|
214 | |
---|
215 | bool HasFreeSlotSubGroup(uint8 subgroup) const |
---|
216 | { |
---|
217 | return (m_subGroupsCounts && m_subGroupsCounts[subgroup] < MAXGROUPSIZE); |
---|
218 | } |
---|
219 | |
---|
220 | bool SameSubGroup(Player const* member1, Player const* member2) const; |
---|
221 | |
---|
222 | MemberSlotList const& GetMemberSlots() const { return m_memberSlots; } |
---|
223 | GroupReference* GetFirstMember() { return m_memberMgr.getFirst(); } |
---|
224 | uint32 GetMembersCount() const { return m_memberSlots.size(); } |
---|
225 | void GetDataForXPAtKill(Unit const* victim, uint32& count,uint32& sum_level, Player* & member_with_max_level, Player* & not_gray_member_with_max_level); |
---|
226 | uint8 GetMemberGroup(uint64 guid) const |
---|
227 | { |
---|
228 | member_citerator mslot = _getMemberCSlot(guid); |
---|
229 | if(mslot==m_memberSlots.end()) |
---|
230 | return (MAXRAIDSIZE/MAXGROUPSIZE+1); |
---|
231 | |
---|
232 | return mslot->group; |
---|
233 | } |
---|
234 | |
---|
235 | // some additional raid methods |
---|
236 | void ConvertToRaid(); |
---|
237 | |
---|
238 | void SetBattlegroundGroup(BattleGround *bg) { m_bgGroup = bg; } |
---|
239 | uint32 CanJoinBattleGroundQueue(uint32 bgTypeId, uint32 bgQueueType, uint32 MinPlayerCount, uint32 MaxPlayerCount, bool isRated, uint32 arenaSlot); |
---|
240 | |
---|
241 | void ChangeMembersGroup(const uint64 &guid, const uint8 &group); |
---|
242 | void ChangeMembersGroup(Player *player, const uint8 &group); |
---|
243 | |
---|
244 | void SetAssistant(uint64 guid, const bool &state) |
---|
245 | { |
---|
246 | if(!isRaidGroup()) |
---|
247 | return; |
---|
248 | if(_setAssistantFlag(guid, state)) |
---|
249 | SendUpdate(); |
---|
250 | } |
---|
251 | void SetMainTank(uint64 guid) |
---|
252 | { |
---|
253 | if(!isRaidGroup()) |
---|
254 | return; |
---|
255 | |
---|
256 | if(_setMainTank(guid)) |
---|
257 | SendUpdate(); |
---|
258 | } |
---|
259 | void SetMainAssistant(uint64 guid) |
---|
260 | { |
---|
261 | if(!isRaidGroup()) |
---|
262 | return; |
---|
263 | |
---|
264 | if(_setMainAssistant(guid)) |
---|
265 | SendUpdate(); |
---|
266 | } |
---|
267 | |
---|
268 | void SetTargetIcon(uint8 id, uint64 guid); |
---|
269 | void SetDifficulty(uint8 difficulty); |
---|
270 | uint8 GetDifficulty() { return m_difficulty; } |
---|
271 | uint16 InInstance(); |
---|
272 | bool InCombatToInstance(uint32 instanceId); |
---|
273 | void ResetInstances(uint8 method, Player* SendMsgTo); |
---|
274 | |
---|
275 | // -no description- |
---|
276 | //void SendInit(WorldSession *session); |
---|
277 | void SendTargetIconList(WorldSession *session); |
---|
278 | void SendUpdate(); |
---|
279 | void UpdatePlayerOutOfRange(Player* pPlayer); |
---|
280 | // ignore: GUID of player that will be ignored |
---|
281 | void BroadcastPacket(WorldPacket *packet, int group=-1, uint64 ignore=0); |
---|
282 | void BroadcastReadyCheck(WorldPacket *packet); |
---|
283 | void OfflineReadyCheck(); |
---|
284 | |
---|
285 | /*********************************************************/ |
---|
286 | /*** LOOT SYSTEM ***/ |
---|
287 | /*********************************************************/ |
---|
288 | |
---|
289 | void SendLootStartRoll(uint32 CountDown, const Roll &r); |
---|
290 | void SendLootRoll(const uint64& SourceGuid, const uint64& TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
---|
291 | void SendLootRollWon(const uint64& SourceGuid, const uint64& TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
---|
292 | void SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r); |
---|
293 | void GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature); |
---|
294 | void NeedBeforeGreed(const uint64& playerGUID, Loot *loot, Creature *creature); |
---|
295 | void MasterLoot(const uint64& playerGUID, Loot *loot, Creature *creature); |
---|
296 | Rolls::iterator GetRoll(uint64 Guid) |
---|
297 | { |
---|
298 | Rolls::iterator iter; |
---|
299 | for (iter=RollId.begin(); iter != RollId.end(); ++iter) |
---|
300 | { |
---|
301 | if ((*iter)->itemGUID == Guid && (*iter)->isValid()) |
---|
302 | { |
---|
303 | return iter; |
---|
304 | } |
---|
305 | } |
---|
306 | return RollId.end(); |
---|
307 | } |
---|
308 | void CountTheRoll(Rolls::iterator roll, uint32 NumberOfPlayers); |
---|
309 | void CountRollVote(const uint64& playerGUID, const uint64& Guid, uint32 NumberOfPlayers, uint8 Choise); |
---|
310 | void EndRoll(); |
---|
311 | |
---|
312 | void LinkMember(GroupReference *pRef) { m_memberMgr.insertFirst(pRef); } |
---|
313 | void DelinkMember(GroupReference* /*pRef*/ ) { } |
---|
314 | |
---|
315 | InstanceGroupBind* BindToInstance(InstanceSave *save, bool permanent, bool load = false); |
---|
316 | void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false); |
---|
317 | InstanceGroupBind* GetBoundInstance(uint32 mapid, uint8 difficulty); |
---|
318 | BoundInstancesMap& GetBoundInstances(uint8 difficulty) { return m_boundInstances[difficulty]; } |
---|
319 | |
---|
320 | protected: |
---|
321 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant=false); |
---|
322 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant, uint8 group); |
---|
323 | bool _removeMember(const uint64 &guid); // returns true if leader has changed |
---|
324 | void _setLeader(const uint64 &guid); |
---|
325 | |
---|
326 | void _removeRolls(const uint64 &guid); |
---|
327 | |
---|
328 | bool _setMembersGroup(const uint64 &guid, const uint8 &group); |
---|
329 | bool _setAssistantFlag(const uint64 &guid, const bool &state); |
---|
330 | bool _setMainTank(const uint64 &guid); |
---|
331 | bool _setMainAssistant(const uint64 &guid); |
---|
332 | |
---|
333 | void _homebindIfInstance(Player *player); |
---|
334 | |
---|
335 | void _initRaidSubGroupsCounter() |
---|
336 | { |
---|
337 | // Sub group counters initialization |
---|
338 | if (!m_subGroupsCounts) |
---|
339 | m_subGroupsCounts = new uint8[MAXRAIDSIZE / MAXGROUPSIZE]; |
---|
340 | |
---|
341 | memset((void*)m_subGroupsCounts, 0, (MAXRAIDSIZE / MAXGROUPSIZE)*sizeof(uint8)); |
---|
342 | |
---|
343 | for (member_citerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
---|
344 | ++m_subGroupsCounts[itr->group]; |
---|
345 | } |
---|
346 | |
---|
347 | member_citerator _getMemberCSlot(uint64 Guid) const |
---|
348 | { |
---|
349 | for(member_citerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
---|
350 | { |
---|
351 | if (itr->guid == Guid) |
---|
352 | return itr; |
---|
353 | } |
---|
354 | return m_memberSlots.end(); |
---|
355 | } |
---|
356 | |
---|
357 | member_witerator _getMemberWSlot(uint64 Guid) |
---|
358 | { |
---|
359 | for(member_witerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
---|
360 | { |
---|
361 | if (itr->guid == Guid) |
---|
362 | return itr; |
---|
363 | } |
---|
364 | return m_memberSlots.end(); |
---|
365 | } |
---|
366 | |
---|
367 | void SubGroupCounterIncrease(uint8 subgroup) |
---|
368 | { |
---|
369 | if (m_subGroupsCounts) |
---|
370 | ++m_subGroupsCounts[subgroup]; |
---|
371 | } |
---|
372 | |
---|
373 | void SubGroupCounterDecrease(uint8 subgroup) |
---|
374 | { |
---|
375 | if (m_subGroupsCounts) |
---|
376 | --m_subGroupsCounts[subgroup]; |
---|
377 | } |
---|
378 | |
---|
379 | MemberSlotList m_memberSlots; |
---|
380 | GroupRefManager m_memberMgr; |
---|
381 | InvitesList m_invitees; |
---|
382 | uint64 m_leaderGuid; |
---|
383 | std::string m_leaderName; |
---|
384 | uint64 m_mainTank; |
---|
385 | uint64 m_mainAssistant; |
---|
386 | GroupType m_groupType; |
---|
387 | uint8 m_difficulty; |
---|
388 | BattleGround* m_bgGroup; |
---|
389 | uint64 m_targetIcons[TARGETICONCOUNT]; |
---|
390 | LootMethod m_lootMethod; |
---|
391 | ItemQualities m_lootThreshold; |
---|
392 | uint64 m_looterGuid; |
---|
393 | Rolls RollId; |
---|
394 | BoundInstancesMap m_boundInstances[TOTAL_DIFFICULTIES]; |
---|
395 | uint8* m_subGroupsCounts; |
---|
396 | }; |
---|
397 | #endif |
---|