Files
TCPlayerbotCore/src/server/game/Battlegrounds/BattlegroundMgr.h
T

136 lines
6.7 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#ifndef __BATTLEGROUNDMGR_H
#define __BATTLEGROUNDMGR_H
2009-10-17 15:51:44 -07:00
#include "Common.h"
#include "DBCEnums.h"
2008-10-02 16:23:55 -05:00
#include "BattleGround.h"
2010-08-08 03:41:46 +02:00
#include "BattleGroundQueue.h"
#include "ace/Singleton.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
typedef std::map<uint32, BattleGround*> BattleGroundSet;
2009-10-17 15:51:44 -07:00
typedef UNORDERED_MAP<uint32, BattleGroundTypeId> BattleMastersMap;
2009-10-17 15:51:44 -07:00
#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // seconds in a day
2010-03-26 16:48:33 +01:00
#define WS_ARENA_DISTRIBUTION_TIME 20001 // Custom worldstate
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class BattleGroundMgr
{
/// Todo: Thread safety?
/* Construction */
friend class ACE_Singleton<BattleGroundMgr, ACE_Null_Mutex>;
BattleGroundMgr();
2008-10-02 16:23:55 -05:00
public:
~BattleGroundMgr();
2009-01-21 16:18:57 -06:00
void Update(uint32 diff);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
/* Packet Building */
void BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Player *plr);
void BuildPlayerLeftBattleGroundPacket(WorldPacket *data, const uint64& guid);
2009-06-11 00:45:59 -05:00
void BuildBattleGroundListPacket(WorldPacket *data, const uint64& guid, Player *plr, BattleGroundTypeId bgTypeId, uint8 fromWhere);
void BuildGroupJoinedBattlegroundPacket(WorldPacket *data, GroupJoinBattlegroundResult result);
2008-10-02 16:23:55 -05:00
void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value);
void BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg);
void BuildBattleGroundStatusPacket(WorldPacket *data, BattleGround *bg, uint8 QueueSlot, uint8 StatusID, uint32 Time1, uint32 Time2, uint8 arenatype);
2008-10-02 16:23:55 -05:00
void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid);
2009-01-18 19:01:41 -06:00
void SendAreaSpiritHealerQueryOpcode(Player *pl, BattleGround *bg, const uint64& guid);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
/* Battlegrounds */
BattleGround* GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId);
BattleGround* GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId); //there must be uint32 because MAX_BATTLEGROUND_TYPE_ID means unknown
2009-10-17 15:51:44 -07:00
BattleGround* GetBattleGroundTemplate(BattleGroundTypeId bgTypeId);
BattleGround* CreateNewBattleGround(BattleGroundTypeId bgTypeId, PvPDifficultyEntry const* bracketEntry, uint8 arenaType, bool isRated);
2009-10-17 15:51:44 -07:00
uint32 CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsArena, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, uint32 LevelMin, uint32 LevelMax, char* BattleGroundName, uint32 MapID, float Team1StartLocX, float Team1StartLocY, float Team1StartLocZ, float Team1StartLocO, float Team2StartLocX, float Team2StartLocY, float Team2StartLocZ, float Team2StartLocO, uint32 scriptId);
2009-10-17 15:51:44 -07:00
void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; };
void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); }
uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BattleGroundBracketId bracket_id);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void CreateInitialBattleGrounds();
void DeleteAllBattleGrounds();
2009-10-17 15:51:44 -07:00
void SendToBattleGround(Player *pl, uint32 InstanceID, BattleGroundTypeId bgTypeId);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
/* Battleground queues */
//these queues are instantiated when creating BattlegroundMrg
2008-10-05 08:48:32 -05:00
BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code
2009-10-17 15:51:44 -07:00
BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID];
2009-10-17 15:51:44 -07:00
void ScheduleQueueUpdate(uint32 arenaRating, uint8 arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BattleGroundBracketId bracket_id);
uint32 GetMaxRatingDifference() const;
uint32 GetRatingDiscardTimer() const;
uint32 GetPrematureFinishTime() const;
2009-10-17 15:51:44 -07:00
2008-10-05 08:48:32 -05:00
void InitAutomaticArenaPointDistribution();
void DistributeArenaPoints();
void ToggleArenaTesting();
void ToggleTesting();
2009-10-17 15:51:44 -07:00
void SetHolidayWeekends(uint32 mask);
void LoadBattleMastersEntry();
BattleGroundTypeId GetBattleMasterBG(uint32 entry) const
{
BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
if (itr != mBattleMastersMap.end())
return itr->second;
return BATTLEGROUND_WS;
}
2009-10-17 15:51:44 -07:00
2009-01-18 19:01:41 -06:00
bool isArenaTesting() const { return m_ArenaTesting; }
bool isTesting() const { return m_Testing; }
2009-10-17 15:51:44 -07:00
static bool IsArenaType(BattleGroundTypeId bgTypeId);
static bool IsBattleGroundType(BattleGroundTypeId bgTypeId) { return !BattleGroundMgr::IsArenaType(bgTypeId); }
static BattleGroundQueueTypeId BGQueueTypeId(BattleGroundTypeId bgTypeId, uint8 arenaType);
static BattleGroundTypeId BGTemplateId(BattleGroundQueueTypeId bgQueueTypeId);
static uint8 BGArenaType(BattleGroundQueueTypeId bgQueueTypeId);
2009-10-17 15:51:44 -07:00
static HolidayIds BGTypeToWeekendHolidayId(BattleGroundTypeId bgTypeId);
static BattleGroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
static bool IsBGWeekend(BattleGroundTypeId bgTypeId);
void DoCompleteAchievement(uint32 achievement, Player * player = NULL);
2008-10-02 16:23:55 -05:00
private:
BattleMastersMap mBattleMastersMap;
2009-10-17 15:51:44 -07:00
typedef std::map<BattleGroundTypeId, uint8> BattleGroundSelectionWeightMap; // TypeId and its selectionWeight
2008-10-02 16:23:55 -05:00
/* Battlegrounds */
BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID];
BattleGroundSelectionWeightMap m_ArenaSelectionWeights;
BattleGroundSelectionWeightMap m_BGSelectionWeights;
std::vector<uint64> m_QueueUpdateScheduler;
std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; //the instanceids just visible for the client
2008-10-05 08:48:32 -05:00
uint32 m_NextRatingDiscardUpdate;
time_t m_NextAutoDistributionTime;
2008-10-05 08:48:32 -05:00
uint32 m_AutoDistributionTimeChecker;
bool m_ArenaTesting;
bool m_Testing;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
#define sBattleGroundMgr (*ACE_Singleton<BattleGroundMgr, ACE_Null_Mutex>::instance())
2008-10-02 16:23:55 -05:00
#endif
2009-02-17 20:07:49 -06:00