allow .goname and .namego in more battleground cases
[getmangos.git] / src / game / BattleGround.h
blob4ae78a3453259fe14ccb688eaa35017e6abe9040
1 /*
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 __BATTLEGROUND_H
20 #define __BATTLEGROUND_H
22 #include "Common.h"
23 #include "SharedDefines.h"
25 class Creature;
26 class GameObject;
27 class Group;
28 class Player;
29 class WorldPacket;
31 struct WorldSafeLocsEntry;
33 enum BattleGroundSounds
35 SOUND_HORDE_WINS = 8454,
36 SOUND_ALLIANCE_WINS = 8455,
37 SOUND_BG_START = 3439
40 enum BattleGroundQuests
42 SPELL_WS_QUEST_REWARD = 43483,
43 SPELL_AB_QUEST_REWARD = 43484,
44 SPELL_AV_QUEST_REWARD = 43475,
45 SPELL_AV_QUEST_KILLED_BOSS = 23658,
46 SPELL_EY_QUEST_REWARD = 43477,
47 SPELL_AB_QUEST_REWARD_4_BASES = 24061,
48 SPELL_AB_QUEST_REWARD_5_BASES = 24064
51 enum BattleGroundMarks
53 SPELL_WS_MARK_LOSER = 24950,
54 SPELL_WS_MARK_WINNER = 24951,
55 SPELL_AB_MARK_LOSER = 24952,
56 SPELL_AB_MARK_WINNER = 24953,
57 SPELL_AV_MARK_LOSER = 24954,
58 SPELL_AV_MARK_WINNER = 24955,
59 ITEM_EY_MARK_OF_HONOR = 29024
62 enum BattleGroundMarksCount
64 ITEM_WINNER_COUNT = 3,
65 ITEM_LOSER_COUNT = 1
68 enum BattleGroundSpells
70 SPELL_WAITING_FOR_RESURRECT = 2584, // Waiting to Resurrect
71 SPELL_SPIRIT_HEAL_CHANNEL = 22011, // Spirit Heal Channel
72 SPELL_SPIRIT_HEAL = 22012, // Spirit Heal
73 SPELL_RESURRECTION_VISUAL = 24171, // Resurrection Impact Visual
74 SPELL_ARENA_PREPARATION = 32727, // use this one, 32728 not correct
75 SPELL_ALLIANCE_GOLD_FLAG = 32724,
76 SPELL_ALLIANCE_GREEN_FLAG = 32725,
77 SPELL_HORDE_GOLD_FLAG = 35774,
78 SPELL_HORDE_GREEN_FLAG = 35775,
79 SPELL_PREPARATION = 44521, // Preparation
80 SPELL_SPIRIT_HEAL_MANA = 44535, // Spirit Heal
81 SPELL_RECENTLY_DROPPED_FLAG = 42792, // Recently Dropped Flag
82 SPELL_AURA_PLAYER_INACTIVE = 43681 // Inactive
85 enum BattleGroundTimeIntervals
87 RESURRECTION_INTERVAL = 30000, // ms
88 REMIND_INTERVAL = 30000, // ms
89 INVITE_ACCEPT_WAIT_TIME = 80000, // ms
90 TIME_TO_AUTOREMOVE = 120000, // ms
91 MAX_OFFLINE_TIME = 300000, // ms
92 START_DELAY0 = 120000, // ms
93 START_DELAY1 = 60000, // ms
94 START_DELAY2 = 30000, // ms
95 START_DELAY3 = 15000, // ms used only in arena
96 RESPAWN_ONE_DAY = 86400, // secs
97 RESPAWN_IMMEDIATELY = 0, // secs
98 BUFF_RESPAWN_TIME = 180, // secs
99 BG_HONOR_SCORE_TICKS = 330 // points
102 enum BattleGroundBuffObjects
104 BG_OBJECTID_SPEEDBUFF_ENTRY = 179871,
105 BG_OBJECTID_REGENBUFF_ENTRY = 179904,
106 BG_OBJECTID_BERSERKERBUFF_ENTRY = 179905
109 const uint32 Buff_Entries[3] = { BG_OBJECTID_SPEEDBUFF_ENTRY, BG_OBJECTID_REGENBUFF_ENTRY, BG_OBJECTID_BERSERKERBUFF_ENTRY };
111 enum BattleGroundStatus
113 STATUS_NONE = 0,
114 STATUS_WAIT_QUEUE = 1,
115 STATUS_WAIT_JOIN = 2,
116 STATUS_IN_PROGRESS = 3,
117 STATUS_WAIT_LEAVE = 4 // custom
120 struct BattleGroundPlayer
122 uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
123 uint32 Team; // Player's team
126 struct BattleGroundObjectInfo
128 BattleGroundObjectInfo() : object(NULL), timer(0), spellid(0) {}
130 GameObject *object;
131 int32 timer;
132 uint32 spellid;
135 // handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time
136 enum BattleGroundQueueTypeId
138 BATTLEGROUND_QUEUE_AV = 1,
139 BATTLEGROUND_QUEUE_WS = 2,
140 BATTLEGROUND_QUEUE_AB = 3,
141 BATTLEGROUND_QUEUE_EY = 4,
142 BATTLEGROUND_QUEUE_SA = 5,
143 BATTLEGROUND_QUEUE_2v2 = 6,
144 BATTLEGROUND_QUEUE_3v3 = 7,
145 BATTLEGROUND_QUEUE_5v5 = 8,
148 enum ScoreType
150 SCORE_KILLING_BLOWS = 1,
151 SCORE_DEATHS = 2,
152 SCORE_HONORABLE_KILLS = 3,
153 SCORE_BONUS_HONOR = 4,
154 //EY, but in MSG_PVP_LOG_DATA opcode!
155 SCORE_DAMAGE_DONE = 5,
156 SCORE_HEALING_DONE = 6,
157 //WS
158 SCORE_FLAG_CAPTURES = 7,
159 SCORE_FLAG_RETURNS = 8,
160 //AB
161 SCORE_BASES_ASSAULTED = 9,
162 SCORE_BASES_DEFENDED = 10,
163 //AV
164 SCORE_GRAVEYARDS_ASSAULTED = 11,
165 SCORE_GRAVEYARDS_DEFENDED = 12,
166 SCORE_TOWERS_ASSAULTED = 13,
167 SCORE_TOWERS_DEFENDED = 14,
168 SCORE_MINES_CAPTURED = 15,
169 SCORE_LEADERS_KILLED = 16,
170 SCORE_SECONDARY_OBJECTIVES = 17
171 // TODO : implement them
174 enum ArenaType
176 ARENA_TYPE_2v2 = 2,
177 ARENA_TYPE_3v3 = 3,
178 ARENA_TYPE_5v5 = 5
181 enum BattleGroundType
183 TYPE_BATTLEGROUND = 3,
184 TYPE_ARENA = 4
187 enum BattleGroundWinner
189 WINNER_HORDE = 0,
190 WINNER_ALLIANCE = 1,
191 WINNER_NONE = 2
194 enum BattleGroundTeamId
196 BG_TEAM_ALLIANCE = 0,
197 BG_TEAM_HORDE = 1
200 enum BattleGroundJoinError
202 BG_JOIN_ERR_OK = 0,
203 BG_JOIN_ERR_OFFLINE_MEMBER = 1,
204 BG_JOIN_ERR_GROUP_TOO_MANY = 2,
205 BG_JOIN_ERR_MIXED_FACTION = 3,
206 BG_JOIN_ERR_MIXED_LEVELS = 4,
207 BG_JOIN_ERR_MIXED_ARENATEAM = 5,
208 BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE = 6,
209 BG_JOIN_ERR_GROUP_DESERTER = 7,
210 BG_JOIN_ERR_ALL_QUEUES_USED = 8,
211 BG_JOIN_ERR_GROUP_NOT_ENOUGH = 9
214 class BattleGroundScore
216 public:
217 BattleGroundScore() : KillingBlows(0), HonorableKills(0), Deaths(0), DamageDone(0), HealingDone(0), BonusHonor(0) {};
218 virtual ~BattleGroundScore() //virtual destructor is used when deleting score from scores map
221 uint32 KillingBlows;
222 uint32 Deaths;
223 uint32 HonorableKills;
224 uint32 BonusHonor;
225 uint32 DamageDone;
226 uint32 HealingDone;
230 This class is used to:
231 1. Add player to battleground
232 2. Remove player from battleground
233 3. some certain cases, same for all battlegrounds
234 4. It has properties same for all battlegrounds
236 class BattleGround
238 friend class BattleGroundMgr;
240 public:
241 /* Construction */
242 BattleGround();
243 /*BattleGround(const BattleGround& bg);*/
244 virtual ~BattleGround();
245 virtual void Update(uint32 diff); // must be implemented in BG subclass of BG specific update code, but must in begginning call parent version
246 virtual bool SetupBattleGround() // must be implemented in BG subclass
248 return true;
250 void Reset(); // resets all common properties for battlegrounds
251 virtual void ResetBGSubclass() // must be implemented in BG subclass
255 /* Battleground */
256 // Get methods:
257 char const* GetName() const { return m_Name; }
258 BattleGroundTypeId GetTypeID() const { return m_TypeID; }
259 uint32 GetQueueType() const { return m_Queue_type; }
260 uint32 GetInstanceID() const { return m_InstanceID; }
261 uint32 GetStatus() const { return m_Status; }
262 uint32 GetStartTime() const { return m_StartTime; }
263 uint32 GetEndTime() const { return m_EndTime; }
264 uint32 GetLastResurrectTime() const { return m_LastResurrectTime; }
265 uint32 GetMaxPlayers() const { return m_MaxPlayers; }
266 uint32 GetMinPlayers() const { return m_MinPlayers; }
268 uint32 GetMinLevel() const { return m_LevelMin; }
269 uint32 GetMaxLevel() const { return m_LevelMax; }
271 uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayersPerTeam; }
272 uint32 GetMinPlayersPerTeam() const { return m_MinPlayersPerTeam; }
274 int GetStartDelayTime() const { return m_StartDelayTime; }
275 uint8 GetArenaType() const { return m_ArenaType; }
276 uint8 GetWinner() const { return m_Winner; }
277 uint32 GetBattlemasterEntry() const;
279 // Set methods:
280 void SetName(char const* Name) { m_Name = Name; }
281 void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; }
282 void SetQueueType(uint32 ID) { m_Queue_type = ID; }
283 void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; }
284 void SetStatus(uint32 Status) { m_Status = Status; }
285 void SetStartTime(uint32 Time) { m_StartTime = Time; }
286 void SetEndTime(uint32 Time) { m_EndTime = Time; }
287 void SetLastResurrectTime(uint32 Time) { m_LastResurrectTime = Time; }
288 void SetMaxPlayers(uint32 MaxPlayers) { m_MaxPlayers = MaxPlayers; }
289 void SetMinPlayers(uint32 MinPlayers) { m_MinPlayers = MinPlayers; }
290 void SetLevelRange(uint32 min, uint32 max) { m_LevelMin = min; m_LevelMax = max; }
291 void SetRated(bool state) { m_IsRated = state; }
292 void SetArenaType(uint8 type) { m_ArenaType = type; }
293 void SetArenaorBGType(bool _isArena) { m_IsArena = _isArena; }
294 void SetWinner(uint8 winner) { m_Winner = winner; }
296 void ModifyStartDelayTime(int diff) { m_StartDelayTime -= diff; }
297 void SetStartDelayTime(int Time) { m_StartDelayTime = Time; }
299 void SetMaxPlayersPerTeam(uint32 MaxPlayers) { m_MaxPlayersPerTeam = MaxPlayers; }
300 void SetMinPlayersPerTeam(uint32 MinPlayers) { m_MinPlayersPerTeam = MinPlayers; }
302 void AddToBGFreeSlotQueue(); //this queue will be useful when more battlegrounds instances will be available
303 void RemoveFromBGFreeSlotQueue(); //this method could delete whole BG instance, if another free is available
305 void DecreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? --m_InvitedAlliance : --m_InvitedHorde; }
306 void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
307 uint32 GetInvitedCount(uint32 team) const
309 if( team == ALLIANCE )
310 return m_InvitedAlliance;
311 else
312 return m_InvitedHorde;
314 bool HasFreeSlotsForTeam(uint32 Team) const;
315 bool HasFreeSlots() const;
316 uint32 GetFreeSlotsForTeam(uint32 Team) const;
318 bool isArena() const { return m_IsArena; }
319 bool isBattleGround() const { return !m_IsArena; }
320 bool isRated() const { return m_IsRated; }
322 typedef std::map<uint64, BattleGroundPlayer> BattleGroundPlayerMap;
323 BattleGroundPlayerMap const& GetPlayers() const { return m_Players; }
324 uint32 GetPlayersSize() const { return m_Players.size(); }
325 uint32 GetRemovedPlayersSize() const { return m_RemovedPlayers.size(); }
327 std::map<uint64, BattleGroundScore*>::const_iterator GetPlayerScoresBegin() const { return m_PlayerScores.begin(); }
328 std::map<uint64, BattleGroundScore*>::const_iterator GetPlayerScoresEnd() const { return m_PlayerScores.end(); }
329 uint32 GetPlayerScoresSize() const { return m_PlayerScores.size(); }
331 uint32 GetReviveQueueSize() const { return m_ReviveQueue.size(); }
333 void AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid);
334 void RemovePlayerFromResurrectQueue(uint64 player_guid);
336 void StartBattleGround();
338 /* Location */
339 void SetMapId(uint32 MapID) { m_MapId = MapID; }
340 uint32 GetMapId() const { return m_MapId; }
342 void SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, float O);
343 void GetTeamStartLoc(uint32 TeamID, float &X, float &Y, float &Z, float &O) const
345 uint8 idx = GetTeamIndexByTeamId(TeamID);
346 X = m_TeamStartLocX[idx];
347 Y = m_TeamStartLocY[idx];
348 Z = m_TeamStartLocZ[idx];
349 O = m_TeamStartLocO[idx];
352 /* Packet Transfer */
353 // method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
354 virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
355 void SendPacketToTeam(uint32 TeamID, WorldPacket *packet, Player *sender = NULL, bool self = true);
356 void SendPacketToAll(WorldPacket *packet);
357 void PlaySoundToTeam(uint32 SoundID, uint32 TeamID);
358 void PlaySoundToAll(uint32 SoundID);
359 void CastSpellOnTeam(uint32 SpellID, uint32 TeamID);
360 void RewardHonorToTeam(uint32 Honor, uint32 TeamID);
361 void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, uint32 TeamID);
362 void RewardMark(Player *plr,uint32 count);
363 void SendRewardMarkByMail(Player *plr,uint32 mark, uint32 count);
364 void RewardQuest(Player *plr);
365 void UpdateWorldState(uint32 Field, uint32 Value);
366 void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player *Source);
367 void EndBattleGround(uint32 winner);
368 void BlockMovement(Player *plr);
370 void SendMessageToAll(char const* text);
371 void SendMessageToAll(int32 entry);
373 /* Raid Group */
374 Group *GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[BG_TEAM_ALLIANCE] : m_BgRaids[BG_TEAM_HORDE]; }
375 void SetBgRaid(uint32 TeamID, Group *bg_raid);
377 virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value);
379 uint8 GetTeamIndexByTeamId(uint32 Team) const { return Team == ALLIANCE ? BG_TEAM_ALLIANCE : BG_TEAM_HORDE; }
380 uint32 GetPlayersCountByTeam(uint32 Team) const { return m_PlayersCount[GetTeamIndexByTeamId(Team)]; }
381 uint32 GetAlivePlayersCountByTeam(uint32 Team) const; // used in arenas to correctly handle death in spirit of redemption / last stand etc. (killer = killed) cases
382 void UpdatePlayersCountByTeam(uint32 Team, bool remove)
384 if(remove)
385 --m_PlayersCount[GetTeamIndexByTeamId(Team)];
386 else
387 ++m_PlayersCount[GetTeamIndexByTeamId(Team)];
390 // used for rated arena battles
391 void SetArenaTeamIdForTeam(uint32 Team, uint32 ArenaTeamId) { m_ArenaTeamIds[GetTeamIndexByTeamId(Team)] = ArenaTeamId; }
392 uint32 GetArenaTeamIdForTeam(uint32 Team) const { return m_ArenaTeamIds[GetTeamIndexByTeamId(Team)]; }
393 void SetArenaTeamRatingChangeForTeam(uint32 Team, int32 RatingChange) { m_ArenaTeamRatingChanges[GetTeamIndexByTeamId(Team)] = RatingChange; }
394 int32 GetArenaTeamRatingChangeForTeam(uint32 Team) const { return m_ArenaTeamRatingChanges[GetTeamIndexByTeamId(Team)]; }
396 /* Triggers handle */
397 // must be implemented in BG subclass
398 virtual void HandleAreaTrigger(Player* /*Source*/, uint32 /*Trigger*/) {}
399 // must be implemented in BG subclass if need AND call base class generic code
400 virtual void HandleKillPlayer(Player *player, Player *killer);
402 /* Battleground events */
403 /* these functions will return true event is possible, but false if player is bugger */
404 virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
405 virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
406 virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
408 /* Death related */
409 virtual WorldSafeLocsEntry const* GetClosestGraveYard(float /*x*/, float /*y*/, float /*z*/, uint32 /*team*/) { return NULL; }
411 virtual void AddPlayer(Player *plr); // must be implemented in BG subclass
413 virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket);
414 // can be extended in in BG subclass
416 void HandleTriggerBuff(uint64 const& go_guid);
418 // TODO: make this protected:
419 typedef std::vector<uint64> BGObjects;
420 typedef std::vector<uint64> BGCreatures;
421 BGObjects m_BgObjects;
422 BGCreatures m_BgCreatures;
423 void SpawnBGObject(uint32 type, uint32 respawntime);
424 bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime = 0);
425 // void SpawnBGCreature(uint32 type, uint32 respawntime);
426 Creature* AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o, uint32 respawntime = 0);
427 bool DelCreature(uint32 type);
428 bool DelObject(uint32 type);
429 bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team);
431 void DoorOpen(uint32 type);
432 void DoorClose(uint32 type);
433 const char *GetMangosString(int32 entry);
435 virtual bool HandlePlayerUnderMap(Player * plr) {return false;}
437 // since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
438 uint32 GetPlayerTeam(uint64 guid);
440 void SetDeleteThis() {m_SetDeleteThis = true;}
442 protected:
443 //this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends BattleGround
444 void EndNow();
446 /* Scorekeeping */
447 // Player scores
448 std::map<uint64, BattleGroundScore*> m_PlayerScores;
449 // must be implemented in BG subclass
450 virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
452 /* Player lists, those need to be accessible by inherited classes */
453 BattleGroundPlayerMap m_Players;
454 // Spirit Guide guid + Player list GUIDS
455 std::map<uint64, std::vector<uint64> > m_ReviveQueue;
458 this is important variable used for invitation messages
460 uint8 m_Events;
462 bool m_BuffChange;
464 private:
465 /* Battleground */
466 BattleGroundTypeId m_TypeID;
467 uint32 m_InstanceID; //BattleGround Instance's GUID!
468 uint32 m_Status;
469 uint32 m_StartTime;
470 uint32 m_EndTime;
471 uint32 m_LastResurrectTime;
472 uint32 m_Queue_type;
473 uint8 m_ArenaType; // 2=2v2, 3=3v3, 5=5v5
474 bool m_InBGFreeSlotQueue; // used to make sure that BG is only once inserted into the BattleGroundMgr.BGFreeSlotQueue[bgTypeId] deque
475 bool m_SetDeleteThis; // used for safe deletion of the bg after end / all players leave
476 // this variable is not used .... it can be found in many other ways... but to store it in BG object instance is useless
477 //uint8 m_BattleGroundType; // 3=BG, 4=arena
478 //instead of uint8 (in previous line) is bool used
479 bool m_IsArena;
480 uint8 m_Winner; // 0=alliance, 1=horde, 2=none
481 int32 m_StartDelayTime;
482 bool m_IsRated; // is this battle rated?
483 bool m_PrematureCountDown;
484 uint32 m_PrematureCountDownTimer;
485 char const *m_Name;
487 /* Player lists */
488 std::vector<uint64> m_ResurrectQueue; // Player GUID
489 std::map<uint64, uint8> m_RemovedPlayers; // uint8 is remove type (0 - bgqueue, 1 - bg, 2 - resurrect queue)
491 /* Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction */
492 /* Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG */
493 /* Invited players counters*/
494 uint32 m_InvitedAlliance;
495 uint32 m_InvitedHorde;
497 /* Raid Group */
498 Group *m_BgRaids[2]; // 0 - alliance, 1 - horde
500 /* Players count by team */
501 uint32 m_PlayersCount[2];
503 /* Arena team ids by team */
504 uint32 m_ArenaTeamIds[2];
506 int32 m_ArenaTeamRatingChanges[2];
508 /* Limits */
509 uint32 m_LevelMin;
510 uint32 m_LevelMax;
511 uint32 m_MaxPlayersPerTeam;
512 uint32 m_MaxPlayers;
513 uint32 m_MinPlayersPerTeam;
514 uint32 m_MinPlayers;
516 /* Location */
517 uint32 m_MapId;
518 float m_TeamStartLocX[2];
519 float m_TeamStartLocY[2];
520 float m_TeamStartLocZ[2];
521 float m_TeamStartLocO[2];
523 #endif