2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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 MANGOSSERVER_GROUP_H
20 #define MANGOSSERVER_GROUP_H
22 #include "GroupReference.h"
23 #include "GroupRefManager.h"
29 #define MAXGROUPSIZE 5
30 #define MAXRAIDSIZE 40
31 #define TARGETICONCOUNT 8
42 enum GroupMemberOnlineStatus
44 MEMBER_STATUS_OFFLINE
= 0x0000,
45 MEMBER_STATUS_ONLINE
= 0x0001,
46 MEMBER_STATUS_PVP
= 0x0002,
47 MEMBER_STATUS_UNK0
= 0x0004, // dead? (health=0)
48 MEMBER_STATUS_UNK1
= 0x0008, // ghost? (health=1)
49 MEMBER_STATUS_UNK2
= 0x0010, // never seen
50 MEMBER_STATUS_UNK3
= 0x0020, // never seen
51 MEMBER_STATUS_UNK4
= 0x0040, // appears with dead and ghost flags
52 MEMBER_STATUS_UNK5
= 0x0080, // never seen
65 GROUP_UPDATE_FLAG_NONE
= 0x00000000, // nothing
66 GROUP_UPDATE_FLAG_STATUS
= 0x00000001, // uint16, flags
67 GROUP_UPDATE_FLAG_CUR_HP
= 0x00000002, // uint32
68 GROUP_UPDATE_FLAG_MAX_HP
= 0x00000004, // uint32
69 GROUP_UPDATE_FLAG_POWER_TYPE
= 0x00000008, // uint8
70 GROUP_UPDATE_FLAG_CUR_POWER
= 0x00000010, // uint16
71 GROUP_UPDATE_FLAG_MAX_POWER
= 0x00000020, // uint16
72 GROUP_UPDATE_FLAG_LEVEL
= 0x00000040, // uint16
73 GROUP_UPDATE_FLAG_ZONE
= 0x00000080, // uint16
74 GROUP_UPDATE_FLAG_POSITION
= 0x00000100, // uint16, uint16
75 GROUP_UPDATE_FLAG_AURAS
= 0x00000200, // uint64 mask, for each bit set uint32 spellid + uint8 unk
76 GROUP_UPDATE_FLAG_PET_GUID
= 0x00000400, // uint64 pet guid
77 GROUP_UPDATE_FLAG_PET_NAME
= 0x00000800, // pet name, NULL terminated string
78 GROUP_UPDATE_FLAG_PET_MODEL_ID
= 0x00001000, // uint16, model id
79 GROUP_UPDATE_FLAG_PET_CUR_HP
= 0x00002000, // uint32 pet cur health
80 GROUP_UPDATE_FLAG_PET_MAX_HP
= 0x00004000, // uint32 pet max health
81 GROUP_UPDATE_FLAG_PET_POWER_TYPE
= 0x00008000, // uint8 pet power type
82 GROUP_UPDATE_FLAG_PET_CUR_POWER
= 0x00010000, // uint16 pet cur power
83 GROUP_UPDATE_FLAG_PET_MAX_POWER
= 0x00020000, // uint16 pet max power
84 GROUP_UPDATE_FLAG_PET_AURAS
= 0x00040000, // uint64 mask, for each bit set uint32 spellid + uint8 unk, pet auras...
85 GROUP_UPDATE_FLAG_VEHICLE_SEAT
= 0x00080000, // uint32 vehicle_seat_id (index from VehicleSeat.dbc)
86 GROUP_UPDATE_PET
= 0x0007FC00, // all pet flags
87 GROUP_UPDATE_FULL
= 0x0007FFFF, // all known flags
90 #define GROUP_UPDATE_FLAGS_COUNT 20
91 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19
92 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};
96 class Roll
: public LootValidatorRef
99 Roll(uint64 _guid
, LootItem
const& li
)
100 : itemGUID(_guid
), itemid(li
.itemid
), itemRandomPropId(li
.randomPropertyId
), itemRandomSuffix(li
.randomSuffix
),
101 totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {}
103 void setLoot(Loot
*pLoot
) { link(pLoot
, this); }
104 Loot
*getLoot() { return getTarget(); }
105 void targetObjectBuildLink();
109 int32 itemRandomPropId
;
110 uint32 itemRandomSuffix
;
111 typedef std::map
<uint64
, RollVote
> PlayerVote
;
112 PlayerVote playerVote
; //vote position correspond with player position (in group)
113 uint8 totalPlayersRolling
;
120 struct InstanceGroupBind
124 /* permanent InstanceGroupBinds exist iff the leader has a permanent
125 PlayerInstanceBind for the same instance. */
126 InstanceGroupBind() : save(NULL
), perm(false) {}
129 /** request member stats checken **/
130 /** todo: uninvite people that not accepted invite **/
131 class MANGOS_DLL_SPEC Group
141 typedef std::list
<MemberSlot
> MemberSlotList
;
142 typedef MemberSlotList::const_iterator member_citerator
;
144 typedef UNORDERED_MAP
< uint32
/*mapId*/, InstanceGroupBind
> BoundInstancesMap
;
146 typedef MemberSlotList::iterator member_witerator
;
147 typedef std::set
<Player
*> InvitesList
;
149 typedef std::vector
<Roll
*> Rolls
;
155 // group manipulation methods
156 bool Create(const uint64
&guid
, const char * name
);
157 bool LoadGroupFromDB(const uint64
&leaderGuid
, QueryResult
*result
= NULL
, bool loadMembers
= true);
158 bool LoadMemberFromDB(uint32 guidLow
, uint8 subgroup
, bool assistant
);
159 bool AddInvite(Player
*player
);
160 uint32
RemoveInvite(Player
*player
);
161 void RemoveAllInvites();
162 bool AddLeaderInvite(Player
*player
);
163 bool AddMember(const uint64
&guid
, const char* name
);
164 // method: 0=just remove, 1=kick
165 uint32
RemoveMember(const uint64
&guid
, const uint8
&method
);
166 void ChangeLeader(const uint64
&guid
);
167 void SetLootMethod(LootMethod method
) { m_lootMethod
= method
; }
168 void SetLooterGuid(const uint64
&guid
) { m_looterGuid
= guid
; }
169 void UpdateLooterGuid( Creature
* creature
, bool ifneed
= false );
170 void SetLootThreshold(ItemQualities threshold
) { m_lootThreshold
= threshold
; }
171 void Disband(bool hideDestroy
=false);
173 // properties accessories
174 bool IsFull() const { return (m_groupType
==GROUPTYPE_NORMAL
) ? (m_memberSlots
.size()>=MAXGROUPSIZE
) : (m_memberSlots
.size()>=MAXRAIDSIZE
); }
175 bool isRaidGroup() const { return m_groupType
==GROUPTYPE_RAID
; }
176 bool isBGGroup() const { return m_bgGroup
!= NULL
; }
177 bool IsCreated() const { return GetMembersCount() > 0; }
178 const uint64
& GetLeaderGUID() const { return m_leaderGuid
; }
179 const char * GetLeaderName() const { return m_leaderName
.c_str(); }
180 LootMethod
GetLootMethod() const { return m_lootMethod
; }
181 const uint64
& GetLooterGuid() const { return m_looterGuid
; }
182 ItemQualities
GetLootThreshold() const { return m_lootThreshold
; }
184 // member manipulation methods
185 bool IsMember(const uint64
& guid
) const { return _getMemberCSlot(guid
) != m_memberSlots
.end(); }
186 bool IsLeader(const uint64
& guid
) const { return (GetLeaderGUID() == guid
); }
187 uint64
GetMemberGUID(const std::string
& name
)
189 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
191 if(itr
->name
== name
)
198 bool IsAssistant(uint64 guid
) const
200 member_citerator mslot
= _getMemberCSlot(guid
);
201 if(mslot
==m_memberSlots
.end())
204 return mslot
->assistant
;
206 Player
* GetInvited(const uint64
& guid
) const;
207 Player
* GetInvited(const std::string
& name
) const;
209 bool SameSubGroup(uint64 guid1
,const uint64
& guid2
) const
211 member_citerator mslot2
= _getMemberCSlot(guid2
);
212 if(mslot2
==m_memberSlots
.end())
215 return SameSubGroup(guid1
,&*mslot2
);
218 bool SameSubGroup(uint64 guid1
, MemberSlot
const* slot2
) const
220 member_citerator mslot1
= _getMemberCSlot(guid1
);
221 if(mslot1
==m_memberSlots
.end() || !slot2
)
224 return (mslot1
->group
==slot2
->group
);
227 bool HasFreeSlotSubGroup(uint8 subgroup
) const
229 return (m_subGroupsCounts
&& m_subGroupsCounts
[subgroup
] < MAXGROUPSIZE
);
232 bool SameSubGroup(Player
const* member1
, Player
const* member2
) const;
234 MemberSlotList
const& GetMemberSlots() const { return m_memberSlots
; }
235 GroupReference
* GetFirstMember() { return m_memberMgr
.getFirst(); }
236 uint32
GetMembersCount() const { return m_memberSlots
.size(); }
237 void GetDataForXPAtKill(Unit
const* victim
, uint32
& count
,uint32
& sum_level
, Player
* & member_with_max_level
, Player
* & not_gray_member_with_max_level
);
238 uint8
GetMemberGroup(uint64 guid
) const
240 member_citerator mslot
= _getMemberCSlot(guid
);
241 if(mslot
==m_memberSlots
.end())
242 return (MAXRAIDSIZE
/MAXGROUPSIZE
+1);
247 // some additional raid methods
248 void ConvertToRaid();
250 void SetBattlegroundGroup(BattleGround
*bg
) { m_bgGroup
= bg
; }
251 uint32
CanJoinBattleGroundQueue(uint32 bgTypeId
, uint32 bgQueueType
, uint32 MinPlayerCount
, uint32 MaxPlayerCount
, bool isRated
, uint32 arenaSlot
);
253 void ChangeMembersGroup(const uint64
&guid
, const uint8
&group
);
254 void ChangeMembersGroup(Player
*player
, const uint8
&group
);
256 void SetAssistant(uint64 guid
, const bool &state
)
260 if(_setAssistantFlag(guid
, state
))
263 void SetMainTank(uint64 guid
)
268 if(_setMainTank(guid
))
271 void SetMainAssistant(uint64 guid
)
276 if(_setMainAssistant(guid
))
280 void SetTargetIcon(uint8 id
, uint64 guid
);
281 void SetDifficulty(uint8 difficulty
);
282 uint8
GetDifficulty() { return m_difficulty
; }
284 bool InCombatToInstance(uint32 instanceId
);
285 void ResetInstances(uint8 method
, Player
* SendMsgTo
);
288 //void SendInit(WorldSession *session);
289 void SendTargetIconList(WorldSession
*session
);
291 void UpdatePlayerOutOfRange(Player
* pPlayer
);
292 // ignore: GUID of player that will be ignored
293 void BroadcastPacket(WorldPacket
*packet
, int group
=-1, uint64 ignore
=0);
294 void BroadcastReadyCheck(WorldPacket
*packet
);
295 void OfflineReadyCheck();
297 /*********************************************************/
298 /*** LOOT SYSTEM ***/
299 /*********************************************************/
301 void SendLootStartRoll(uint32 CountDown
, const Roll
&r
);
302 void SendLootRoll(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
303 void SendLootRollWon(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
304 void SendLootAllPassed(uint32 NumberOfPlayers
, const Roll
&r
);
305 void GroupLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
306 void NeedBeforeGreed(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
307 void MasterLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
308 Rolls::iterator
GetRoll(uint64 Guid
)
310 Rolls::iterator iter
;
311 for (iter
=RollId
.begin(); iter
!= RollId
.end(); ++iter
)
313 if ((*iter
)->itemGUID
== Guid
&& (*iter
)->isValid())
320 void CountTheRoll(Rolls::iterator roll
, uint32 NumberOfPlayers
);
321 void CountRollVote(const uint64
& playerGUID
, const uint64
& Guid
, uint32 NumberOfPlayers
, uint8 Choise
);
324 void LinkMember(GroupReference
*pRef
) { m_memberMgr
.insertFirst(pRef
); }
325 void DelinkMember(GroupReference
* /*pRef*/ ) { }
327 InstanceGroupBind
* BindToInstance(InstanceSave
*save
, bool permanent
, bool load
= false);
328 void UnbindInstance(uint32 mapid
, uint8 difficulty
, bool unload
= false);
329 InstanceGroupBind
* GetBoundInstance(uint32 mapid
, uint8 difficulty
);
330 BoundInstancesMap
& GetBoundInstances(uint8 difficulty
) { return m_boundInstances
[difficulty
]; }
333 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
=false);
334 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
, uint8 group
);
335 bool _removeMember(const uint64
&guid
); // returns true if leader has changed
336 void _setLeader(const uint64
&guid
);
338 void _removeRolls(const uint64
&guid
);
340 bool _setMembersGroup(const uint64
&guid
, const uint8
&group
);
341 bool _setAssistantFlag(const uint64
&guid
, const bool &state
);
342 bool _setMainTank(const uint64
&guid
);
343 bool _setMainAssistant(const uint64
&guid
);
345 void _homebindIfInstance(Player
*player
);
347 void _initRaidSubGroupsCounter()
349 // Sub group counters initialization
350 if (!m_subGroupsCounts
)
351 m_subGroupsCounts
= new uint8
[MAXRAIDSIZE
/ MAXGROUPSIZE
];
353 memset((void*)m_subGroupsCounts
, 0, (MAXRAIDSIZE
/ MAXGROUPSIZE
)*sizeof(uint8
));
355 for (member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
356 ++m_subGroupsCounts
[itr
->group
];
359 member_citerator
_getMemberCSlot(uint64 Guid
) const
361 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
363 if (itr
->guid
== Guid
)
366 return m_memberSlots
.end();
369 member_witerator
_getMemberWSlot(uint64 Guid
)
371 for(member_witerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
373 if (itr
->guid
== Guid
)
376 return m_memberSlots
.end();
379 void SubGroupCounterIncrease(uint8 subgroup
)
381 if (m_subGroupsCounts
)
382 ++m_subGroupsCounts
[subgroup
];
385 void SubGroupCounterDecrease(uint8 subgroup
)
387 if (m_subGroupsCounts
)
388 --m_subGroupsCounts
[subgroup
];
391 MemberSlotList m_memberSlots
;
392 GroupRefManager m_memberMgr
;
393 InvitesList m_invitees
;
395 std::string m_leaderName
;
397 uint64 m_mainAssistant
;
398 GroupType m_groupType
;
400 BattleGround
* m_bgGroup
;
401 uint64 m_targetIcons
[TARGETICONCOUNT
];
402 LootMethod m_lootMethod
;
403 ItemQualities m_lootThreshold
;
406 BoundInstancesMap m_boundInstances
[TOTAL_DIFFICULTIES
];
407 uint8
* m_subGroupsCounts
;