2 * Copyright (C) 2005-2009 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
44 enum GroupMemberOnlineStatus
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
67 GROUP_UPDATE_FLAG_NONE
= 0x00000000, // nothing
68 GROUP_UPDATE_FLAG_STATUS
= 0x00000001, // uint16, flags
69 GROUP_UPDATE_FLAG_CUR_HP
= 0x00000002, // uint32
70 GROUP_UPDATE_FLAG_MAX_HP
= 0x00000004, // uint32
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 uint32 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, // uint32 pet cur health
82 GROUP_UPDATE_FLAG_PET_MAX_HP
= 0x00004000, // uint32 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 uint32 spellid + uint8 unk, pet auras...
87 GROUP_UPDATE_FLAG_VEHICLE_SEAT
= 0x00080000, // uint32 vehicle_seat_id (index from VehicleSeat.dbc)
88 GROUP_UPDATE_PET
= 0x0007FC00, // all pet flags
89 GROUP_UPDATE_FULL
= 0x0007FFFF, // all known flags
92 #define GROUP_UPDATE_FLAGS_COUNT 20
93 // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19
94 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};
98 class Roll
: public LootValidatorRef
101 Roll(uint64 _guid
, LootItem
const& li
)
102 : itemGUID(_guid
), itemid(li
.itemid
), itemRandomPropId(li
.randomPropertyId
), itemRandomSuffix(li
.randomSuffix
), itemCount(li
.count
),
103 totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {}
105 void setLoot(Loot
*pLoot
) { link(pLoot
, this); }
106 Loot
*getLoot() { return getTarget(); }
107 void targetObjectBuildLink();
111 int32 itemRandomPropId
;
112 uint32 itemRandomSuffix
;
114 typedef std::map
<uint64
, RollVote
> PlayerVote
;
115 PlayerVote playerVote
; //vote position correspond with player position (in group)
116 uint8 totalPlayersRolling
;
123 struct InstanceGroupBind
127 /* permanent InstanceGroupBinds exist iff the leader has a permanent
128 PlayerInstanceBind for the same instance. */
129 InstanceGroupBind() : save(NULL
), perm(false) {}
132 /** request member stats checken **/
133 /** todo: uninvite people that not accepted invite **/
134 class MANGOS_DLL_SPEC Group
144 typedef std::list
<MemberSlot
> MemberSlotList
;
145 typedef MemberSlotList::const_iterator member_citerator
;
147 typedef UNORDERED_MAP
< uint32
/*mapId*/, InstanceGroupBind
> BoundInstancesMap
;
149 typedef MemberSlotList::iterator member_witerator
;
150 typedef std::set
<Player
*> InvitesList
;
152 typedef std::vector
<Roll
*> Rolls
;
158 // group manipulation methods
159 bool Create(const uint64
&guid
, const char * name
);
160 bool LoadGroupFromDB(const uint64
&leaderGuid
, QueryResult
*result
= NULL
, bool loadMembers
= true);
161 bool LoadMemberFromDB(uint32 guidLow
, uint8 subgroup
, bool assistant
);
162 bool AddInvite(Player
*player
);
163 uint32
RemoveInvite(Player
*player
);
164 void RemoveAllInvites();
165 bool AddLeaderInvite(Player
*player
);
166 bool AddMember(const uint64
&guid
, const char* name
);
167 // method: 0=just remove, 1=kick
168 uint32
RemoveMember(const uint64
&guid
, const uint8
&method
);
169 void ChangeLeader(const uint64
&guid
);
170 void SetLootMethod(LootMethod method
) { m_lootMethod
= method
; }
171 void SetLooterGuid(const uint64
&guid
) { m_looterGuid
= guid
; }
172 void UpdateLooterGuid( Creature
* creature
, bool ifneed
= false );
173 void SetLootThreshold(ItemQualities threshold
) { m_lootThreshold
= threshold
; }
174 void Disband(bool hideDestroy
=false);
176 // properties accessories
177 bool IsFull() const { return (m_groupType
==GROUPTYPE_NORMAL
) ? (m_memberSlots
.size()>=MAXGROUPSIZE
) : (m_memberSlots
.size()>=MAXRAIDSIZE
); }
178 bool isRaidGroup() const { return m_groupType
==GROUPTYPE_RAID
; }
179 bool isBGGroup() const { return m_bgGroup
!= NULL
; }
180 bool IsCreated() const { return GetMembersCount() > 0; }
181 const uint64
& GetLeaderGUID() const { return m_leaderGuid
; }
182 const char * GetLeaderName() const { return m_leaderName
.c_str(); }
183 LootMethod
GetLootMethod() const { return m_lootMethod
; }
184 const uint64
& GetLooterGuid() const { return m_looterGuid
; }
185 ItemQualities
GetLootThreshold() const { return m_lootThreshold
; }
187 // member manipulation methods
188 bool IsMember(const uint64
& guid
) const { return _getMemberCSlot(guid
) != m_memberSlots
.end(); }
189 bool IsLeader(const uint64
& guid
) const { return (GetLeaderGUID() == guid
); }
190 uint64
GetMemberGUID(const std::string
& name
)
192 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
194 if(itr
->name
== name
)
201 bool IsAssistant(uint64 guid
) const
203 member_citerator mslot
= _getMemberCSlot(guid
);
204 if(mslot
==m_memberSlots
.end())
207 return mslot
->assistant
;
209 Player
* GetInvited(const uint64
& guid
) const;
210 Player
* GetInvited(const std::string
& name
) const;
212 bool SameSubGroup(uint64 guid1
,const uint64
& guid2
) const
214 member_citerator mslot2
= _getMemberCSlot(guid2
);
215 if(mslot2
==m_memberSlots
.end())
218 return SameSubGroup(guid1
,&*mslot2
);
221 bool SameSubGroup(uint64 guid1
, MemberSlot
const* slot2
) const
223 member_citerator mslot1
= _getMemberCSlot(guid1
);
224 if(mslot1
==m_memberSlots
.end() || !slot2
)
227 return (mslot1
->group
==slot2
->group
);
230 bool HasFreeSlotSubGroup(uint8 subgroup
) const
232 return (m_subGroupsCounts
&& m_subGroupsCounts
[subgroup
] < MAXGROUPSIZE
);
235 bool SameSubGroup(Player
const* member1
, Player
const* member2
) const;
237 MemberSlotList
const& GetMemberSlots() const { return m_memberSlots
; }
238 GroupReference
* GetFirstMember() { return m_memberMgr
.getFirst(); }
239 uint32
GetMembersCount() const { return m_memberSlots
.size(); }
240 void GetDataForXPAtKill(Unit
const* victim
, uint32
& count
,uint32
& sum_level
, Player
* & member_with_max_level
, Player
* & not_gray_member_with_max_level
);
241 uint8
GetMemberGroup(uint64 guid
) const
243 member_citerator mslot
= _getMemberCSlot(guid
);
244 if(mslot
==m_memberSlots
.end())
245 return (MAXRAIDSIZE
/MAXGROUPSIZE
+1);
250 // some additional raid methods
251 void ConvertToRaid();
253 void SetBattlegroundGroup(BattleGround
*bg
) { m_bgGroup
= bg
; }
254 uint32
CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId
, BattleGroundQueueTypeId bgQueueTypeId
, uint32 MinPlayerCount
, uint32 MaxPlayerCount
, bool isRated
, uint32 arenaSlot
);
256 void ChangeMembersGroup(const uint64
&guid
, const uint8
&group
);
257 void ChangeMembersGroup(Player
*player
, const uint8
&group
);
259 void SetAssistant(uint64 guid
, const bool &state
)
263 if(_setAssistantFlag(guid
, state
))
266 void SetMainTank(uint64 guid
)
271 if(_setMainTank(guid
))
274 void SetMainAssistant(uint64 guid
)
279 if(_setMainAssistant(guid
))
283 void SetTargetIcon(uint8 id
, uint64 guid
);
285 Difficulty
GetDifficulty(bool isRaid
) const { return isRaid
? m_raidDifficulty
: m_dungeonDifficulty
; }
286 Difficulty
GetDungeonDifficulty() const { return m_dungeonDifficulty
; }
287 Difficulty
GetRaidDifficulty() const { return m_raidDifficulty
; }
288 void SetDungeonDifficulty(Difficulty difficulty
);
289 void SetRaidDifficulty(Difficulty difficulty
);
291 bool InCombatToInstance(uint32 instanceId
);
292 void ResetInstances(uint8 method
, bool isRaid
, Player
* SendMsgTo
);
295 //void SendInit(WorldSession *session);
296 void SendTargetIconList(WorldSession
*session
);
298 void UpdatePlayerOutOfRange(Player
* pPlayer
);
299 // ignore: GUID of player that will be ignored
300 void BroadcastPacket(WorldPacket
*packet
, bool ignorePlayersInBGRaid
, int group
=-1, uint64 ignore
=0);
301 void BroadcastReadyCheck(WorldPacket
*packet
);
302 void OfflineReadyCheck();
304 /*********************************************************/
305 /*** LOOT SYSTEM ***/
306 /*********************************************************/
308 void SendLootStartRoll(uint32 CountDown
, const Roll
&r
);
309 void SendLootRoll(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
310 void SendLootRollWon(const uint64
& SourceGuid
, const uint64
& TargetGuid
, uint8 RollNumber
, uint8 RollType
, const Roll
&r
);
311 void SendLootAllPassed(uint32 NumberOfPlayers
, const Roll
&r
);
312 void GroupLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
313 void NeedBeforeGreed(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
314 void MasterLoot(const uint64
& playerGUID
, Loot
*loot
, Creature
*creature
);
315 Rolls::iterator
GetRoll(uint64 Guid
)
317 Rolls::iterator iter
;
318 for (iter
=RollId
.begin(); iter
!= RollId
.end(); ++iter
)
320 if ((*iter
)->itemGUID
== Guid
&& (*iter
)->isValid())
327 void CountTheRoll(Rolls::iterator roll
, uint32 NumberOfPlayers
);
328 void CountRollVote(const uint64
& playerGUID
, const uint64
& Guid
, uint32 NumberOfPlayers
, uint8 Choise
);
331 void LinkMember(GroupReference
*pRef
) { m_memberMgr
.insertFirst(pRef
); }
332 void DelinkMember(GroupReference
* /*pRef*/ ) { }
334 InstanceGroupBind
* BindToInstance(InstanceSave
*save
, bool permanent
, bool load
= false);
335 void UnbindInstance(uint32 mapid
, uint8 difficulty
, bool unload
= false);
336 InstanceGroupBind
* GetBoundInstance(Player
* player
);
337 InstanceGroupBind
* GetBoundInstance(Map
* aMap
);
338 BoundInstancesMap
& GetBoundInstances(Difficulty difficulty
) { return m_boundInstances
[difficulty
]; }
341 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
=false);
342 bool _addMember(const uint64
&guid
, const char* name
, bool isAssistant
, uint8 group
);
343 bool _removeMember(const uint64
&guid
); // returns true if leader has changed
344 void _setLeader(const uint64
&guid
);
346 void _removeRolls(const uint64
&guid
);
348 bool _setMembersGroup(const uint64
&guid
, const uint8
&group
);
349 bool _setAssistantFlag(const uint64
&guid
, const bool &state
);
350 bool _setMainTank(const uint64
&guid
);
351 bool _setMainAssistant(const uint64
&guid
);
353 void _homebindIfInstance(Player
*player
);
355 void _initRaidSubGroupsCounter()
357 // Sub group counters initialization
358 if (!m_subGroupsCounts
)
359 m_subGroupsCounts
= new uint8
[MAXRAIDSIZE
/ MAXGROUPSIZE
];
361 memset((void*)m_subGroupsCounts
, 0, (MAXRAIDSIZE
/ MAXGROUPSIZE
)*sizeof(uint8
));
363 for (member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
364 ++m_subGroupsCounts
[itr
->group
];
367 member_citerator
_getMemberCSlot(uint64 Guid
) const
369 for(member_citerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
371 if (itr
->guid
== Guid
)
374 return m_memberSlots
.end();
377 member_witerator
_getMemberWSlot(uint64 Guid
)
379 for(member_witerator itr
= m_memberSlots
.begin(); itr
!= m_memberSlots
.end(); ++itr
)
381 if (itr
->guid
== Guid
)
384 return m_memberSlots
.end();
387 void SubGroupCounterIncrease(uint8 subgroup
)
389 if (m_subGroupsCounts
)
390 ++m_subGroupsCounts
[subgroup
];
393 void SubGroupCounterDecrease(uint8 subgroup
)
395 if (m_subGroupsCounts
)
396 --m_subGroupsCounts
[subgroup
];
399 MemberSlotList m_memberSlots
;
400 GroupRefManager m_memberMgr
;
401 InvitesList m_invitees
;
403 std::string m_leaderName
;
405 uint64 m_mainAssistant
;
406 GroupType m_groupType
;
407 Difficulty m_dungeonDifficulty
;
408 Difficulty m_raidDifficulty
;
409 BattleGround
* m_bgGroup
;
410 uint64 m_targetIcons
[TARGETICONCOUNT
];
411 LootMethod m_lootMethod
;
412 ItemQualities m_lootThreshold
;
415 BoundInstancesMap m_boundInstances
[MAX_DIFFICULTY
];
416 uint8
* m_subGroupsCounts
;