| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.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(uint64 guid) const { return _getMemberCSlot(guid) != m_memberSlots.end(); } |
|---|
| 187 | bool IsLeader(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, 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 SameSubGroup(Player const* member1, Player const* member2) const; |
|---|
| 216 | |
|---|
| 217 | MemberSlotList const& GetMemberSlots() const { return m_memberSlots; } |
|---|
| 218 | GroupReference* GetFirstMember() { return m_memberMgr.getFirst(); } |
|---|
| 219 | uint32 GetMembersCount() const { return m_memberSlots.size(); } |
|---|
| 220 | void GetDataForXPAtKill(Unit const* victim, uint32& count,uint32& sum_level, Player* & member_with_max_level); |
|---|
| 221 | uint8 GetMemberGroup(uint64 guid) const |
|---|
| 222 | { |
|---|
| 223 | member_citerator mslot = _getMemberCSlot(guid); |
|---|
| 224 | if(mslot==m_memberSlots.end()) |
|---|
| 225 | return (MAXRAIDSIZE/MAXGROUPSIZE+1); |
|---|
| 226 | |
|---|
| 227 | return mslot->group; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | // some additional raid methods |
|---|
| 231 | void ConvertToRaid() |
|---|
| 232 | { |
|---|
| 233 | _convertToRaid(); |
|---|
| 234 | SendUpdate(); |
|---|
| 235 | } |
|---|
| 236 | void SetBattlegroundGroup(BattleGround *bg) { m_bgGroup = bg; } |
|---|
| 237 | uint32 CanJoinBattleGroundQueue(uint32 bgTypeId, uint32 bgQueueType, uint32 MinPlayerCount, uint32 MaxPlayerCount, bool isRated, uint32 arenaSlot); |
|---|
| 238 | |
|---|
| 239 | void ChangeMembersGroup(const uint64 &guid, const uint8 &group); |
|---|
| 240 | void ChangeMembersGroup(Player *player, const uint8 &group); |
|---|
| 241 | |
|---|
| 242 | void SetAssistant(const uint64 &guid, const bool &state) |
|---|
| 243 | { |
|---|
| 244 | if(!isRaidGroup()) |
|---|
| 245 | return; |
|---|
| 246 | if(_setAssistantFlag(guid, state)) |
|---|
| 247 | SendUpdate(); |
|---|
| 248 | } |
|---|
| 249 | void SetMainTank(const uint64 &guid) |
|---|
| 250 | { |
|---|
| 251 | if(!isRaidGroup()) |
|---|
| 252 | return; |
|---|
| 253 | |
|---|
| 254 | if(_setMainTank(guid)) |
|---|
| 255 | SendUpdate(); |
|---|
| 256 | } |
|---|
| 257 | void SetMainAssistant(const uint64 &guid) |
|---|
| 258 | { |
|---|
| 259 | if(!isRaidGroup()) |
|---|
| 260 | return; |
|---|
| 261 | |
|---|
| 262 | if(_setMainAssistant(guid)) |
|---|
| 263 | SendUpdate(); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | void SetTargetIcon(uint8 id, uint64 guid); |
|---|
| 267 | void SetDifficulty(uint8 difficulty); |
|---|
| 268 | uint8 GetDifficulty() { return m_difficulty; } |
|---|
| 269 | uint16 InInstance(); |
|---|
| 270 | bool InCombatToInstance(uint32 instanceId); |
|---|
| 271 | void ResetInstances(uint8 method, Player* SendMsgTo); |
|---|
| 272 | |
|---|
| 273 | // -no description- |
|---|
| 274 | //void SendInit(WorldSession *session); |
|---|
| 275 | void SendTargetIconList(WorldSession *session); |
|---|
| 276 | void SendUpdate(); |
|---|
| 277 | void UpdatePlayerOutOfRange(Player* pPlayer); |
|---|
| 278 | // ignore: GUID of player that will be ignored |
|---|
| 279 | void BroadcastPacket(WorldPacket *packet, int group=-1, uint64 ignore=0); |
|---|
| 280 | void BroadcastReadyCheck(WorldPacket *packet); |
|---|
| 281 | void OfflineReadyCheck(); |
|---|
| 282 | |
|---|
| 283 | /*********************************************************/ |
|---|
| 284 | /*** LOOT SYSTEM ***/ |
|---|
| 285 | /*********************************************************/ |
|---|
| 286 | |
|---|
| 287 | void SendLootStartRoll(uint32 CountDown, const Roll &r); |
|---|
| 288 | void SendLootRoll(uint64 SourceGuid, uint64 TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
|---|
| 289 | void SendLootRollWon(uint64 SourceGuid, uint64 TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
|---|
| 290 | void SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r); |
|---|
| 291 | void GroupLoot(uint64 playerGUID, Loot *loot, Creature *creature); |
|---|
| 292 | void NeedBeforeGreed(uint64 playerGUID, Loot *loot, Creature *creature); |
|---|
| 293 | void MasterLoot(uint64 playerGUID, Loot *loot, Creature *creature); |
|---|
| 294 | Rolls::iterator GetRoll(uint64 Guid) |
|---|
| 295 | { |
|---|
| 296 | Rolls::iterator iter; |
|---|
| 297 | for (iter=RollId.begin(); iter != RollId.end(); ++iter) |
|---|
| 298 | { |
|---|
| 299 | if ((*iter)->itemGUID == Guid && (*iter)->isValid()) |
|---|
| 300 | { |
|---|
| 301 | return iter; |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | return RollId.end(); |
|---|
| 305 | } |
|---|
| 306 | void CountTheRoll(Rolls::iterator roll, uint32 NumberOfPlayers); |
|---|
| 307 | void CountRollVote(uint64 playerGUID, uint64 Guid, uint32 NumberOfPlayers, uint8 Choise); |
|---|
| 308 | void EndRoll(); |
|---|
| 309 | |
|---|
| 310 | void LinkMember(GroupReference *pRef) { m_memberMgr.insertFirst(pRef); } |
|---|
| 311 | void DelinkMember(GroupReference* /*pRef*/ ) { } |
|---|
| 312 | |
|---|
| 313 | InstanceGroupBind* BindToInstance(InstanceSave *save, bool permanent, bool load = false); |
|---|
| 314 | void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false); |
|---|
| 315 | InstanceGroupBind* GetBoundInstance(uint32 mapid, uint8 difficulty); |
|---|
| 316 | BoundInstancesMap& GetBoundInstances(uint8 difficulty) { return m_boundInstances[difficulty]; } |
|---|
| 317 | |
|---|
| 318 | protected: |
|---|
| 319 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant=false); |
|---|
| 320 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant, uint8 group); |
|---|
| 321 | bool _removeMember(const uint64 &guid); // returns true if leader has changed |
|---|
| 322 | void _setLeader(const uint64 &guid); |
|---|
| 323 | |
|---|
| 324 | void _removeRolls(const uint64 &guid); |
|---|
| 325 | |
|---|
| 326 | void _convertToRaid(); |
|---|
| 327 | bool _setMembersGroup(const uint64 &guid, const uint8 &group); |
|---|
| 328 | bool _setAssistantFlag(const uint64 &guid, const bool &state); |
|---|
| 329 | bool _setMainTank(const uint64 &guid); |
|---|
| 330 | bool _setMainAssistant(const uint64 &guid); |
|---|
| 331 | |
|---|
| 332 | void _homebindIfInstance(Player *player); |
|---|
| 333 | |
|---|
| 334 | member_citerator _getMemberCSlot(uint64 Guid) const |
|---|
| 335 | { |
|---|
| 336 | for(member_citerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
|---|
| 337 | { |
|---|
| 338 | if (itr->guid == Guid) |
|---|
| 339 | return itr; |
|---|
| 340 | } |
|---|
| 341 | return m_memberSlots.end(); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | member_witerator _getMemberWSlot(uint64 Guid) |
|---|
| 345 | { |
|---|
| 346 | for(member_witerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
|---|
| 347 | { |
|---|
| 348 | if (itr->guid == Guid) |
|---|
| 349 | return itr; |
|---|
| 350 | } |
|---|
| 351 | return m_memberSlots.end(); |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | MemberSlotList m_memberSlots; |
|---|
| 355 | GroupRefManager m_memberMgr; |
|---|
| 356 | InvitesList m_invitees; |
|---|
| 357 | uint64 m_leaderGuid; |
|---|
| 358 | std::string m_leaderName; |
|---|
| 359 | uint64 m_mainTank; |
|---|
| 360 | uint64 m_mainAssistant; |
|---|
| 361 | GroupType m_groupType; |
|---|
| 362 | uint8 m_difficulty; |
|---|
| 363 | BattleGround* m_bgGroup; |
|---|
| 364 | uint64 m_targetIcons[TARGETICONCOUNT]; |
|---|
| 365 | LootMethod m_lootMethod; |
|---|
| 366 | ItemQualities m_lootThreshold; |
|---|
| 367 | uint64 m_looterGuid; |
|---|
| 368 | Rolls RollId; |
|---|
| 369 | BoundInstancesMap m_boundInstances[TOTAL_DIFFICULTIES]; |
|---|
| 370 | }; |
|---|
| 371 | #endif |
|---|