Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / src / game / BattleGround.h
blob9e41e661b578b531faa5b349ce8e2f49e3e1d0d3
1 /*
2 * Copyright (C) 2005-2008 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 "WorldPacket.h"
24 #include "WorldSession.h"
25 #include "Opcodes.h"
26 #include "ObjectMgr.h"
27 #include "BattleGroundMgr.h"
28 #include "SharedDefines.h"
30 enum BattleGroundSounds
32 SOUND_HORDE_WINS = 8454,
33 SOUND_ALLIANCE_WINS = 8455,
34 SOUND_BG_START = 3439
37 enum BattleGroundQuests
39 SPELL_WS_QUEST_REWARD = 43483,
40 SPELL_AB_QUEST_REWARD = 43484,
41 SPELL_AV_QUEST_REWARD = 43475,
42 SPELL_AV_QUEST_KILLED_BOSS = 23658,
43 SPELL_EY_QUEST_REWARD = 43477,
44 SPELL_AB_QUEST_REWARD_4_BASES = 24061,
45 SPELL_AB_QUEST_REWARD_5_BASES = 24064
48 enum BattleGroundMarks
50 SPELL_WS_MARK_LOSER = 24950,
51 SPELL_WS_MARK_WINNER = 24951,
52 SPELL_AB_MARK_LOSER = 24952,
53 SPELL_AB_MARK_WINNER = 24953,
54 SPELL_AV_MARK_LOSER = 24954,
55 SPELL_AV_MARK_WINNER = 24955,
56 ITEM_EY_MARK_OF_HONOR = 29024
59 enum BattleGroundMarksCount
61 ITEM_WINNER_COUNT = 3,
62 ITEM_LOSER_COUNT = 1
65 enum BattleGroundSpells
67 SPELL_WAITING_FOR_RESURRECT = 2584, // Waiting to Resurrect
68 SPELL_SPIRIT_HEAL_CHANNEL = 22011, // Spirit Heal Channel
69 SPELL_SPIRIT_HEAL = 22012, // Spirit Heal
70 SPELL_RESURRECTION_VISUAL = 24171, // Resurrection Impact Visual
71 SPELL_ARENA_PREPARATION = 32727, // use this one, 32728 not correct
72 SPELL_ALLIANCE_GOLD_FLAG = 32724,
73 SPELL_ALLIANCE_GREEN_FLAG = 32725,
74 SPELL_HORDE_GOLD_FLAG = 35774,
75 SPELL_HORDE_GREEN_FLAG = 35775,
76 SPELL_PREPARATION = 44521, // Preparation
77 SPELL_SPIRIT_HEAL_MANA = 44535, // Spirit Heal
78 SPELL_RECENTLY_DROPPED_FLAG = 42792, // Recently Dropped Flag
79 SPELL_AURA_PLAYER_INACTIVE = 43681 // Inactive
82 enum BattleGroundTimeIntervals
84 RESURRECTION_INTERVAL = 30000, // ms
85 REMIND_INTERVAL = 30000, // ms
86 INVITE_ACCEPT_WAIT_TIME = 120000, // ms
87 TIME_TO_AUTOREMOVE = 120000, // ms
88 MAX_OFFLINE_TIME = 300000, // ms
89 START_DELAY0 = 120000, // ms
90 START_DELAY1 = 60000, // ms
91 START_DELAY2 = 30000, // ms
92 START_DELAY3 = 15000, // ms used only in arena
93 RESPAWN_ONE_DAY = 86400, // secs
94 RESPAWN_IMMEDIATELY = 0, // secs
95 BUFF_RESPAWN_TIME = 180, // secs
96 BG_HONOR_SCORE_TICKS = 330 // points
99 enum BattleGroundBuffObjects
101 BG_OBJECTID_SPEEDBUFF_ENTRY = 179871,
102 BG_OBJECTID_REGENBUFF_ENTRY = 179904,
103 BG_OBJECTID_BERSERKERBUFF_ENTRY = 179905
106 const uint32 Buff_Entries[3] = { BG_OBJECTID_SPEEDBUFF_ENTRY, BG_OBJECTID_REGENBUFF_ENTRY, BG_OBJECTID_BERSERKERBUFF_ENTRY };
108 enum BattleGroundStatus
110 STATUS_NONE = 0,
111 STATUS_WAIT_QUEUE = 1,
112 STATUS_WAIT_JOIN = 2,
113 STATUS_IN_PROGRESS = 3,
114 STATUS_WAIT_LEAVE = 4 // custom
117 struct BattleGroundPlayer
119 uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
120 uint32 Team; // Player's team
123 struct BattleGroundObjectInfo
125 BattleGroundObjectInfo() : object(NULL), timer(0), spellid(0) {}
127 GameObject *object;
128 int32 timer;
129 uint32 spellid;
132 #define MAX_QUEUED_PLAYERS_MAP 7
134 enum BattleGroundTypeId
136 BATTLEGROUND_AV = 1,
137 BATTLEGROUND_WS = 2,
138 BATTLEGROUND_AB = 3,
139 BATTLEGROUND_NA = 4,
140 BATTLEGROUND_BE = 5,
141 BATTLEGROUND_AA = 6,
142 BATTLEGROUND_EY = 7,
143 BATTLEGROUND_RL = 8
146 enum ScoreType
148 SCORE_KILLING_BLOWS = 1,
149 SCORE_DEATHS = 2,
150 SCORE_HONORABLE_KILLS = 3,
151 SCORE_BONUS_HONOR = 4,
152 //EY, but in MSG_PVP_LOG_DATA opcode!
153 SCORE_DAMAGE_DONE = 5,
154 SCORE_HEALING_DONE = 6,
155 //WS
156 SCORE_FLAG_CAPTURES = 7,
157 SCORE_FLAG_RETURNS = 8,
158 //AB
159 SCORE_BASES_ASSAULTED = 9,
160 SCORE_BASES_DEFENDED = 10,
161 //AV
162 SCORE_GRAVEYARDS_ASSAULTED = 11,
163 SCORE_GRAVEYARDS_DEFENDED = 12,
164 SCORE_TOWERS_ASSAULTED = 13,
165 SCORE_TOWERS_DEFENDED = 14,
166 SCORE_MINES_CAPTURED = 15,
167 SCORE_LEADERS_KILLED = 16,
168 SCORE_SECONDARY_OBJECTIVES = 17
169 // TODO : implement them
172 enum ArenaType
174 ARENA_TYPE_2v2 = 2,
175 ARENA_TYPE_3v3 = 3,
176 ARENA_TYPE_5v5 = 5
179 enum BattleGroundType
181 TYPE_BATTLEGROUND = 3,
182 TYPE_ARENA = 4
185 enum BattleGroundWinner
187 WINNER_HORDE = 0,
188 WINNER_ALLIANCE = 1,
189 WINNER_NONE = 2
192 enum BattleGroundTeamId
194 BG_TEAM_ALLIANCE = 0,
195 BG_TEAM_HORDE = 1
198 class BattleGroundScore
200 public:
201 BattleGroundScore() : KillingBlows(0), HonorableKills(0), Deaths(0), DamageDone(0), HealingDone(0), BonusHonor(0) {};
202 virtual ~BattleGroundScore() //virtual destructor is used when deleting score from scores map
205 uint32 KillingBlows;
206 uint32 Deaths;
207 uint32 HonorableKills;
208 uint32 BonusHonor;
209 uint32 DamageDone;
210 uint32 HealingDone;
214 This class is used to:
215 1. Add player to battleground
216 2. Remove player from battleground
217 3. some certain cases, same for all battlegrounds
218 4. It has properties same for all battlegrounds
220 class BattleGround
222 friend class BattleGroundMgr;
224 public:
225 /* Construction */
226 BattleGround();
227 virtual ~BattleGround();
228 virtual void Update(time_t diff); // must be implemented in BG subclass of BG specific update code, but must in begginning call parent version
229 virtual bool SetupBattleGround() // must be implemented in BG subclass
231 return true;
233 void Reset(); // resets all common properties for battlegrounds
234 virtual void ResetBGSubclass() // must be implemented in BG subclass
238 /* Battleground */
239 // Get methods:
240 char const* GetName() const { return m_Name; }
241 uint32 GetTypeID() const { return m_TypeID; }
242 uint32 GetQueueType() const { return m_Queue_type; }
243 uint32 GetInstanceID() const { return m_InstanceID; }
244 uint32 GetStatus() const { return m_Status; }
245 uint32 GetStartTime() const { return m_StartTime; }
246 uint32 GetEndTime() const { return m_EndTime; }
247 uint32 GetLastResurrectTime() const { return m_LastResurrectTime; }
248 uint32 GetMaxPlayers() const { return m_MaxPlayers; }
249 uint32 GetMinPlayers() const { return m_MinPlayers; }
251 uint32 GetMinLevel() const { return m_LevelMin; }
252 uint32 GetMaxLevel() const { return m_LevelMax; }
254 uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayersPerTeam; }
255 uint32 GetMinPlayersPerTeam() const { return m_MinPlayersPerTeam; }
257 int GetStartDelayTime() const { return m_StartDelayTime; }
258 uint8 GetArenaType() const { return m_ArenaType; }
259 uint8 GetWinner() const { return m_Winner; }
260 uint32 GetBattlemasterEntry() const;
262 // Set methods:
263 void SetName(char const* Name) { m_Name = Name; }
264 void SetTypeID(uint32 TypeID) { m_TypeID = TypeID; }
265 void SetQueueType(uint32 ID) { m_Queue_type = ID; }
266 void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; }
267 void SetStatus(uint32 Status) { m_Status = Status; }
268 void SetStartTime(uint32 Time) { m_StartTime = Time; }
269 void SetEndTime(uint32 Time) { m_EndTime = Time; }
270 void SetLastResurrectTime(uint32 Time) { m_LastResurrectTime = Time; }
271 void SetMaxPlayers(uint32 MaxPlayers) { m_MaxPlayers = MaxPlayers; }
272 void SetMinPlayers(uint32 MinPlayers) { m_MinPlayers = MinPlayers; }
273 void SetLevelRange(uint32 min, uint32 max) { m_LevelMin = min; m_LevelMax = max; }
274 void SetRated(bool state) { m_IsRated = state; }
275 void SetArenaType(uint8 type) { m_ArenaType = type; }
276 void SetArenaorBGType(bool _isArena) { m_IsArena = _isArena; }
277 void SetWinner(uint8 winner) { m_Winner = winner; }
279 void ModifyStartDelayTime(int diff) { m_StartDelayTime -= diff; }
280 void SetStartDelayTime(int Time) { m_StartDelayTime = Time; }
282 void SetMaxPlayersPerTeam(uint32 MaxPlayers) { m_MaxPlayersPerTeam = MaxPlayers; }
283 void SetMinPlayersPerTeam(uint32 MinPlayers) { m_MinPlayersPerTeam = MinPlayers; }
285 void AddToBGFreeSlotQueue(); //this queue will be useful when more battlegrounds instances will be available
286 void RemoveFromBGFreeSlotQueue(); //this method could delete whole BG instance, if another free is available
288 void DecreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? --m_InvitedAlliance : --m_InvitedHorde; }
289 void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
290 uint32 GetInvitedCount(uint32 team) const
292 if( team == ALLIANCE )
293 return m_InvitedAlliance;
294 else
295 return m_InvitedHorde;
297 bool HasFreeSlotsForTeam(uint32 Team) const;
298 bool HasFreeSlots() const;
300 bool isArena() const { return m_IsArena; }
301 bool isBattleGround() const { return !m_IsArena; }
302 bool isRated() const { return m_IsRated; }
304 typedef std::map<uint64, BattleGroundPlayer> BattleGroundPlayerMap;
305 BattleGroundPlayerMap const& GetPlayers() const { return m_Players; }
306 uint32 GetPlayersSize() const { return m_Players.size(); }
307 uint32 GetRemovedPlayersSize() const { return m_RemovedPlayers.size(); }
309 std::map<uint64, BattleGroundScore*>::const_iterator GetPlayerScoresBegin() const { return m_PlayerScores.begin(); }
310 std::map<uint64, BattleGroundScore*>::const_iterator GetPlayerScoresEnd() const { return m_PlayerScores.end(); }
311 uint32 GetPlayerScoresSize() const { return m_PlayerScores.size(); }
313 uint32 GetReviveQueueSize() const { return m_ReviveQueue.size(); }
315 void AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid);
316 void RemovePlayerFromResurrectQueue(uint64 player_guid);
318 void StartBattleGround();
320 /* Location */
321 void SetMapId(uint32 MapID) { m_MapId = MapID; }
322 uint32 GetMapId() const { return m_MapId; }
324 void SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, float O);
325 void GetTeamStartLoc(uint32 TeamID, float &X, float &Y, float &Z, float &O) const
327 uint8 idx = GetTeamIndexByTeamId(TeamID);
328 X = m_TeamStartLocX[idx];
329 Y = m_TeamStartLocY[idx];
330 Z = m_TeamStartLocZ[idx];
331 O = m_TeamStartLocO[idx];
334 /* Packet Transfer */
335 // method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
336 virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
337 void SendPacketToTeam(uint32 TeamID, WorldPacket *packet, Player *sender = NULL, bool self = true);
338 void SendPacketToAll(WorldPacket *packet);
339 void PlaySoundToTeam(uint32 SoundID, uint32 TeamID);
340 void PlaySoundToAll(uint32 SoundID);
341 void CastSpellOnTeam(uint32 SpellID, uint32 TeamID);
342 void RewardHonorToTeam(uint32 Honor, uint32 TeamID);
343 void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, uint32 TeamID);
344 void RewardMark(Player *plr,uint32 count);
345 void SendRewardMarkByMail(Player *plr,uint32 mark, uint32 count);
346 void RewardQuest(Player *plr);
347 void UpdateWorldState(uint32 Field, uint32 Value);
348 void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player *Source);
349 void EndBattleGround(uint32 winner);
350 void BlockMovement(Player *plr);
352 void SendMessageToAll(char const* text);
353 void SendMessageToAll(int32 entry);
355 /* Raid Group */
356 Group *GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[BG_TEAM_ALLIANCE] : m_BgRaids[BG_TEAM_HORDE]; }
357 void SetBgRaid(uint32 TeamID, Group *bg_raid)
359 Group* &old_raid = TeamID == ALLIANCE ? m_BgRaids[BG_TEAM_ALLIANCE] : m_BgRaids[BG_TEAM_HORDE];
360 if(old_raid) old_raid->SetBattlegroundGroup(NULL);
361 if(bg_raid) bg_raid->SetBattlegroundGroup(this);
362 old_raid = bg_raid;
365 virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value);
367 uint8 GetTeamIndexByTeamId(uint32 Team) const { return Team == ALLIANCE ? BG_TEAM_ALLIANCE : BG_TEAM_HORDE; }
368 uint32 GetPlayersCountByTeam(uint32 Team) const { return m_PlayersCount[GetTeamIndexByTeamId(Team)]; }
369 void UpdatePlayersCountByTeam(uint32 Team, bool remove)
371 if(remove)
372 --m_PlayersCount[GetTeamIndexByTeamId(Team)];
373 else
374 ++m_PlayersCount[GetTeamIndexByTeamId(Team)];
377 /* Triggers handle */
378 // must be implemented in BG subclass
379 virtual void HandleAreaTrigger(Player* /*Source*/, uint32 /*Trigger*/) {}
380 // must be implemented in BG subclass if need AND call base class generic code
381 virtual void HandleKillPlayer(Player *player, Player *killer);
383 /* Battleground events */
384 /* these functions will return true event is possible, but false if player is bugger */
385 virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
386 virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
387 virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
389 /* Death related */
390 virtual WorldSafeLocsEntry const* GetClosestGraveYard(float /*x*/, float /*y*/, float /*z*/, uint32 /*team*/) { return NULL; }
392 virtual void AddPlayer(Player *plr); // must be implemented in BG subclass
393 virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket);
394 // can be extended in in BG subclass
396 void HandleTriggerBuff(uint64 const& go_guid);
398 // TODO: make this protected:
399 typedef std::vector<uint64> BGObjects;
400 typedef std::vector<uint64> BGCreatures;
401 BGObjects m_BgObjects;
402 BGCreatures m_BgCreatures;
403 void SpawnBGObject(uint32 type, uint32 respawntime);
404 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);
405 Creature* AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o);
406 bool DelCreature(uint32 type);
407 bool DelObject(uint32 type);
408 bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team);
410 void DoorOpen(uint32 type);
411 void DoorClose(uint32 type);
412 const char *GetMangosString(int32 entry);
414 protected:
415 //this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends BattleGround
416 void EndNow();
418 /* Scorekeeping */
419 // Player scores
420 std::map<uint64, BattleGroundScore*> m_PlayerScores;
421 // must be implemented in BG subclass
422 virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
424 /* Player lists, those need to be accessible by inherited classes */
425 BattleGroundPlayerMap m_Players;
426 // Spirit Guide guid + Player list GUIDS
427 std::map<uint64, std::vector<uint64> > m_ReviveQueue;
430 this is important variable used for invitation messages
432 uint8 m_Events;
434 bool m_BuffChange;
436 private:
437 /* Battleground */
438 uint32 m_TypeID; //Battleground type, defined in enum BattleGroundTypeId
439 uint32 m_InstanceID; //BattleGround Instance's GUID!
440 uint32 m_Status;
441 uint32 m_StartTime;
442 uint32 m_EndTime;
443 uint32 m_LastResurrectTime;
444 uint32 m_Queue_type;
445 uint8 m_ArenaType; // 2=2v2, 3=3v3, 5=5v5
446 // this variable is not used .... it can be found in many other ways... but to store it in BG object instance is useless
447 //uint8 m_BattleGroundType; // 3=BG, 4=arena
448 //instead of uint8 (in previous line) is bool used
449 bool m_IsArena;
450 uint8 m_Winner; // 0=alliance, 1=horde, 2=none
451 int32 m_StartDelayTime;
452 bool m_IsRated; // is this battle rated?
453 char const *m_Name;
455 /* Player lists */
456 std::vector<uint64> m_ResurrectQueue; // Player GUID
457 std::map<uint64, uint8> m_RemovedPlayers; // uint8 is remove type (0 - bgqueue, 1 - bg, 2 - resurrect queue)
459 /* 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 */
460 /* Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG */
461 /* Invited players counters*/
462 uint32 m_InvitedAlliance;
463 uint32 m_InvitedHorde;
465 /* Raid Group */
466 Group *m_BgRaids[2]; // 0 - alliance, 1 - horde
468 /* Players count by team */
469 uint32 m_PlayersCount[2];
471 /* Limits */
472 uint32 m_LevelMin;
473 uint32 m_LevelMax;
474 uint32 m_MaxPlayersPerTeam;
475 uint32 m_MaxPlayers;
476 uint32 m_MinPlayersPerTeam;
477 uint32 m_MinPlayers;
479 /* Location */
480 uint32 m_MapId;
481 float m_TeamStartLocX[2];
482 float m_TeamStartLocY[2];
483 float m_TeamStartLocZ[2];
484 float m_TeamStartLocO[2];
486 #endif