[2] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 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. |
---|
| 8 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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 |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef MANGOSSERVER_GROUP_H |
---|
| 20 | #define MANGOSSERVER_GROUP_H |
---|
| 21 | |
---|
| 22 | #include "GroupReference.h" |
---|
| 23 | #include "GroupRefManager.h" |
---|
| 24 | #include "LootMgr.h" |
---|
| 25 | |
---|
| 26 | #include <map> |
---|
| 27 | #include <vector> |
---|
| 28 | |
---|
| 29 | #define MAXGROUPSIZE 5 |
---|
| 30 | #define MAXRAIDSIZE 40 |
---|
| 31 | #define TARGETICONCOUNT 8 |
---|
| 32 | |
---|
| 33 | enum RollVote |
---|
| 34 | { |
---|
| 35 | PASS = 0, |
---|
| 36 | NEED = 1, |
---|
| 37 | GREED = 2, |
---|
| 38 | NOT_EMITED_YET = 3, |
---|
| 39 | NOT_VALID = 4 |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | enum GroupMemberOnlineStatus |
---|
| 43 | { |
---|
| 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 |
---|
| 53 | }; |
---|
| 54 | |
---|
| 55 | enum GroupType |
---|
| 56 | { |
---|
| 57 | GROUPTYPE_NORMAL = 0, |
---|
| 58 | GROUPTYPE_RAID = 1 |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | class BattleGround; |
---|
| 62 | |
---|
| 63 | enum GroupUpdateFlags |
---|
| 64 | { |
---|
| 65 | GROUP_UPDATE_FLAG_NONE = 0x00000000, // nothing |
---|
| 66 | GROUP_UPDATE_FLAG_STATUS = 0x00000001, // uint16, flags |
---|
| 67 | GROUP_UPDATE_FLAG_CUR_HP = 0x00000002, // uint16 |
---|
| 68 | GROUP_UPDATE_FLAG_MAX_HP = 0x00000004, // uint16 |
---|
| 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 uint16 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, // uint16 pet cur health |
---|
| 80 | GROUP_UPDATE_FLAG_PET_MAX_HP = 0x00004000, // uint16 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 uint16 spellid + uint8 unk, pet auras... |
---|
| 85 | GROUP_UPDATE_PET = 0x0007FC00, // all pet flags |
---|
| 86 | GROUP_UPDATE_FULL = 0x0007FFFF, // all known flags |
---|
| 87 | }; |
---|
| 88 | |
---|
| 89 | #define GROUP_UPDATE_FLAGS_COUNT 20 |
---|
| 90 | // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19 |
---|
| 91 | 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}; |
---|
| 92 | |
---|
| 93 | class InstanceSave; |
---|
| 94 | |
---|
| 95 | class Roll : public LootValidatorRef |
---|
| 96 | { |
---|
| 97 | public: |
---|
| 98 | Roll(uint64 _guid, LootItem const& li) |
---|
| 99 | : itemGUID(_guid), itemid(li.itemid), itemRandomPropId(li.randomPropertyId), itemRandomSuffix(li.randomSuffix), |
---|
| 100 | totalPlayersRolling(0), totalNeed(0), totalGreed(0), totalPass(0), itemSlot(0) {} |
---|
| 101 | ~Roll() { } |
---|
| 102 | void setLoot(Loot *pLoot) { link(pLoot, this); } |
---|
| 103 | Loot *getLoot() { return getTarget(); } |
---|
| 104 | void targetObjectBuildLink(); |
---|
| 105 | |
---|
| 106 | uint64 itemGUID; |
---|
| 107 | uint32 itemid; |
---|
| 108 | int32 itemRandomPropId; |
---|
| 109 | uint32 itemRandomSuffix; |
---|
| 110 | typedef std::map<uint64, RollVote> PlayerVote; |
---|
| 111 | PlayerVote playerVote; //vote position correspond with player position (in group) |
---|
| 112 | uint8 totalPlayersRolling; |
---|
| 113 | uint8 totalNeed; |
---|
| 114 | uint8 totalGreed; |
---|
| 115 | uint8 totalPass; |
---|
| 116 | uint8 itemSlot; |
---|
| 117 | }; |
---|
| 118 | |
---|
| 119 | struct InstanceGroupBind |
---|
| 120 | { |
---|
| 121 | InstanceSave *save; |
---|
| 122 | bool perm; |
---|
| 123 | /* permanent InstanceGroupBinds exist iff the leader has a permanent |
---|
| 124 | PlayerInstanceBind for the same instance. */ |
---|
| 125 | InstanceGroupBind() : save(NULL), perm(false) {} |
---|
| 126 | }; |
---|
| 127 | |
---|
| 128 | /** request member stats checken **/ |
---|
| 129 | /** todo: uninvite people that not accepted invite **/ |
---|
| 130 | class MANGOS_DLL_SPEC Group |
---|
| 131 | { |
---|
| 132 | public: |
---|
| 133 | struct MemberSlot |
---|
| 134 | { |
---|
| 135 | uint64 guid; |
---|
| 136 | std::string name; |
---|
| 137 | uint8 group; |
---|
| 138 | bool assistant; |
---|
| 139 | }; |
---|
| 140 | typedef std::list<MemberSlot> MemberSlotList; |
---|
| 141 | typedef MemberSlotList::const_iterator member_citerator; |
---|
| 142 | |
---|
| 143 | typedef HM_NAMESPACE::hash_map< uint32 /*mapId*/, InstanceGroupBind> BoundInstancesMap; |
---|
| 144 | protected: |
---|
| 145 | typedef MemberSlotList::iterator member_witerator; |
---|
| 146 | typedef std::set<uint64> InvitesList; |
---|
| 147 | |
---|
| 148 | typedef std::vector<Roll*> Rolls; |
---|
| 149 | |
---|
| 150 | public: |
---|
| 151 | Group(); |
---|
| 152 | ~Group(); |
---|
| 153 | |
---|
| 154 | // group manipulation methods |
---|
| 155 | bool Create(const uint64 &guid, const char * name); |
---|
| 156 | bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result = NULL, bool loadMembers = true); |
---|
| 157 | bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant); |
---|
| 158 | bool AddInvite(Player *player); |
---|
| 159 | uint32 RemoveInvite(Player *player); |
---|
| 160 | void RemoveAllInvites(); |
---|
| 161 | bool AddLeaderInvite(Player *player); |
---|
| 162 | bool AddMember(const uint64 &guid, const char* name); |
---|
| 163 | // method: 0=just remove, 1=kick |
---|
| 164 | uint32 RemoveMember(const uint64 &guid, const uint8 &method); |
---|
| 165 | void ChangeLeader(const uint64 &guid); |
---|
| 166 | void SetLootMethod(LootMethod method) { m_lootMethod = method; } |
---|
| 167 | void SetLooterGuid(const uint64 &guid) { m_looterGuid = guid; } |
---|
| 168 | void UpdateLooterGuid( Creature* creature, bool ifneed = false ); |
---|
| 169 | void SetLootThreshold(ItemQualities threshold) { m_lootThreshold = threshold; } |
---|
| 170 | void Disband(bool hideDestroy=false); |
---|
| 171 | |
---|
| 172 | // properties accessories |
---|
| 173 | bool IsFull() const { return (m_groupType==GROUPTYPE_NORMAL) ? (m_memberSlots.size()>=MAXGROUPSIZE) : (m_memberSlots.size()>=MAXRAIDSIZE); } |
---|
| 174 | bool isRaidGroup() const { return m_groupType==GROUPTYPE_RAID; } |
---|
| 175 | bool isBGGroup() const { return m_bgGroup != NULL; } |
---|
| 176 | bool IsCreated() const { return GetMembersCount() > 0; } |
---|
| 177 | const uint64& GetLeaderGUID() const { return m_leaderGuid; } |
---|
| 178 | const char * GetLeaderName() const { return m_leaderName.c_str(); } |
---|
| 179 | LootMethod GetLootMethod() const { return m_lootMethod; } |
---|
| 180 | const uint64& GetLooterGuid() const { return m_looterGuid; } |
---|
| 181 | ItemQualities GetLootThreshold() const { return m_lootThreshold; } |
---|
| 182 | |
---|
| 183 | // member manipulation methods |
---|
| 184 | bool IsMember(uint64 guid) const { return _getMemberCSlot(guid) != m_memberSlots.end(); } |
---|
| 185 | bool IsLeader(uint64 guid) const { return (GetLeaderGUID() == guid); } |
---|
| 186 | bool IsAssistant(uint64 guid) const |
---|
| 187 | { |
---|
| 188 | member_citerator mslot = _getMemberCSlot(guid); |
---|
| 189 | if(mslot==m_memberSlots.end()) |
---|
| 190 | return false; |
---|
| 191 | |
---|
| 192 | return mslot->assistant; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | bool SameSubGroup(uint64 guid1, uint64 guid2) const |
---|
| 196 | { |
---|
| 197 | member_citerator mslot2 = _getMemberCSlot(guid2); |
---|
| 198 | if(mslot2==m_memberSlots.end()) |
---|
| 199 | return false; |
---|
| 200 | |
---|
| 201 | return SameSubGroup(guid1,&*mslot2); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | bool SameSubGroup(uint64 guid1, MemberSlot const* slot2) const |
---|
| 205 | { |
---|
| 206 | member_citerator mslot1 = _getMemberCSlot(guid1); |
---|
| 207 | if(mslot1==m_memberSlots.end() || !slot2) |
---|
| 208 | return false; |
---|
| 209 | |
---|
| 210 | return (mslot1->group==slot2->group); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | bool SameSubGroup(Player const* member1, Player const* member2) const; |
---|
| 214 | |
---|
| 215 | MemberSlotList const& GetMemberSlots() const { return m_memberSlots; } |
---|
| 216 | GroupReference* GetFirstMember() { return m_memberMgr.getFirst(); } |
---|
| 217 | uint32 GetMembersCount() const { return m_memberSlots.size(); } |
---|
| 218 | void GetDataForXPAtKill(Unit const* victim, uint32& count,uint32& sum_level, Player* & member_with_max_level); |
---|
| 219 | uint8 GetMemberGroup(uint64 guid) const |
---|
| 220 | { |
---|
| 221 | member_citerator mslot = _getMemberCSlot(guid); |
---|
| 222 | if(mslot==m_memberSlots.end()) |
---|
| 223 | return (MAXRAIDSIZE/MAXGROUPSIZE+1); |
---|
| 224 | |
---|
| 225 | return mslot->group; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | // some additional raid methods |
---|
| 229 | void ConvertToRaid() |
---|
| 230 | { |
---|
| 231 | _convertToRaid(); |
---|
| 232 | SendUpdate(); |
---|
| 233 | } |
---|
| 234 | void SetBattlegroundGroup(BattleGround *bg) { m_bgGroup = bg; } |
---|
[9] | 235 | uint32 CanJoinBattleGroundQueue(uint32 bgTypeId, uint32 bgQueueType, uint32 MinPlayerCount, uint32 MaxPlayerCount, bool isRated, uint32 arenaSlot); |
---|
[2] | 236 | |
---|
| 237 | void ChangeMembersGroup(const uint64 &guid, const uint8 &group); |
---|
| 238 | void ChangeMembersGroup(Player *player, const uint8 &group); |
---|
| 239 | |
---|
| 240 | void SetAssistant(const uint64 &guid, const bool &state) |
---|
| 241 | { |
---|
| 242 | if(!isRaidGroup()) |
---|
| 243 | return; |
---|
| 244 | if(_setAssistantFlag(guid, state)) |
---|
| 245 | SendUpdate(); |
---|
| 246 | } |
---|
| 247 | void SetMainTank(const uint64 &guid) |
---|
| 248 | { |
---|
| 249 | if(!isRaidGroup()) |
---|
| 250 | return; |
---|
| 251 | |
---|
| 252 | if(_setMainTank(guid)) |
---|
| 253 | SendUpdate(); |
---|
| 254 | } |
---|
| 255 | void SetMainAssistant(const uint64 &guid) |
---|
| 256 | { |
---|
| 257 | if(!isRaidGroup()) |
---|
| 258 | return; |
---|
| 259 | |
---|
| 260 | if(_setMainAssistant(guid)) |
---|
| 261 | SendUpdate(); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | void SetTargetIcon(uint8 id, uint64 guid); |
---|
| 265 | void SetDifficulty(uint8 difficulty); |
---|
| 266 | uint8 GetDifficulty() { return m_difficulty; } |
---|
| 267 | uint16 InInstance(); |
---|
| 268 | bool InCombatToInstance(uint32 instanceId); |
---|
| 269 | void ResetInstances(uint8 method, Player* SendMsgTo); |
---|
| 270 | |
---|
| 271 | // -no description- |
---|
| 272 | //void SendInit(WorldSession *session); |
---|
| 273 | void SendTargetIconList(WorldSession *session); |
---|
| 274 | void SendUpdate(); |
---|
| 275 | void UpdatePlayerOutOfRange(Player* pPlayer); |
---|
| 276 | // ignore: GUID of player that will be ignored |
---|
| 277 | void BroadcastPacket(WorldPacket *packet, int group=-1, uint64 ignore=0); |
---|
| 278 | void BroadcastReadyCheck(WorldPacket *packet); |
---|
| 279 | void OfflineReadyCheck(); |
---|
| 280 | |
---|
| 281 | /*********************************************************/ |
---|
| 282 | /*** LOOT SYSTEM ***/ |
---|
| 283 | /*********************************************************/ |
---|
| 284 | |
---|
| 285 | void SendLootStartRoll(uint32 CountDown, const Roll &r); |
---|
| 286 | void SendLootRoll(uint64 SourceGuid, uint64 TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
---|
| 287 | void SendLootRollWon(uint64 SourceGuid, uint64 TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r); |
---|
| 288 | void SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r); |
---|
| 289 | void GroupLoot(uint64 playerGUID, Loot *loot, Creature *creature); |
---|
| 290 | void NeedBeforeGreed(uint64 playerGUID, Loot *loot, Creature *creature); |
---|
| 291 | void MasterLoot(uint64 playerGUID, Loot *loot, Creature *creature); |
---|
| 292 | Rolls::iterator GetRoll(uint64 Guid) |
---|
| 293 | { |
---|
| 294 | Rolls::iterator iter; |
---|
| 295 | for (iter=RollId.begin(); iter != RollId.end(); ++iter) |
---|
| 296 | { |
---|
| 297 | if ((*iter)->itemGUID == Guid && (*iter)->isValid()) |
---|
| 298 | { |
---|
| 299 | return iter; |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | return RollId.end(); |
---|
| 303 | } |
---|
| 304 | void CountTheRoll(Rolls::iterator roll, uint32 NumberOfPlayers); |
---|
| 305 | void CountRollVote(uint64 playerGUID, uint64 Guid, uint32 NumberOfPlayers, uint8 Choise); |
---|
| 306 | void EndRoll(); |
---|
| 307 | |
---|
| 308 | void LinkMember(GroupReference *pRef) { m_memberMgr.insertFirst(pRef); } |
---|
| 309 | void DelinkMember(GroupReference* /*pRef*/ ) { } |
---|
| 310 | |
---|
| 311 | InstanceGroupBind* BindToInstance(InstanceSave *save, bool permanent, bool load = false); |
---|
| 312 | void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false); |
---|
| 313 | InstanceGroupBind* GetBoundInstance(uint32 mapid, uint8 difficulty); |
---|
| 314 | BoundInstancesMap& GetBoundInstances(uint8 difficulty) { return m_boundInstances[difficulty]; } |
---|
| 315 | |
---|
| 316 | protected: |
---|
| 317 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant=false); |
---|
| 318 | bool _addMember(const uint64 &guid, const char* name, bool isAssistant, uint8 group); |
---|
| 319 | bool _removeMember(const uint64 &guid); // returns true if leader has changed |
---|
| 320 | void _setLeader(const uint64 &guid); |
---|
| 321 | |
---|
| 322 | void _removeRolls(const uint64 &guid); |
---|
| 323 | |
---|
| 324 | void _convertToRaid(); |
---|
| 325 | bool _setMembersGroup(const uint64 &guid, const uint8 &group); |
---|
| 326 | bool _setAssistantFlag(const uint64 &guid, const bool &state); |
---|
| 327 | bool _setMainTank(const uint64 &guid); |
---|
| 328 | bool _setMainAssistant(const uint64 &guid); |
---|
| 329 | |
---|
| 330 | void _homebindIfInstance(Player *player); |
---|
| 331 | |
---|
| 332 | member_citerator _getMemberCSlot(uint64 Guid) const |
---|
| 333 | { |
---|
| 334 | for(member_citerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
---|
| 335 | { |
---|
| 336 | if (itr->guid == Guid) |
---|
| 337 | return itr; |
---|
| 338 | } |
---|
| 339 | return m_memberSlots.end(); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | member_witerator _getMemberWSlot(uint64 Guid) |
---|
| 343 | { |
---|
| 344 | for(member_witerator itr = m_memberSlots.begin(); itr != m_memberSlots.end(); ++itr) |
---|
| 345 | { |
---|
| 346 | if (itr->guid == Guid) |
---|
| 347 | return itr; |
---|
| 348 | } |
---|
| 349 | return m_memberSlots.end(); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | MemberSlotList m_memberSlots; |
---|
| 353 | GroupRefManager m_memberMgr; |
---|
| 354 | InvitesList m_invitees; |
---|
| 355 | uint64 m_leaderGuid; |
---|
| 356 | std::string m_leaderName; |
---|
| 357 | uint64 m_mainTank; |
---|
| 358 | uint64 m_mainAssistant; |
---|
| 359 | GroupType m_groupType; |
---|
| 360 | uint8 m_difficulty; |
---|
| 361 | BattleGround* m_bgGroup; |
---|
| 362 | uint64 m_targetIcons[TARGETICONCOUNT]; |
---|
| 363 | LootMethod m_lootMethod; |
---|
| 364 | ItemQualities m_lootThreshold; |
---|
| 365 | uint64 m_looterGuid; |
---|
| 366 | Rolls RollId; |
---|
| 367 | BoundInstancesMap m_boundInstances[TOTAL_DIFFICULTIES]; |
---|
| 368 | }; |
---|
| 369 | #endif |
---|