mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-19 03:45:43 +00:00
* feat(Core): Config to disable all Wintergrasp processing * Use 2 instead of -1 - configs are parsed as uint * Fix build warnings
153 lines
4.6 KiB
C++
153 lines
4.6 KiB
C++
/*
|
|
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Affero General Public License as published by the
|
|
* Free Software Foundation; either version 3 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 MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "BattlefieldMgr.h"
|
|
#include "Player.h"
|
|
#include "Zones/BattlefieldWG.h"
|
|
|
|
BattlefieldMgr::BattlefieldMgr()
|
|
{
|
|
m_UpdateTimer = 0;
|
|
//LOG_DEBUG("bg.battlefield", "Instantiating BattlefieldMgr");
|
|
}
|
|
|
|
BattlefieldMgr::~BattlefieldMgr()
|
|
{
|
|
//LOG_DEBUG("bg.battlefield", "Deleting BattlefieldMgr");
|
|
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
|
|
delete *itr;
|
|
}
|
|
|
|
BattlefieldMgr* BattlefieldMgr::instance()
|
|
{
|
|
static BattlefieldMgr instance;
|
|
return &instance;
|
|
}
|
|
|
|
void BattlefieldMgr::InitBattlefield()
|
|
{
|
|
if (sWorld->getIntConfig(CONFIG_WINTERGRASP_ENABLE) == 2)
|
|
{
|
|
LOG_INFO("server.loading", "Battlefield: Wintergrasp is disabled.");
|
|
LOG_INFO("server.loading", " ");
|
|
return;
|
|
}
|
|
Battlefield* pBf = new BattlefieldWG;
|
|
// respawn, init variables
|
|
if (!pBf->SetupBattlefield())
|
|
{
|
|
LOG_ERROR("server.loading", "Battlefield: Wintergrasp init failed.");
|
|
LOG_INFO("server.loading", " ");
|
|
delete pBf;
|
|
}
|
|
else
|
|
{
|
|
m_BattlefieldSet.push_back(pBf);
|
|
LOG_INFO("server.loading", "Battlefield: Wintergrasp successfully initiated.");
|
|
LOG_INFO("server.loading", " ");
|
|
}
|
|
|
|
/* For Cataclysm: Tol Barad
|
|
pBf = new BattlefieldTB;
|
|
// respawn, init variables
|
|
if(!pBf->SetupBattlefield())
|
|
{
|
|
LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad init failed.");
|
|
delete pBf;
|
|
}
|
|
else
|
|
{
|
|
m_BattlefieldSet.push_back(pBf);
|
|
LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad successfully initiated.");
|
|
} */
|
|
}
|
|
|
|
void BattlefieldMgr::AddZone(uint32 zoneid, Battlefield* handle)
|
|
{
|
|
m_BattlefieldMap[zoneid] = handle;
|
|
}
|
|
|
|
void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneid)
|
|
{
|
|
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
|
|
if (itr == m_BattlefieldMap.end())
|
|
return;
|
|
|
|
if (itr->second->HasPlayer(player) || !itr->second->IsEnabled())
|
|
return;
|
|
|
|
itr->second->HandlePlayerEnterZone(player, zoneid);
|
|
LOG_DEBUG("bg.battlefield", "Player {} entered outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
|
|
}
|
|
|
|
void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneid)
|
|
{
|
|
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
|
|
if (itr == m_BattlefieldMap.end())
|
|
return;
|
|
|
|
// teleport: remove once in removefromworld, once in updatezone
|
|
if (!itr->second->HasPlayer(player))
|
|
return;
|
|
itr->second->HandlePlayerLeaveZone(player, zoneid);
|
|
LOG_DEBUG("bg.battlefield", "Player {} left outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId());
|
|
}
|
|
|
|
Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneid)
|
|
{
|
|
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid);
|
|
if (itr == m_BattlefieldMap.end())
|
|
{
|
|
// no handle for this zone, return
|
|
return nullptr;
|
|
}
|
|
if (!itr->second->IsEnabled())
|
|
return nullptr;
|
|
return itr->second;
|
|
}
|
|
|
|
Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleid)
|
|
{
|
|
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
|
|
{
|
|
if ((*itr)->GetBattleId() == battleid)
|
|
return (*itr);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void BattlefieldMgr::Update(uint32 diff)
|
|
{
|
|
m_UpdateTimer += diff;
|
|
if (m_UpdateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL)
|
|
{
|
|
for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr)
|
|
//if ((*itr)->IsEnabled())
|
|
(*itr)->Update(m_UpdateTimer);
|
|
m_UpdateTimer = 0;
|
|
}
|
|
}
|
|
|
|
ZoneScript* BattlefieldMgr::GetZoneScript(uint32 zoneId)
|
|
{
|
|
BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneId);
|
|
if (itr != m_BattlefieldMap.end())
|
|
return itr->second;
|
|
else
|
|
return nullptr;
|
|
}
|