Core/Battlefields: Refactor Battlefield creation to be linked to host map creation instead of having globally accessible objects

This commit is contained in:
Shauren
2022-07-19 23:18:19 +02:00
parent 83b3266794
commit 073a036d84
21 changed files with 160 additions and 114 deletions
+3 -4
View File
@@ -33,10 +33,9 @@
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "WorldSession.h"
#include "WorldStatePackets.h"
#include <G3D/g3dmath.h>
Battlefield::Battlefield()
Battlefield::Battlefield(Map* map)
{
m_Timer = 0;
m_IsEnabled = true;
@@ -46,8 +45,8 @@ Battlefield::Battlefield()
m_TypeId = 0;
m_BattleId = 0;
m_ZoneId = 0;
m_Map = nullptr;
m_MapId = 0;
m_Map = map;
m_MapId = map->GetId();
m_MaxPlayer = 0;
m_MinPlayer = 0;
m_MinLevel = 0;
+1 -1
View File
@@ -212,7 +212,7 @@ class TC_GAME_API Battlefield : public ZoneScript
public:
/// Constructor
Battlefield();
explicit Battlefield(Map* map);
/// Destructor
virtual ~Battlefield();
+65 -57
View File
@@ -16,24 +16,27 @@
*/
#include "BattlefieldMgr.h"
#include "Containers.h"
#include "DatabaseEnv.h"
#include "ObjectMgr.h"
#include "Log.h"
#include "Map.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
namespace
{
constexpr std::array<uint32, BATTLEFIELD_MAX> BattlefieldIdToMapId = { 0, 571, 732 };
constexpr std::array<uint32, BATTLEFIELD_MAX> BattlefieldIdToZoneId = { 0, 4197, 5095 }; // imitate World_PVP_Area.db2
std::array<uint32, BATTLEFIELD_MAX> BattlefieldIdToScriptId = { 0, 0, 0 };
}
BattlefieldMgr::BattlefieldMgr()
{
_updateTimer = 0;
}
BattlefieldMgr::~BattlefieldMgr()
{
for (BattlefieldSet::iterator itr = _battlefieldSet.begin(); itr != _battlefieldSet.end(); ++itr)
delete *itr;
_battlefieldMap.clear();
}
BattlefieldMgr::~BattlefieldMgr() = default;
BattlefieldMgr* BattlefieldMgr::instance()
{
@@ -61,22 +64,8 @@ void BattlefieldMgr::InitBattlefield()
continue;
}
uint32 scriptId = sObjectMgr->GetScriptId(fields[1].GetString());
BattlefieldIdToScriptId[typeId] = sObjectMgr->GetScriptId(fields[1].GetString());
Battlefield* bf = sScriptMgr->CreateBattlefield(scriptId);
if (!bf)
continue;
if (!bf->SetupBattlefield())
{
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u failed.", typeId);
delete bf;
}
else
{
_battlefieldSet.push_back(bf);
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u succeeded.", typeId);
}
++count;
} while (result->NextRow());
@@ -85,15 +74,45 @@ void BattlefieldMgr::InitBattlefield()
TC_LOG_INFO("server.loading", ">> Loaded %u battlefields in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
void BattlefieldMgr::CreateBattlefieldsForMap(Map* map)
{
for (uint32 i = 0; i < BATTLEFIELD_MAX; ++i)
{
if (!BattlefieldIdToScriptId[i])
continue;
if (BattlefieldIdToMapId[i] != map->GetId())
continue;
Battlefield* bf = sScriptMgr->CreateBattlefield(BattlefieldIdToScriptId[i], map);
if (!bf)
continue;
if (!bf->SetupBattlefield())
{
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u on map %u instance id %u failed.", i, map->GetId(), map->GetInstanceId());
delete bf;
}
_battlefieldsByMap[map].emplace_back(bf);
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u on map %u instance id %u succeeded.", i, map->GetId(), map->GetInstanceId());
}
}
void BattlefieldMgr::DestroyBattlefieldsForMap(Map const* map)
{
_battlefieldsByMap.erase(map);
}
void BattlefieldMgr::AddZone(uint32 zoneId, Battlefield* bf)
{
_battlefieldMap[zoneId] = bf;
_battlefieldsByZone[{ bf->GetMap(), zoneId }] = bf;
}
void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneId)
{
BattlefieldMap::iterator itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
auto itr = _battlefieldsByZone.find({ player->GetMap(), zoneId });
if (itr == _battlefieldsByZone.end())
return;
Battlefield* bf = itr->second;
@@ -106,8 +125,8 @@ void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneId)
void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneId)
{
BattlefieldMap::iterator itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
auto itr = _battlefieldsByZone.find({ player->GetMap(), zoneId });
if (itr == _battlefieldsByZone.end())
return;
// teleport: remove once in removefromworld, once in updatezone
@@ -118,10 +137,15 @@ void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneId)
TC_LOG_DEBUG("bg.battlefield", "Player %s left battlefield id %u", player->GetGUID().ToString().c_str(), itr->second->GetTypeId());
}
Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneId)
bool BattlefieldMgr::IsWorldPvpArea(uint32 zoneId) const
{
BattlefieldMap::iterator itr = _battlefieldMap.find(zoneId);
if (itr == _battlefieldMap.end())
return std::find(BattlefieldIdToZoneId.begin(), BattlefieldIdToZoneId.end(), zoneId) != BattlefieldIdToZoneId.end();
}
Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(Map const* map, uint32 zoneId)
{
auto itr = _battlefieldsByZone.find({ map, zoneId });
if (itr == _battlefieldsByZone.end())
{
// no handle for this zone, return
return nullptr;
@@ -133,30 +157,12 @@ Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneId)
return itr->second;
}
Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleId)
Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(Map const* map, uint32 battleId)
{
for (BattlefieldSet::iterator itr = _battlefieldSet.begin(); itr != _battlefieldSet.end(); ++itr)
{
if ((*itr)->GetBattleId() == battleId)
return *itr;
}
return nullptr;
}
Battlefield* BattlefieldMgr::GetBattlefieldByQueueId(uint64 queueId)
{
for (Battlefield* bf : _battlefieldSet)
if (bf->GetQueueId() == queueId)
return bf;
return nullptr;
}
ZoneScript* BattlefieldMgr::GetZoneScript(uint32 zoneId)
{
BattlefieldMap::iterator itr = _battlefieldMap.find(zoneId);
if (itr != _battlefieldMap.end())
return itr->second;
if (BattlefieldsMapByMap::mapped_type const* battlefields = Trinity::Containers::MapGetValuePtr(_battlefieldsByMap, map))
for (std::unique_ptr<Battlefield> const& battlefield : *battlefields)
if (battlefield->GetBattleId() == battleId)
return battlefield.get();
return nullptr;
}
@@ -166,9 +172,11 @@ void BattlefieldMgr::Update(uint32 diff)
_updateTimer += diff;
if (_updateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL)
{
for (BattlefieldSet::iterator itr = _battlefieldSet.begin(); itr != _battlefieldSet.end(); ++itr)
if ((*itr)->IsEnabled())
(*itr)->Update(_updateTimer);
for (auto const& [map, battlefields] : _battlefieldsByMap)
for (std::unique_ptr<Battlefield> const& bfItr : battlefields)
if (bfItr->IsEnabled())
bfItr->Update(_updateTimer);
_updateTimer = 0;
}
}
+22 -9
View File
@@ -19,6 +19,10 @@
#define BATTLEFIELD_MGR_H_
#include "Battlefield.h"
#include "Hash.h"
#include <memory>
#include <unordered_map>
#include <vector>
class Player;
class ZoneScript;
@@ -27,22 +31,31 @@ class ZoneScript;
class TC_GAME_API BattlefieldMgr
{
public:
BattlefieldMgr(BattlefieldMgr const&) = delete;
BattlefieldMgr(BattlefieldMgr&&) = delete;
BattlefieldMgr& operator=(BattlefieldMgr const&) = delete;
BattlefieldMgr& operator=(BattlefieldMgr&&) = delete;
static BattlefieldMgr* instance();
// create battlefield events
void InitBattlefield();
void CreateBattlefieldsForMap(Map* map);
void DestroyBattlefieldsForMap(Map const* map);
// called when a player enters an battlefield area
void HandlePlayerEnterZone(Player* player, uint32 zoneId);
// called when player leaves an battlefield area
void HandlePlayerLeaveZone(Player* player, uint32 zoneId);
// return assigned battlefield
Battlefield* GetBattlefieldToZoneId(uint32 zoneId);
Battlefield* GetBattlefieldByBattleId(uint32 battleId);
Battlefield* GetBattlefieldByQueueId(uint64 queueId);
bool IsWorldPvpArea(uint32 zoneId) const;
ZoneScript* GetZoneScript(uint32 zoneId);
// return assigned battlefield
Battlefield* GetBattlefieldToZoneId(Map const* map, uint32 zoneId);
Battlefield* GetBattlefieldByBattleId(Map const* map, uint32 battleId);
void AddZone(uint32 zoneId, Battlefield* bf);
@@ -52,14 +65,14 @@ class TC_GAME_API BattlefieldMgr
BattlefieldMgr();
~BattlefieldMgr();
typedef std::vector<Battlefield*> BattlefieldSet;
typedef std::map<uint32 /*zoneId*/, Battlefield*> BattlefieldMap;
typedef std::unordered_map<Map const*, std::vector<std::unique_ptr<Battlefield>>> BattlefieldsMapByMap;
typedef std::unordered_map<std::pair<Map const*, uint32 /*zoneid*/>, Battlefield*> BattlefieldMapByZone;
// contains all initiated battlefield events
// used when initing / cleaning up
BattlefieldSet _battlefieldSet;
BattlefieldsMapByMap _battlefieldsByMap;
// maps the zone ids to an battlefield event
// used in player event handling
BattlefieldMap _battlefieldMap;
BattlefieldMapByZone _battlefieldsByZone;
// update interval
uint32 _updateTimer;
};
+1 -1
View File
@@ -1901,7 +1901,7 @@ ZoneScript* WorldObject::FindZoneScript() const
return reinterpret_cast<ZoneScript*>(instanceMap->GetInstanceScript());
else if (!map->IsBattlegroundOrArena())
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(map, GetZoneId()))
return bf;
else
return sOutdoorPvPMgr->GetOutdoorPvPToZoneId(map, GetZoneId());
+2 -2
View File
@@ -4769,7 +4769,7 @@ void Player::RepopAtGraveyard()
ClosestGrave = bg->GetClosestGraveyard(this);
else
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(GetMap(), GetZoneId()))
ClosestGrave = bf->GetClosestGraveyard(this);
else
ClosestGrave = sObjectMgr->GetClosestGraveyard(*this, GetTeam(), this);
@@ -26736,7 +26736,7 @@ bool Player::IsAreaThatActivatesPvpTalents(uint32 areaID) const
if (area->Flags[0] & AREA_FLAG_ARENA)
return true;
if (sBattlefieldMgr->GetBattlefieldToZoneId(area->ID))
if (sBattlefieldMgr->IsWorldPvpArea(area->ID))
return true;
area = sAreaTableStore.LookupEntry(area->ParentAreaID);
+1 -1
View File
@@ -10813,7 +10813,7 @@ void Unit::SetMeleeAnimKitId(uint16 animKitId)
if (OutdoorPvP* pvp = player->GetOutdoorPvP())
pvp->HandleKill(player, victim);
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId()))
bf->HandleKill(player, victim);
}
@@ -661,7 +661,7 @@ void WorldSession::HandleAreaSpiritHealerQueryOpcode(WorldPackets::Battleground:
if (Battleground* bg = _player->GetBattleground())
sBattlegroundMgr->SendAreaSpiritHealerQueryOpcode(_player, bg, areaSpiritHealerQuery.HealerGuid);
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetMap(), _player->GetZoneId()))
bf->SendAreaSpiritHealerQueryOpcode(_player, areaSpiritHealerQuery.HealerGuid);
}
@@ -677,7 +677,7 @@ void WorldSession::HandleAreaSpiritHealerQueueOpcode(WorldPackets::Battleground:
if (Battleground* bg = _player->GetBattleground())
bg->AddPlayerToResurrectQueue(areaSpiritHealerQueue.HealerGuid, _player->GetGUID());
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetMap(), _player->GetZoneId()))
bf->AddPlayerToResurrectQueue(areaSpiritHealerQueue.HealerGuid, _player->GetGUID());
}
@@ -686,7 +686,7 @@ void WorldSession::HandleHearthAndResurrect(WorldPackets::Battleground::HearthAn
if (_player->IsInFlight())
return;
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetMap(), _player->GetZoneId()))
{
bf->PlayerAskToLeave(_player);
return;
+3
View File
@@ -16,6 +16,7 @@
*/
#include "Map.h"
#include "BattlefieldMgr.h"
#include "Battleground.h"
#include "CellImpl.h"
#include "CharacterPackets.h"
@@ -96,6 +97,7 @@ Map::~Map()
sMapMgr->DecreaseScheduledScriptCount(m_scriptSchedule.size());
sOutdoorPvPMgr->DestroyOutdoorPvPForMap(this);
sBattlefieldMgr->DestroyBattlefieldsForMap(this);
if (m_parentMap == this)
delete m_childTerrainMaps;
@@ -379,6 +381,7 @@ i_scriptLock(false), _respawnCheckTimer(0)
_worldStateValues = sWorldStateMgr->GetInitialWorldStatesForMap(this);
sOutdoorPvPMgr->CreateOutdoorPvPForMap(this);
sBattlefieldMgr->CreateBattlefieldsForMap(this);
sScriptMgr->OnCreateMap(this);
}
+2 -2
View File
@@ -1737,10 +1737,10 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger, b
return entered ? tmpscript->OnTrigger(player, trigger) : tmpscript->OnExit(player, trigger);
}
Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId)
Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId, Map* map)
{
GET_SCRIPT_RET(BattlefieldScript, scriptId, tmpscript, nullptr);
return tmpscript->GetBattlefield();
return tmpscript->GetBattlefield(map);
}
Battleground* ScriptMgr::CreateBattleground(BattlegroundTypeId /*typeId*/)
+2 -2
View File
@@ -522,7 +522,7 @@ class TC_GAME_API BattlefieldScript : public ScriptObject
~BattlefieldScript();
virtual Battlefield* GetBattlefield() const = 0;
virtual Battlefield* GetBattlefield(Map* map) const = 0;
};
class TC_GAME_API BattlegroundScript : public ScriptObject
@@ -1146,7 +1146,7 @@ class TC_GAME_API ScriptMgr
public: /* BattlefieldScript */
Battlefield* CreateBattlefield(uint32 scriptId);
Battlefield* CreateBattlefield(uint32 scriptId, Map* map);
public: /* BattlegroundScript */
@@ -4583,7 +4583,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const* aurApp, uint8 mode, bool
{
if (Battleground* bg = target->ToPlayer()->GetBattleground())
bg->RemovePlayerFromResurrectQueue(target->GetGUID());
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(target->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(target->GetMap(), target->GetZoneId()))
bf->RemovePlayerFromResurrectQueue(target->GetGUID());
}
break;
+1 -1
View File
@@ -6528,7 +6528,7 @@ SpellCastResult Spell::CheckCast(bool strict, int32* param1 /*= nullptr*/, int32
// allow always ghost flight spells
if (m_originalCaster && m_originalCaster->GetTypeId() == TYPEID_PLAYER && m_originalCaster->IsAlive())
{
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldToZoneId(m_originalCaster->GetZoneId());
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldToZoneId(m_originalCaster->GetMap(), m_originalCaster->GetZoneId());
if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(m_originalCaster->GetAreaId()))
if (area->Flags[0] & AREA_FLAG_NO_FLY_ZONE || (Bf && !Bf->CanFlyIn()))
return SPELL_FAILED_NOT_HERE;
+4 -4
View File
@@ -750,7 +750,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
if (!player)
return false;
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId());
Battlefield* Bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId());
if (!Bf || Bf->CanFlyIn() || (!player->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) && !player->HasAuraType(SPELL_AURA_FLY)))
return false;
break;
@@ -761,7 +761,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
if (!player)
return false;
Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId());
Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId());
if (!bf || bf->GetTypeId() != BATTLEFIELD_WG)
return false;
@@ -781,7 +781,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
if (!player)
return false;
if (Battlefield* battlefieldWG = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG))
if (Battlefield* battlefieldWG = sBattlefieldMgr->GetBattlefieldByBattleId(player->GetMap(), BATTLEFIELD_BATTLEID_WG))
return battlefieldWG->IsEnabled() && (player->GetTeamId() == battlefieldWG->GetDefenderTeam()) && !battlefieldWG->IsWarTime();
break;
}
@@ -790,7 +790,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32
if (!player)
return false;
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId()))
return bf->IsWarTime();
break;
}
@@ -45,8 +45,6 @@ bool BattlefieldTB::SetupBattlefield()
m_TypeId = BATTLEFIELD_TB; // See enum BattlefieldTypes
m_BattleId = BATTLEFIELD_BATTLEID_TB;
m_ZoneId = BATTLEFIELD_TB_ZONEID;
m_MapId = BATTLEFIELD_TB_MAPID;
m_Map = sMapMgr->CreateBaseMap(m_MapId);
InitStalker(NPC_DEBUG_ANNOUNCER, TolBaradDebugAnnouncerPos);
@@ -757,9 +755,9 @@ class Battlefield_tol_barad : public BattlefieldScript
public:
Battlefield_tol_barad() : BattlefieldScript("battlefield_tb") { }
Battlefield* GetBattlefield() const override
Battlefield* GetBattlefield(Map* map) const override
{
return new BattlefieldTB();
return new BattlefieldTB(map);
}
};
@@ -549,6 +549,7 @@ class TolBaradCapturePoint : public BfCapturePoint
class BattlefieldTB : public Battlefield
{
public:
using Battlefield::Battlefield;
~BattlefieldTB();
void OnStartGrouping() override;
@@ -411,8 +411,6 @@ bool BattlefieldWG::SetupBattlefield()
m_TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes
m_BattleId = BATTLEFIELD_BATTLEID_WG;
m_ZoneId = AREA_WINTERGRASP;
m_MapId = BATTLEFIELD_WG_MAPID;
m_Map = sMapMgr->CreateBaseMap(m_MapId);
InitStalker(BATTLEFIELD_WG_NPC_STALKER, WintergraspStalkerPos);
@@ -1477,6 +1475,26 @@ void BfWGGameObjectBuilding::Init(GameObject* go)
}
_state = WintergraspGameObjectState(sWorldStateMgr->GetValue(_worldState, _wg->GetMap()));
if (_state == BATTLEFIELD_WG_OBJECTSTATE_NONE)
{
// set to default state based on type
switch (_teamControl)
{
case TEAM_ALLIANCE:
_state = BATTLEFIELD_WG_OBJECTSTATE_ALLIANCE_INTACT;
break;
case TEAM_HORDE:
_state = BATTLEFIELD_WG_OBJECTSTATE_HORDE_INTACT;
break;
case TEAM_NEUTRAL:
_state = BATTLEFIELD_WG_OBJECTSTATE_NEUTRAL_INTACT;
break;
default:
break;
}
sWorldStateMgr->SetValueAndSaveInDb(_worldState, _state, false, _wg->GetMap());
}
switch (_state)
{
case BATTLEFIELD_WG_OBJECTSTATE_NEUTRAL_INTACT:
@@ -1774,9 +1792,9 @@ class Battlefield_wintergrasp : public BattlefieldScript
public:
Battlefield_wintergrasp() : BattlefieldScript("battlefield_wg") { }
Battlefield* GetBattlefield() const override
Battlefield* GetBattlefield(Map* map) const override
{
return new BattlefieldWG();
return new BattlefieldWG(map);
}
};
@@ -1794,7 +1812,7 @@ public:
if (!killer || killer->GetTypeId() != TYPEID_PLAYER)
return;
BattlefieldWG* wintergrasp = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG));
BattlefieldWG* wintergrasp = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(killer->GetMap(), BATTLEFIELD_BATTLEID_WG));
if (!wintergrasp)
return;
@@ -200,6 +200,7 @@ class WintergraspCapturePoint : public BfCapturePoint
class BattlefieldWG : public Battlefield
{
public:
using Battlefield::Battlefield;
~BattlefieldWG();
/**
* \brief Called when the battle start
+6 -5
View File
@@ -26,6 +26,7 @@ EndScriptData */
#include "BattlefieldMgr.h"
#include "Chat.h"
#include "ChatCommand.h"
#include "Player.h"
#include "RBAC.h"
using namespace Trinity::ChatCommands;
@@ -54,7 +55,7 @@ public:
static bool HandleBattlefieldStart(ChatHandler* handler, uint32 battleId)
{
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
if (!bf)
return false;
@@ -69,7 +70,7 @@ public:
static bool HandleBattlefieldEnd(ChatHandler* handler, uint32 battleId)
{
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
if (!bf)
return false;
@@ -84,7 +85,7 @@ public:
static bool HandleBattlefieldEnable(ChatHandler* handler, uint32 battleId)
{
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
if (!bf)
return false;
@@ -107,7 +108,7 @@ public:
static bool HandleBattlefieldSwitch(ChatHandler* handler, uint32 battleId)
{
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
if (!bf)
return false;
@@ -121,7 +122,7 @@ public:
static bool HandleBattlefieldTimer(ChatHandler* handler, uint32 battleId, uint32 time)
{
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(handler->GetPlayer()->GetMap(), battleId);
if (!bf)
return false;
+1 -1
View File
@@ -1408,7 +1408,7 @@ public:
nearestLoc = bg->GetClosestGraveyard(player);
else
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId()))
nearestLoc = bf->GetClosestGraveyard(player);
else
nearestLoc = sObjectMgr->GetClosestGraveyard(*player, player->GetTeam(), player);
@@ -172,7 +172,7 @@ struct npc_wg_demolisher_engineer : public ScriptedAI
private:
bool CanBuild() const
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return false;
@@ -203,7 +203,7 @@ struct npc_wg_spirit_guide : public ScriptedAI
if (me->IsQuestGiver())
player->PrepareQuestMenu(me->GetGUID());
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -221,7 +221,7 @@ struct npc_wg_spirit_guide : public ScriptedAI
uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
CloseGossipMenuFor(player);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (wintergrasp)
{
GraveyardVect gy = wintergrasp->GetGraveyardVector();
@@ -272,7 +272,7 @@ struct npc_wg_queue : public ScriptedAI
if (me->IsQuestGiver())
player->PrepareQuestMenu(me->GetGUID());
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -300,7 +300,7 @@ struct npc_wg_queue : public ScriptedAI
{
CloseGossipMenuFor(player);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -441,8 +441,8 @@ class spell_wintergrasp_defender_teleport : public SpellScript
SpellCastResult CheckCast()
{
if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG))
if (Player* target = GetExplTargetUnit()->ToPlayer())
if (Player* target = GetExplTargetUnit()->ToPlayer())
if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(target->GetMap(), BATTLEFIELD_BATTLEID_WG))
// check if we are in Wintergrasp at all, SotA uses same teleport spells
if ((target->GetZoneId() == AREA_WINTERGRASP && target->GetTeamId() != wg->GetDefenderTeam()) || target->HasAura(SPELL_WINTERGRASP_TELEPORT_TRIGGER))
return SPELL_FAILED_BAD_TARGETS;
@@ -528,9 +528,11 @@ class condition_is_wintergrasp_horde : public ConditionScript
public:
condition_is_wintergrasp_horde() : ConditionScript("condition_is_wintergrasp_horde") { }
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& /* sourceInfo */)
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& sourceInfo)
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
if (!sourceInfo.mConditionMap)
return false;
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(sourceInfo.mConditionMap, BATTLEFIELD_BATTLEID_WG);
if (wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_HORDE)
return true;
return false;
@@ -542,9 +544,11 @@ class condition_is_wintergrasp_alliance : public ConditionScript
public:
condition_is_wintergrasp_alliance() : ConditionScript("condition_is_wintergrasp_alliance") { }
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& /* sourceInfo */)
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& sourceInfo)
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
if (!sourceInfo.mConditionMap)
return false;
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(sourceInfo.mConditionMap, BATTLEFIELD_BATTLEID_WG);
if (wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_ALLIANCE)
return true;
return false;