Guest User

BattleGround.h

a guest
Dec 26th, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.23 KB | None | 0 0
  1. /**
  2. * This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
  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 __BATTLEGROUND_H
  20. #define __BATTLEGROUND_H
  21.  
  22. #include "Common.h"
  23. #include "SharedDefines.h"
  24. #include "Map.h"
  25. #include "ByteBuffer.h"
  26. #include "ObjectGuid.h"
  27.  
  28. // magic event-numbers
  29. #define BG_EVENT_NONE 255
  30. // those generic events should get a high event id
  31. #define BG_EVENT_DOOR 254
  32. // only arena event
  33. // cause this buff apears 90sec after start in every bg i implement it here
  34. #define ARENA_BUFF_EVENT 253
  35.  
  36.  
  37. class Creature;
  38. class GameObject;
  39. class Group;
  40. class Player;
  41. class WorldPacket;
  42. class BattleGroundMap;
  43.  
  44. struct WorldSafeLocsEntry;
  45.  
  46. struct BattleGroundEventIdx
  47. {
  48.     uint8 event1;
  49.     uint8 event2;
  50. };
  51.  
  52. enum BattleGroundSounds
  53. {
  54.     SOUND_HORDE_WINS = 8454,
  55.     SOUND_ALLIANCE_WINS = 8455,
  56.     SOUND_BG_START = 3439
  57. };
  58.  
  59. enum BattleGroundQuests
  60. {
  61.     SPELL_WS_QUEST_REWARD = 43483,
  62.     SPELL_AB_QUEST_REWARD = 43484,
  63.     SPELL_AV_QUEST_REWARD = 43475,
  64.     SPELL_AV_QUEST_KILLED_BOSS = 23658,
  65.     SPELL_EY_QUEST_REWARD = 43477,
  66.     SPELL_AB_QUEST_REWARD_4_BASES = 24061,
  67.     SPELL_AB_QUEST_REWARD_5_BASES = 24064
  68. };
  69.  
  70. enum BattleGroundMarks
  71. {
  72.     SPELL_WS_MARK_LOSER = 24950,
  73.     SPELL_WS_MARK_WINNER = 24951,
  74.     SPELL_AB_MARK_LOSER = 24952,
  75.     SPELL_AB_MARK_WINNER = 24953,
  76.     SPELL_AV_MARK_LOSER = 24954,
  77.     SPELL_AV_MARK_WINNER = 24955,
  78.     ITEM_EY_MARK_OF_HONOR = 29024
  79. };
  80.  
  81. enum BattleGroundMarksCount
  82. {
  83.     ITEM_WINNER_COUNT = 3,
  84.     ITEM_LOSER_COUNT = 1
  85. };
  86.  
  87. enum BattleGroundSpells
  88. {
  89.     SPELL_ARENA_PREPARATION = 32727, // use this one, 32728 not correct
  90.     SPELL_ALLIANCE_GOLD_FLAG = 32724,
  91.     SPELL_ALLIANCE_GREEN_FLAG = 32725,
  92.     SPELL_HORDE_GOLD_FLAG = 35774,
  93.     SPELL_HORDE_GREEN_FLAG = 35775,
  94.     SPELL_PREPARATION = 44521, // Preparation
  95.     SPELL_RECENTLY_DROPPED_FLAG = 42792, // Recently Dropped Flag
  96.     SPELL_AURA_PLAYER_INACTIVE = 43681 // Inactive
  97. };
  98.  
  99. enum BattleGroundTimeIntervals
  100. {
  101.     RESURRECTION_INTERVAL = 30000, // ms
  102.     INVITATION_REMIND_TIME = 60000, // ms
  103.     INVITE_ACCEPT_WAIT_TIME = 80000, // ms
  104.     TIME_TO_AUTOREMOVE = 120000, // ms
  105.     MAX_OFFLINE_TIME = 300, // secs
  106.     RESPAWN_ONE_DAY = 86400, // secs
  107.     RESPAWN_IMMEDIATELY = 0, // secs
  108.     BUFF_RESPAWN_TIME = 180, // secs
  109.     ARENA_SPAWN_BUFF_OBJECTS = 90000, // ms - 90sec after start
  110. };
  111.  
  112. enum BattleGroundStartTimeIntervals
  113. {
  114.     BG_START_DELAY_2M = 120000, // ms (2 minutes)
  115.     BG_START_DELAY_1M = 60000, // ms (1 minute)
  116.     BG_START_DELAY_30S = 30000, // ms (30 seconds)
  117.     BG_START_DELAY_15S = 15000, // ms (15 seconds) Used only in arena
  118.     BG_START_DELAY_NONE = 0, // ms
  119. };
  120.  
  121. enum BattleGroundBuffObjects
  122. {
  123.     BG_OBJECTID_SPEEDBUFF_ENTRY = 179871,
  124.     BG_OBJECTID_REGENBUFF_ENTRY = 179904,
  125.     BG_OBJECTID_BERSERKERBUFF_ENTRY = 179905
  126. };
  127.  
  128. const uint32 Buff_Entries[3] = { BG_OBJECTID_SPEEDBUFF_ENTRY, BG_OBJECTID_REGENBUFF_ENTRY, BG_OBJECTID_BERSERKERBUFF_ENTRY };
  129.  
  130. enum BattleGroundStatus
  131. {
  132.     STATUS_NONE = 0, // first status, should mean bg is not instance
  133.     STATUS_WAIT_QUEUE = 1, // means bg is empty and waiting for queue
  134.     STATUS_WAIT_JOIN = 2, // this means, that BG has already started and it is waiting for more players
  135.     STATUS_IN_PROGRESS = 3, // means bg is running
  136.     STATUS_WAIT_LEAVE = 4 // means some faction has won BG and it is ending
  137. };
  138.  
  139. struct BattleGroundPlayer
  140. {
  141.     time_t OfflineRemoveTime; // for tracking and removing offline players from queue after 5 minutes
  142.     Team PlayerTeam; // Player's team
  143. };
  144.  
  145. struct BattleGroundObjectInfo
  146. {
  147.     BattleGroundObjectInfo() : object(NULL), timer(0), spellid(0) {}
  148.  
  149.     GameObject* object;
  150.     int32 timer;
  151.     uint32 spellid;
  152. };
  153.  
  154. // handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time
  155. enum BattleGroundQueueTypeId
  156. {
  157.     BATTLEGROUND_QUEUE_NONE = 0,
  158.     BATTLEGROUND_QUEUE_AV = 1,
  159.     BATTLEGROUND_QUEUE_WS = 2,
  160.     BATTLEGROUND_QUEUE_AB = 3,
  161.     BATTLEGROUND_QUEUE_EY = 4,
  162.     BATTLEGROUND_QUEUE_2v2 = 5,
  163.     BATTLEGROUND_QUEUE_3v3 = 6,
  164.     BATTLEGROUND_QUEUE_5v5 = 7,
  165. };
  166. #define MAX_BATTLEGROUND_QUEUE_TYPES 8
  167.  
  168. enum BattleGroundBracketId // bracketId for level ranges
  169. {
  170.     BG_BRACKET_ID_TEMPLATE = -1, // used to mark bg as template
  171.     BG_BRACKET_ID_FIRST = 0, // brackets start from specific BG min level and each include 10 levels range
  172.     BG_BRACKET_ID_LAST = 6, // so for start level 10 will be 10-19, 20-29, ... all greater max bg level included in last breaket
  173. };
  174.  
  175. #define MAX_BATTLEGROUND_BRACKETS 7
  176.  
  177. enum ScoreType
  178. {
  179.     SCORE_KILLING_BLOWS = 1,
  180.     SCORE_DEATHS = 2,
  181.     SCORE_HONORABLE_KILLS = 3,
  182.     SCORE_BONUS_HONOR = 4,
  183.     // EY, but in MSG_PVP_LOG_DATA opcode!
  184.     SCORE_DAMAGE_DONE = 5,
  185.     SCORE_HEALING_DONE = 6,
  186.     // WS
  187.     SCORE_FLAG_CAPTURES = 7,
  188.     SCORE_FLAG_RETURNS = 8,
  189.     // AB
  190.     SCORE_BASES_ASSAULTED = 9,
  191.     SCORE_BASES_DEFENDED = 10,
  192.     // AV
  193.     SCORE_GRAVEYARDS_ASSAULTED = 11,
  194.     SCORE_GRAVEYARDS_DEFENDED = 12,
  195.     SCORE_TOWERS_ASSAULTED = 13,
  196.     SCORE_TOWERS_DEFENDED = 14,
  197.     SCORE_SECONDARY_OBJECTIVES = 15
  198. };
  199.  
  200. enum BattleGroundType
  201. {
  202.     TYPE_BATTLEGROUND = 3,
  203.     TYPE_ARENA = 4
  204. };
  205.  
  206. enum BattleGroundTeamIndex
  207. {
  208.     BG_TEAM_ALLIANCE = 0,
  209.     BG_TEAM_HORDE = 1
  210. };
  211.  
  212. #define BG_TEAMS_COUNT 2
  213.  
  214. enum BattleGroundStartingEvents
  215. {
  216.     BG_STARTING_EVENT_NONE = 0x00,
  217.     BG_STARTING_EVENT_1 = 0x01,
  218.     BG_STARTING_EVENT_2 = 0x02,
  219.     BG_STARTING_EVENT_3 = 0x04,
  220.     BG_STARTING_EVENT_4 = 0x08
  221. };
  222.  
  223. enum BattleGroundStartingEventsIds
  224. {
  225.     BG_STARTING_EVENT_FIRST = 0,
  226.     BG_STARTING_EVENT_SECOND = 1,
  227.     BG_STARTING_EVENT_THIRD = 2,
  228.     BG_STARTING_EVENT_FOURTH = 3
  229. };
  230. #define BG_STARTING_EVENT_COUNT 4
  231.  
  232. enum BattleGroundJoinError
  233. {
  234.     BG_JOIN_ERR_OK = 0,
  235.     BG_JOIN_ERR_OFFLINE_MEMBER = 1,
  236.     BG_JOIN_ERR_GROUP_TOO_MANY = 2,
  237.     BG_JOIN_ERR_MIXED_FACTION = 3,
  238.     BG_JOIN_ERR_MIXED_LEVELS = 4,
  239.     BG_JOIN_ERR_MIXED_ARENATEAM = 5,
  240.     BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE = 6,
  241.     BG_JOIN_ERR_GROUP_DESERTER = 7,
  242.     BG_JOIN_ERR_ALL_QUEUES_USED = 8,
  243.     BG_JOIN_ERR_GROUP_NOT_ENOUGH = 9
  244. };
  245.  
  246. class BattleGroundScore
  247. {
  248.     public:
  249.         BattleGroundScore() : KillingBlows(0), Deaths(0), HonorableKills(0),
  250.             BonusHonor(0), DamageDone(0), HealingDone(0)
  251.         {}
  252.         virtual ~BattleGroundScore() {} // virtual destructor is used when deleting score from scores map
  253.  
  254.         uint32 KillingBlows;
  255.         uint32 Deaths;
  256.         uint32 HonorableKills;
  257.         uint32 BonusHonor;
  258.         uint32 DamageDone;
  259.         uint32 HealingDone;
  260. };
  261.  
  262. /*
  263. This class is used to:
  264. 1. Add player to battleground
  265. 2. Remove player from battleground
  266. 3. some certain cases, same for all battlegrounds
  267. 4. It has properties same for all battlegrounds
  268. */
  269. class BattleGround
  270. {
  271.         friend class BattleGroundMgr;
  272.  
  273.     public:
  274.         /* Construction */
  275.         BattleGround();
  276.         /*BattleGround(const BattleGround& bg);*/
  277.         virtual ~BattleGround();
  278.         virtual void Update(uint32 diff); // must be implemented in BG subclass of BG specific update code, but must in begginning call parent version
  279.         virtual void Reset(); // resets all common properties for battlegrounds, must be implemented and called in BG subclass
  280.         virtual void StartingEventCloseDoors() {}
  281.         virtual void StartingEventOpenDoors() {}
  282.  
  283.         /* Battleground */
  284.         // Get methods:
  285.         char const* GetName() const { return m_Name; }
  286.         BattleGroundTypeId GetTypeID() const { return m_TypeID; }
  287.         BattleGroundBracketId GetBracketId() const { return m_BracketId; }
  288.         // the instanceId check is also used to determine a bg-template
  289.         // that's why the m_map hack is here..
  290.         uint32 GetInstanceID() { return m_Map ? GetBgMap()->GetInstanceId() : 0; }
  291.         BattleGroundStatus GetStatus() const { return m_Status; }
  292.         uint32 GetClientInstanceID() const { return m_ClientInstanceID; }
  293.         uint32 GetStartTime() const { return m_StartTime; }
  294.         uint32 GetEndTime() const { return m_EndTime; }
  295.         uint32 GetMaxPlayers() const { return m_MaxPlayers; }
  296.         uint32 GetMinPlayers() const { return m_MinPlayers; }
  297.  
  298.         uint32 GetMinLevel() const { return m_LevelMin; }
  299.         uint32 GetMaxLevel() const { return m_LevelMax; }
  300.  
  301.         uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayersPerTeam; }
  302.         uint32 GetMinPlayersPerTeam() const { return m_MinPlayersPerTeam; }
  303.  
  304.         int32 GetStartDelayTime() const { return m_StartDelayTime; }
  305.         ArenaType GetArenaType() const { return m_ArenaType; }
  306.         Team GetWinner() const { return m_Winner; }
  307.         uint32 GetBattlemasterEntry() const;
  308.         uint32 GetBonusHonorFromKill(uint32 kills) const;
  309.  
  310.         // Set methods:
  311.         void SetName(char const* Name) { m_Name = Name; }
  312.         void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; }
  313.         void SetBracketId(BattleGroundBracketId ID) { m_BracketId = ID; }
  314.         void SetStatus(BattleGroundStatus Status) { m_Status = Status; }
  315.         void SetClientInstanceID(uint32 InstanceID) { m_ClientInstanceID = InstanceID; }
  316.         void SetStartTime(uint32 Time) { m_StartTime = Time; }
  317.         void SetEndTime(uint32 Time) { m_EndTime = Time; }
  318.         void SetMaxPlayers(uint32 MaxPlayers) { m_MaxPlayers = MaxPlayers; }
  319.         void SetMinPlayers(uint32 MinPlayers) { m_MinPlayers = MinPlayers; }
  320.         void SetLevelRange(uint32 min, uint32 max) { m_LevelMin = min; m_LevelMax = max; }
  321.         void SetRated(bool state) { m_IsRated = state; }
  322.         void SetArenaType(ArenaType type) { m_ArenaType = type; }
  323.         void SetArenaorBGType(bool _isArena) { m_IsArena = _isArena; }
  324.         void SetWinner(Team winner) { m_Winner = winner; }
  325.  
  326.         void ModifyStartDelayTime(int diff) { m_StartDelayTime -= diff; }
  327.         void SetStartDelayTime(int Time) { m_StartDelayTime = Time; }
  328.  
  329.         void SetMaxPlayersPerTeam(uint32 MaxPlayers) { m_MaxPlayersPerTeam = MaxPlayers; }
  330.         void SetMinPlayersPerTeam(uint32 MinPlayers) { m_MinPlayersPerTeam = MinPlayers; }
  331.  
  332.         void AddToBGFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available
  333.         void RemoveFromBGFreeSlotQueue(); // this method could delete whole BG instance, if another free is available
  334.  
  335.         void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_InvitedAlliance : --m_InvitedHorde; }
  336.         void IncreaseInvitedCount(Team team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
  337.         uint32 GetInvitedCount(Team team) const
  338.         {
  339.             if (team == ALLIANCE)
  340.                 return m_InvitedAlliance;
  341.             else
  342.                 return m_InvitedHorde;
  343.         }
  344.         bool HasFreeSlots() const;
  345.         uint32 GetFreeSlotsForTeam(Team team) const;
  346.  
  347.         bool isArena() const { return m_IsArena; }
  348.         bool isBattleGround() const { return !m_IsArena; }
  349.         bool isRated() const { return m_IsRated; }
  350.  
  351.         typedef std::map<ObjectGuid, BattleGroundPlayer> BattleGroundPlayerMap;
  352.         BattleGroundPlayerMap const& GetPlayers() const { return m_Players; }
  353.         uint32 GetPlayersSize() const { return m_Players.size(); }
  354.  
  355.         typedef std::map<ObjectGuid, BattleGroundScore*> BattleGroundScoreMap;
  356.         BattleGroundScoreMap::const_iterator GetPlayerScoresBegin() const { return m_PlayerScores.begin(); }
  357.         BattleGroundScoreMap::const_iterator GetPlayerScoresEnd() const { return m_PlayerScores.end(); }
  358.         uint32 GetPlayerScoresSize() const { return m_PlayerScores.size(); }
  359.  
  360.         void StartBattleGround();
  361.  
  362.         /* Location */
  363.         void SetMapId(uint32 MapID) { m_MapId = MapID; }
  364.         uint32 GetMapId() const { return m_MapId; }
  365.  
  366.         /* Map pointers */
  367.         void SetBgMap(BattleGroundMap* map) { m_Map = map; }
  368.         BattleGroundMap* GetBgMap()
  369.         {
  370.             MANGOS_ASSERT(m_Map);
  371.             return m_Map;
  372.         }
  373.  
  374.         void SetTeamStartLoc(Team team, float X, float Y, float Z, float O);
  375.         void GetTeamStartLoc(Team team, float& X, float& Y, float& Z, float& O) const
  376.         {
  377.             BattleGroundTeamIndex idx = GetTeamIndexByTeamId(team);
  378.             X = m_TeamStartLocX[idx];
  379.             Y = m_TeamStartLocY[idx];
  380.             Z = m_TeamStartLocZ[idx];
  381.             O = m_TeamStartLocO[idx];
  382.         }
  383.  
  384.         /* Packet Transfer */
  385.         // method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
  386.         virtual void FillInitialWorldStates(WorldPacket& /*data*/, uint32& /*count*/) {}
  387.         void SendPacketToTeam(Team team, WorldPacket* packet, Player* sender = NULL, bool self = true);
  388.         void SendPacketToAll(WorldPacket* packet);
  389.  
  390.         template<class Do>
  391.         void BroadcastWorker(Do& _do);
  392.  
  393.         void PlaySoundToTeam(uint32 SoundID, Team team);
  394.         void PlaySoundToAll(uint32 SoundID);
  395.         void CastSpellOnTeam(uint32 SpellID, Team team);
  396.         void RewardHonorToTeam(uint32 Honor, Team team);
  397.         void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, Team team);
  398.         void RewardMark(Player* plr, uint32 count);
  399.         void SendRewardMarkByMail(Player* plr, uint32 mark, uint32 count);
  400.         void RewardItem(Player* plr, uint32 item_id, uint32 count);
  401.         void RewardQuestComplete(Player* plr);
  402.         void RewardSpellCast(Player* plr, uint32 spell_id);
  403.         void UpdateWorldState(uint32 Field, uint32 Value);
  404.         void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player* Source);
  405.         virtual void EndBattleGround(Team winner);
  406.         void BlockMovement(Player* plr);
  407.  
  408.         void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL);
  409.         void SendYellToAll(int32 entry, uint32 language, ObjectGuid guid);
  410.         void PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...);
  411.  
  412.         // specialized version with 2 string id args
  413.         void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0);
  414.         void SendYell2ToAll(int32 entry, uint32 language, ObjectGuid guid, int32 arg1, int32 arg2);
  415.  
  416.         /* Raid Group */
  417.         Group* GetBgRaid(Team team) const { return m_BgRaids[GetTeamIndexByTeamId(team)]; }
  418.         void SetBgRaid(Team team, Group* bg_raid);
  419.  
  420.         virtual void UpdatePlayerScore(Player* Source, uint32 type, uint32 value);
  421.  
  422.         static BattleGroundTeamIndex GetTeamIndexByTeamId(Team team) { return team == ALLIANCE ? BG_TEAM_ALLIANCE : BG_TEAM_HORDE; }
  423.         uint32 GetPlayersCountByTeam(Team team) const { return m_PlayersCount[GetTeamIndexByTeamId(team)]; }
  424.         uint32 GetAlivePlayersCountByTeam(Team team) const; // used in arenas to correctly handle death in spirit of redemption / last stand etc. (killer = killed) cases
  425.         void UpdatePlayersCountByTeam(Team team, bool remove)
  426.         {
  427.             if (remove)
  428.                 --m_PlayersCount[GetTeamIndexByTeamId(team)];
  429.             else
  430.                 ++m_PlayersCount[GetTeamIndexByTeamId(team)];
  431.         }
  432.  
  433.         // used for rated arena battles
  434.         void SetArenaTeamIdForTeam(Team team, uint32 ArenaTeamId) { m_ArenaTeamIds[GetTeamIndexByTeamId(team)] = ArenaTeamId; }
  435.         uint32 GetArenaTeamIdForTeam(Team team) const { return m_ArenaTeamIds[GetTeamIndexByTeamId(team)]; }
  436.         void SetArenaTeamRatingChangeForTeam(Team team, int32 RatingChange) { m_ArenaTeamRatingChanges[GetTeamIndexByTeamId(team)] = RatingChange; }
  437.         int32 GetArenaTeamRatingChangeForTeam(Team team) const { return m_ArenaTeamRatingChanges[GetTeamIndexByTeamId(team)]; }
  438.         void CheckArenaWinConditions();
  439.  
  440.         /* Triggers handle */
  441.         // must be implemented in BG subclass
  442.         virtual void HandleAreaTrigger(Player* /*Source*/, uint32 /*Trigger*/) {}
  443.         // must be implemented in BG subclass if need AND call base class generic code
  444.         virtual void HandleKillPlayer(Player* player, Player* killer);
  445.         virtual void HandleKillUnit(Creature* /*unit*/, Player* /*killer*/) {}
  446.  
  447.         // Process Capture event
  448.         virtual bool HandleEvent(uint32 /*eventId*/, GameObject* /*go*/) { return false; }
  449.  
  450.         // Called when a gameobject is created
  451.         virtual void HandleGameObjectCreate(GameObject* /*go*/) {}
  452.  
  453.         /* Battleground events */
  454.         virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
  455.         virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
  456.         virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
  457.         void EventPlayerLoggedIn(Player* player, ObjectGuid plr_guid);
  458.         void EventPlayerLoggedOut(Player* player);
  459.  
  460.         /* Death related */
  461.         virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
  462.  
  463.         virtual void AddPlayer(Player* plr); // must be implemented in BG subclass
  464.  
  465.         void AddOrSetPlayerToCorrectBgGroup(Player* plr, ObjectGuid plr_guid, Team team);
  466.  
  467.         virtual void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket);
  468.         // can be extended in in BG subclass
  469.  
  470.         /* event related */
  471.         // called when a creature gets added to map (NOTE: only triggered if
  472.         // a player activates the cell of the creature)
  473.         void OnObjectDBLoad(Creature* /*creature*/);
  474.         void OnObjectDBLoad(GameObject* /*obj*/);
  475.         // (de-)spawns creatures and gameobjects from an event
  476.         void SpawnEvent(uint8 event1, uint8 event2, bool spawn);
  477.         bool IsActiveEvent(uint8 event1, uint8 event2)
  478.         {
  479.             if (m_ActiveEvents.find(event1) == m_ActiveEvents.end())
  480.                 return false;
  481.             return m_ActiveEvents[event1] == event2;
  482.         }
  483.         ObjectGuid GetSingleCreatureGuid(uint8 event1, uint8 event2);
  484.  
  485.         void OpenDoorEvent(uint8 event1, uint8 event2 = 0);
  486.         bool IsDoor(uint8 event1, uint8 event2);
  487.  
  488.         void HandleTriggerBuff(ObjectGuid go_guid);
  489.  
  490.         void SpawnBGObject(ObjectGuid guid, uint32 respawntime);
  491.         void SpawnBGCreature(ObjectGuid guid, uint32 respawntime);
  492.  
  493.         void DoorOpen(ObjectGuid guid);
  494.         void DoorClose(ObjectGuid guid);
  495.  
  496.         virtual bool HandlePlayerUnderMap(Player * /*plr*/) { return false; }
  497.  
  498.         // since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
  499.         Team GetPlayerTeam(ObjectGuid guid);
  500.         static Team GetOtherTeam(Team team) { return team ? ((team == ALLIANCE) ? HORDE : ALLIANCE) : TEAM_NONE; }
  501.         static BattleGroundTeamIndex GetOtherTeamIndex(BattleGroundTeamIndex teamIdx) { return teamIdx == BG_TEAM_ALLIANCE ? BG_TEAM_HORDE : BG_TEAM_ALLIANCE; }
  502.         bool IsPlayerInBattleGround(ObjectGuid guid);
  503.  
  504.         /* virtual score-array - get's used in bg-subclasses */
  505.         int32 m_TeamScores[BG_TEAMS_COUNT];
  506.  
  507.         struct EventObjects
  508.         {
  509.             GuidVector gameobjects;
  510.             GuidVector creatures;
  511.         };
  512.  
  513.         // cause we create it dynamicly i use a map - to avoid resizing when
  514.         // using vector - also it contains 2*events concatenated with PAIR32
  515.         // this is needed to avoid overhead of a 2dimensional std::map
  516.         std::map<uint32, EventObjects> m_EventObjects;
  517.         // this must be filled first in BattleGroundXY::Reset().. else
  518.         // creatures will get added wrong
  519.         // door-events are automaticly added - but _ALL_ other must be in this vector
  520.         std::map<uint8, uint8> m_ActiveEvents;
  521.  
  522.  
  523.     protected:
  524.         // this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends BattleGround
  525.         void EndNow();
  526.         void PlayerAddedToBGCheckIfBGIsRunning(Player* plr);
  527.  
  528.         /* Scorekeeping */
  529.  
  530.         BattleGroundScoreMap m_PlayerScores; // Player scores
  531.         // must be implemented in BG subclass
  532.         virtual void RemovePlayer(Player * /*player*/, ObjectGuid /*guid*/) {}
  533.  
  534.         /* Player lists, those need to be accessible by inherited classes */
  535.         BattleGroundPlayerMap m_Players;
  536.  
  537.         /*
  538. these are important variables used for starting messages
  539. */
  540.         uint8 m_Events;
  541.         BattleGroundStartTimeIntervals m_StartDelayTimes[BG_STARTING_EVENT_COUNT];
  542.         // this must be filled in constructors!
  543.         uint32 m_StartMessageIds[BG_STARTING_EVENT_COUNT];
  544.  
  545.         bool m_BuffChange;
  546.  
  547.     private:
  548.         /* Battleground */
  549.         BattleGroundTypeId m_TypeID;
  550.         BattleGroundStatus m_Status;
  551.         uint32 m_ClientInstanceID; // the instance-id which is sent to the client and without any other internal use
  552.         uint32 m_StartTime;
  553.         bool m_ArenaBuffSpawned; // to cache if arenabuff event is started (cause bool is faster than checking IsActiveEvent)
  554.         int32 m_EndTime; // it is set to 120000 when bg is ending and it decreases itself
  555.         BattleGroundBracketId m_BracketId;
  556.         ArenaType m_ArenaType; // 2=2v2, 3=3v3, 5=5v5
  557.         bool m_InBGFreeSlotQueue; // used to make sure that BG is only once inserted into the BattleGroundMgr.BGFreeSlotQueue[bgTypeId] deque
  558.         bool m_IsArena;
  559.         Team m_Winner;
  560.         int32 m_StartDelayTime;
  561.         bool m_IsRated; // is this battle rated?
  562.         bool m_PrematureCountDown;
  563.         uint32 m_PrematureCountDownTimer;
  564.         char const* m_Name;
  565.  
  566.         /* Player lists */
  567.         typedef std::deque<ObjectGuid> OfflineQueue;
  568.         OfflineQueue m_OfflineQueue; // Player GUID
  569.  
  570.         /* 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 */
  571.         /* Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG */
  572.         /* Invited players counters*/
  573.         uint32 m_InvitedAlliance;
  574.         uint32 m_InvitedHorde;
  575.  
  576.         /* Raid Group */
  577.         Group* m_BgRaids[BG_TEAMS_COUNT]; // 0 - alliance, 1 - horde
  578.  
  579.         /* Players count by team */
  580.         uint32 m_PlayersCount[BG_TEAMS_COUNT];
  581.  
  582.         /* Arena team ids by team */
  583.         uint32 m_ArenaTeamIds[BG_TEAMS_COUNT];
  584.  
  585.         int32 m_ArenaTeamRatingChanges[BG_TEAMS_COUNT];
  586.  
  587.         /* Limits */
  588.         uint32 m_LevelMin;
  589.         uint32 m_LevelMax;
  590.         uint32 m_MaxPlayersPerTeam;
  591.         uint32 m_MaxPlayers;
  592.         uint32 m_MinPlayersPerTeam;
  593.         uint32 m_MinPlayers;
  594.  
  595.         /* Start location */
  596.         uint32 m_MapId;
  597.         BattleGroundMap* m_Map;
  598.         float m_TeamStartLocX[BG_TEAMS_COUNT];
  599.         float m_TeamStartLocY[BG_TEAMS_COUNT];
  600.         float m_TeamStartLocZ[BG_TEAMS_COUNT];
  601.         float m_TeamStartLocO[BG_TEAMS_COUNT];
  602. };
  603.  
  604. // helper functions for world state list fill
  605. inline void FillInitialWorldState(ByteBuffer& data, uint32& count, uint32 state, uint32 value)
  606. {
  607.     data << uint32(state);
  608.     data << uint32(value);
  609.     ++count;
  610. }
  611.  
  612. inline void FillInitialWorldState(ByteBuffer& data, uint32& count, uint32 state, int32 value)
  613. {
  614.     data << uint32(state);
  615.     data << int32(value);
  616.     ++count;
  617. }
  618.  
  619. inline void FillInitialWorldState(ByteBuffer& data, uint32& count, uint32 state, bool value)
  620. {
  621.     data << uint32(state);
  622.     data << uint32(value ? 1 : 0);
  623.     ++count;
  624. }
  625.  
  626. struct WorldStatePair
  627. {
  628.     uint32 state;
  629.     uint32 value;
  630. };
  631.  
  632. inline void FillInitialWorldState(ByteBuffer& data, uint32& count, WorldStatePair const* array)
  633. {
  634.     for (WorldStatePair const* itr = array; itr->state; ++itr)
  635.     {
  636.         data << uint32(itr->state);
  637.         data << uint32(itr->value);
  638.         ++count;
  639.     }
  640. }
  641.  
  642. #endif
Advertisement
Add Comment
Please, Sign In to add comment