2 * Copyright (C) 2005-2010 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"
24 #include "BattleGround.h"
31 #define MAXGROUPSIZE 5
32 #define MAXRAIDSIZE 40
33 #define TARGETICONCOUNT 8
45 enum GroupMemberOnlineStatus
47 MEMBER_STATUS_OFFLINE
= 0x0000,
48 MEMBER_STATUS_ONLINE
= 0x0001,
49 MEMBER_STATUS_PVP
= 0x0002,
50 MEMBER_STATUS_UNK0
= 0x0004, // dead? (health=0)
51 MEMBER_STATUS_UNK1
= 0x0008, // ghost? (health=1)
52 MEMBER_STATUS_UNK2
= 0x0010, // never seen
53 MEMBER_STATUS_UNK3
= 0x0020, // never seen
54 MEMBER_STATUS_UNK4
= 0x0040, // appears with dead and ghost flags
55 MEMBER_STATUS_UNK5
= 0x0080, // never seen
58 enum GroupType
// group type flags?
60 GROUPTYPE_NORMAL
= 0x00,
62 GROUPTYPE_RAID
= 0x02,
63 GROUPTYPE_BGRAID
= GROUPTYPE_BG
| GROUPTYPE_RAID
, // mask
66 // 0x10, leave/change group?, I saw this flag when leaving group and after leaving BG while in group
73 GROUP_UPDATE_FLAG_NONE
= 0x00000000, // nothing
74 GROUP_UPDATE_FLAG_STATUS
= 0x00000001, // uint16, flags
75 GROUP_UPDATE_FLAG_CUR_HP
= 0x00000002, // uint32
76 GROUP_UPDATE_FLAG_MAX_HP
= 0x00000004, // uint32
77 GROUP_UPDATE_FLAG_POWER_TYPE
= 0x00000008, // uint8
78 GROUP_UPDATE_FLAG_CUR_POWER
= 0x00000010, // uint16
79 GROUP_UPDATE_FLAG_MAX_POWER
= 0x00000020, // uint16
80 GROUP_UPDATE_FLAG_LEVEL
= 0x00000040, // uint16
81 GROUP_UPDATE_FLAG_ZONE
= 0x00000080, // uint16
82 GROUP_UPDATE_FLAG_POSITION
= 0x00000100, // uint16, uint16
83 GROUP_UPDATE_FLAG_AURAS
= 0x00000200, // uint64 mask, for each bit set uint32 spellid + uint8 unk
84 GROUP_UPDATE_FLAG_PET_GUID
= 0x00000400, // uint64 pet guid
85 GROUP_UPDATE_FLAG_PET_NAME
= 0x00000800, // pet name, NULL terminated string
86 GROUP_UPDATE_FLAG_PET_MODEL_ID
= 0x00001000, // uint16, model id
87 GROUP_UPDATE_FLAG_PET_CUR_HP
= 0x00002000, // uint32 pet cur health
88 GROUP_UPDATE_FLAG_PET_MAX_HP
= 0x00004000, // uint32 pet max health
89 GROUP_UPDATE_FLAG_PET_POWER_TYPE
= 0x00008000, // uint8 pet power type
90 GROUP_UPDATE_FLAG_PET_CUR_POWER
= 0x00010000, // uint16 pet cur power
91 GROUP_UPDATE_FLAG_PET_MAX_POWER
= 0x00020000, // uint16 pet max power
92 GROUP_UPDATE_FLAG_PET_AURAS
= 0x00040000, // uint64 mask, for each bit set uint32 spellid + uint8 unk, pet auras...
93 GROUP_UPDATE_FLAG_VEHICLE_SEAT
= 0x00080000, // uint32 vehicle_seat_id (index from VehicleSeat.dbc)
94 GROUP_UPDATE_PET
= 0x0007FC00, // all pet flags
95 GROUP_UPDATE_FULL
= 0x0007FFFF, // all known flags
98 #define GROUP_UPDATE_FLAGS_COUNT 20
99 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19
100 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};
104 class Roll
: public LootValidatorRef
107 Roll(uint64 _guid
, LootItem
const& li
)
108 : itemGUID(_guid
), itemid(li
.itemid
), itemRandomPropId(li
.randomPropertyId
), itemRandomSuffix(li
.randomSuffix
), itemCount(li
.count
),
109 totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {}
111 void setLoot(Loot
*pLoot
) { link(pLoot
, this); }
112 Loot
*getLoot() { return getTarget(); }
113 void targetObjectBuildLink();
117 int32 itemRandomPropId
;
118 uint32 itemRandomSuffix
;
120 typedef std::map
<uint64
, RollVote
> PlayerVote
;
121 PlayerVote playerVote
; //vote position correspond with player position (in group)
122 uint8 totalPlayersRolling
;
129 struct InstanceGroupBind
133 /* permanent InstanceGroupBinds exist iff the leader has a permanent
134 PlayerInstanceBind for the same instance. */
135 InstanceGroupBind() : save(NULL
), perm(false) {}
138 /** request member stats checken **/
139 /** todo: uninvite people that not accepted invite **/
140 class MANGOS_DLL_SPEC Group
150 typedef std::list
<MemberSlot
> MemberSlotList
;
151 typedef MemberSlotList::const_iterator member_citerator
;
153 typedef UNORDERED_MAP
< uint32
/*mapId*/, InstanceGroupBind
> BoundInstancesMap
;
155 typedef MemberSlotList::iterator member_witerator
;
156 typedef std::set
<Player
*> InvitesList
;
158 typedef std::vector
<Roll
*> Rolls
;
164 // group manipulation methods
165 bool Create(const uint64
&guid
, const char * name
);
166 bool LoadGroupFromDB(const uint64
&leaderGuid
, QueryResult
*result
= NULL
, bool loadMembers
= true);
167 bool LoadMemberFromDB(uint32 guidLow
, uint8 subgroup
, bool assistant
);
168 bool AddInvite(Player
*player
);
169 uint32
RemoveInvite(Player
*player
);
170 void RemoveAllInvites();
171 bool AddLeaderInvite(Player
*player
);
172 bool AddMember(const uint64
&guid
, const char* name
);
173 // method: 0=just remove, 1=kick
174 uint32
RemoveMember(const uint64
&guid
, const uint8
&method
);
175 void ChangeLeader(const uint64
&guid
);
176 void SetLootMethod(LootMethod method
) { m_lootMethod
= method
; }
177 void SetLooterGuid(const uint64
&guid
) { m_looterGuid
= guid
; }
178 void UpdateLooterGuid( Creature
* creature
, bool ifneed
= false );
179 void SetLootThreshold(ItemQualities threshold
) { m_lootThreshold
= threshold
; }
180 void Disband(bool hideDestroy
=false);
182 // properties accessories
183 bool IsFull() const { return (m_groupType
==GROUPTYPE_NORMAL
) ? (m_memberSlots
.size()>=MAXGROUPSIZE
) : (m_memberSlots
.size()>=MAXRAIDSIZE
); }
184 bool isRaidGroup() const { return m_groupType
==GROUPTYPE_RAID
; }
185 bool isBGGroup() const { return m_bgGroup
!= NULL
; }
186 bool IsCreated() const { return GetMembersCount() > 0; }
187 const uint64
& GetLeaderGUID() const { return m_leaderGuid
; }
188 const char * GetLeaderName() const { return m_leaderName
.c_str(); }
189 LootMethod
GetLootMethod() const { return m_lootMethod
; }
190 const uint64
& GetLooterGuid() const { return m_looterGuid
; }
191 ItemQualities
GetLootThreshold() const { return m_lootThreshold
; }
193 // member manipulation methods
194 bool IsMember(const uint64
& guid
) const { return _getMemberCSlot(guid
) != m_memberSlots
.end(); }
195 bool IsLeader(const uint64
& guid
) const { return (GetLeaderGUID() == guid
); }
196 uint64
GetMemberGUID(const std::string
& name
)
198 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
200 if(itr
->name
== name
)
207 bool IsAssistant(uint64 guid
) const
209 member_citerator mslot
= _getMemberCSlot(guid
);
210 if(mslot
==m_memberSlots
.end())
213 return mslot
->assistant
;
215 Player
* GetInvited(const uint64
& guid
) const;
216 Player
* GetInvited(const std::string
& name
) const;
218 bool SameSubGroup(uint64 guid1
,const uint64
& guid2
) const
220 member_citerator mslot2
= _getMemberCSlot(guid2
);
221 if(mslot2
==m_memberSlots
.end())
224 return SameSubGroup(guid1
,&*mslot2
);
227 bool SameSubGroup(uint64 guid1
, MemberSlot
const* slot2
) const
229 member_citerator mslot1
= _getMemberCSlot(guid1
);
230 if(mslot1
==m_memberSlots
.end() || !slot2
)
233 return (mslot1
->group
==slot2
->group
);
236 bool HasFreeSlotSubGroup(uint8 subgroup
) const
238 return (m_subGroupsCounts
&& m_subGroupsCounts
[subgroup
] < MAXGROUPSIZE
);
241 bool SameSubGroup(Player
const* member1
, Player
const* member2
) const;
243 MemberSlotList
const& GetMemberSlots() const { return m_memberSlots
; }
244 GroupReference
* GetFirstMember() { return m_memberMgr
.getFirst(); }
245 uint32
GetMembersCount() const { return m_memberSlots
.size(); }
246 void GetDataForXPAtKill(Unit
const* victim
, uint32
& count
,uint32
& sum_level
, Player
* & member_with_max_level
, Player
* & not_gray_member_with_max_level
);
247 uint8
GetMemberGroup(uint64 guid
) const
249 member_citerator mslot
= _getMemberCSlot(guid
);
250 if(mslot
==m_memberSlots
.end())
251 return (MAXRAIDSIZE
/MAXGROUPSIZE
+1);
256 // some additional raid methods
257 void ConvertToRaid();
259 void SetBattlegroundGroup(BattleGround
*bg
) { m_bgGroup
= bg
; }
260 uint32
CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId
, BattleGroundQueueTypeId bgQueueTypeId
, uint32 MinPlayerCount
, uint32 MaxPlayerCount
, bool isRated
, uint32 arenaSlot
);
262 void ChangeMembersGroup(const uint64
&guid
, const uint8
&group
);
263 void ChangeMembersGroup(Player
*player
, const uint8
&group
);
265 void SetAssistant(uint64 guid
, const bool &state
)
269 if(_setAssistantFlag(guid
, state
))
272 void SetMainTank(uint64 guid
)
277 if(_setMainTank(guid
))
280 void SetMainAssistant(uint64 guid
)
285 if(_setMainAssistant(guid
))
289 void SetTargetIcon(uint8 id
, uint64 guid
);
291 Difficulty
GetDifficulty(bool isRaid
) const { return isRaid
? m_raidDifficulty
: m_dungeonDifficulty
; }
292 Difficulty
GetDungeonDifficulty() const { return m_dungeonDifficulty
; }
293 Difficulty
GetRaidDifficulty() const { return m_raidDifficulty
; }
294 void SetDungeonDifficulty(Difficulty difficulty
);
295 void SetRaidDifficulty(Difficulty difficulty
);
297 bool InCombatToInstance(uint32 instanceId
);
298 void ResetInstances(uint8 method
, bool isRaid
, Player
* SendMsgTo
);
301 //void SendInit(WorldSession *session);
302 void SendTargetIconList(WorldSession
*session
);
304 void UpdatePlayerOutOfRange(Player
* pPlayer
);
305 // ignore: GUID of player that will be ignored
306 void BroadcastPacket(WorldPacket
*packet
, bool ignorePlayersInBGRaid
, int group
=-1, uint64 ignore
=0);
307 void BroadcastReadyCheck(WorldPacket
*packet
);
308 void OfflineReadyCheck();
310 /*********************************************************/
311 /*** LOOT SYSTEM ***/
312 /*********************************************************/
314 void SendLootStartRoll(uint32 CountDown
, const Roll
&r
);
315 void SendLootRoll(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
316 void SendLootRollWon(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
317 void SendLootAllPassed(uint32 NumberOfPlayers
, const Roll
&r
);
318 void GroupLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
319 void NeedBeforeGreed(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
320 void MasterLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
321 Rolls::iterator
GetRoll(uint64 Guid
)
323 Rolls::iterator iter
;
324 for (iter
=RollId
.begin(); iter
!= RollId
.end(); ++iter
)
326 if ((*iter
)->itemGUID
== Guid
&& (*iter
)->isValid())
333 void CountTheRoll(Rolls::iterator roll
, uint32 NumberOfPlayers
);
334 void CountRollVote(const uint64
& playerGUID
, const uint64
& Guid
, uint32 NumberOfPlayers
, uint8 Choise
);
337 void LinkMember(GroupReference
*pRef
) { m_memberMgr
.insertFirst(pRef
); }
338 void DelinkMember(GroupReference
* /*pRef*/ ) { }
340 InstanceGroupBind
* BindToInstance(InstanceSave
*save
, bool permanent
, bool load
= false);
341 void UnbindInstance(uint32 mapid
, uint8 difficulty
, bool unload
= false);
342 InstanceGroupBind
* GetBoundInstance(Player
* player
);
343 InstanceGroupBind
* GetBoundInstance(Map
* aMap
);
344 BoundInstancesMap
& GetBoundInstances(Difficulty difficulty
) { return m_boundInstances
[difficulty
]; }
347 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
=false);
348 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
, uint8 group
);
349 bool _removeMember(const uint64
&guid
); // returns true if leader has changed
350 void _setLeader(const uint64
&guid
);
352 void _removeRolls(const uint64
&guid
);
354 bool _setMembersGroup(const uint64
&guid
, const uint8
&group
);
355 bool _setAssistantFlag(const uint64
&guid
, const bool &state
);
356 bool _setMainTank(const uint64
&guid
);
357 bool _setMainAssistant(const uint64
&guid
);
359 void _homebindIfInstance(Player
*player
);
361 void _initRaidSubGroupsCounter()
363 // Sub group counters initialization
364 if (!m_subGroupsCounts
)
365 m_subGroupsCounts
= new uint8
[MAXRAIDSIZE
/ MAXGROUPSIZE
];
367 memset((void*)m_subGroupsCounts
, 0, (MAXRAIDSIZE
/ MAXGROUPSIZE
)*sizeof(uint8
));
369 for (member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
370 ++m_subGroupsCounts
[itr
->group
];
373 member_citerator
_getMemberCSlot(uint64 Guid
) const
375 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
377 if (itr
->guid
== Guid
)
380 return m_memberSlots
.end();
383 member_witerator
_getMemberWSlot(uint64 Guid
)
385 for(member_witerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
387 if (itr
->guid
== Guid
)
390 return m_memberSlots
.end();
393 void SubGroupCounterIncrease(uint8 subgroup
)
395 if (m_subGroupsCounts
)
396 ++m_subGroupsCounts
[subgroup
];
399 void SubGroupCounterDecrease(uint8 subgroup
)
401 if (m_subGroupsCounts
)
402 --m_subGroupsCounts
[subgroup
];
405 MemberSlotList m_memberSlots
;
406 GroupRefManager m_memberMgr
;
407 InvitesList m_invitees
;
409 std::string m_leaderName
;
411 uint64 m_mainAssistant
;
412 GroupType m_groupType
;
413 Difficulty m_dungeonDifficulty
;
414 Difficulty m_raidDifficulty
;
415 BattleGround
* m_bgGroup
;
416 uint64 m_targetIcons
[TARGETICONCOUNT
];
417 LootMethod m_lootMethod
;
418 ItemQualities m_lootThreshold
;
421 BoundInstancesMap m_boundInstances
[MAX_DIFFICULTY
];
422 uint8
* m_subGroupsCounts
;