2018-03-06 22:22:19 +01:00
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Database/DatabaseDef.h>
|
|
|
|
#include <Exd/ExdDataGenerated.h>
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-02-28 10:26:03 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2018-01-28 22:36:43 +01:00
|
|
|
#include "Actor/Player.h"
|
|
|
|
|
2018-01-27 23:52:49 +01:00
|
|
|
#include "Zone.h"
|
2018-07-15 23:59:15 +02:00
|
|
|
#include "HousingZone.h"
|
2018-01-27 23:52:49 +01:00
|
|
|
#include "ZonePosition.h"
|
2018-01-29 13:05:33 +11:00
|
|
|
#include "InstanceContent.h"
|
2018-03-02 07:22:25 -03:00
|
|
|
#include "TerritoryMgr.h"
|
|
|
|
#include "Framework.h"
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-03-09 10:19:38 +01:00
|
|
|
extern Core::Framework g_fw;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
|
|
|
Core::TerritoryMgr::TerritoryMgr() :
|
2018-08-29 21:40:59 +02:00
|
|
|
m_lastInstanceId( 10000 )
|
2018-01-27 23:52:49 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::TerritoryMgr::loadTerritoryTypeDetailCache()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto idList = pExdData->getTerritoryTypeIdList();
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( auto id : idList )
|
|
|
|
{
|
|
|
|
auto teri1 = pExdData->get< Core::Data::TerritoryType >( id );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !teri1->name.empty() )
|
|
|
|
m_territoryTypeDetailCacheMap[ id ] = teri1;
|
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::isValidTerritory( uint32_t territoryTypeId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return !( m_territoryTypeDetailCacheMap.find( territoryTypeId ) == m_territoryTypeDetailCacheMap.end() );
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::init()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
loadTerritoryTypeDetailCache();
|
|
|
|
loadTerritoryPositionMap();
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
createDefaultTerritories();
|
|
|
|
createHousingTerritories();
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Core::TerritoryMgr::getNextInstanceId()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return ++m_lastInstanceId;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::Data::TerritoryTypePtr Core::TerritoryMgr::getTerritoryDetail( uint32_t territoryTypeId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto tIt = m_territoryTypeDetailCacheMap.find( territoryTypeId );
|
|
|
|
if( tIt == m_territoryTypeDetailCacheMap.end() )
|
|
|
|
return nullptr;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return tIt->second;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::isInstanceContentTerritory( uint32_t territoryTypeId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pTeri = getTerritoryDetail( territoryTypeId );
|
|
|
|
|
|
|
|
if( !pTeri )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto intendedUse = pTeri->territoryIntendedUse;
|
|
|
|
|
|
|
|
return intendedUse == TerritoryIntendedUse::AllianceRaid ||
|
|
|
|
intendedUse == TerritoryIntendedUse::BeforeTrialDung ||
|
|
|
|
intendedUse == TerritoryIntendedUse::Trial ||
|
|
|
|
intendedUse == TerritoryIntendedUse::Dungeon ||
|
|
|
|
intendedUse == TerritoryIntendedUse::OpenWorldInstanceBattle ||
|
|
|
|
intendedUse == TerritoryIntendedUse::PalaceOfTheDead ||
|
|
|
|
intendedUse == TerritoryIntendedUse::RaidFights ||
|
|
|
|
intendedUse == TerritoryIntendedUse::Raids ||
|
|
|
|
intendedUse == TerritoryIntendedUse::TreasureMapInstance ||
|
|
|
|
intendedUse == TerritoryIntendedUse::EventTrial;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::isPrivateTerritory( uint32_t territoryTypeId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pTeri = getTerritoryDetail( territoryTypeId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pTeri )
|
|
|
|
return false;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return pTeri->territoryIntendedUse == TerritoryIntendedUse::OpeningArea ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::Inn ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::HousingPrivateArea ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::JailArea ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::MSQPrivateArea;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::createDefaultTerritories()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto pLog = g_fw.get< Logger >();
|
|
|
|
// for each entry in territoryTypeExd, check if it is a normal and if so, add the zone object
|
|
|
|
for( const auto& territory : m_territoryTypeDetailCacheMap )
|
|
|
|
{
|
|
|
|
auto territoryId = territory.first;
|
|
|
|
auto territoryInfo = territory.second;
|
|
|
|
|
|
|
|
// if the zone has no name set
|
|
|
|
if( territoryInfo->name.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto pPlaceName = pExdData->get< Core::Data::PlaceName >( territoryInfo->placeName );
|
|
|
|
|
|
|
|
if( !pPlaceName || pPlaceName->name.empty() || !isDefaultTerritory( territoryId ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint32_t guid = getNextInstanceId();
|
|
|
|
pLog->info( std::to_string( territoryId ) +
|
|
|
|
"\t" + std::to_string( guid ) +
|
|
|
|
"\t" + std::to_string( territoryInfo->territoryIntendedUse ) +
|
|
|
|
"\t" + ( territoryInfo->name.length() <= 4 ? territoryInfo->name + "\t" : territoryInfo->name ) +
|
|
|
|
"\t" + ( isPrivateTerritory( territoryId ) ? "PRIVATE" : "PUBLIC" ) +
|
|
|
|
"\t" + pPlaceName->name );
|
|
|
|
|
|
|
|
auto pZone = make_Zone( territoryId, guid, territoryInfo->name, pPlaceName->name );
|
|
|
|
pZone->init();
|
|
|
|
|
|
|
|
InstanceIdToZonePtrMap instanceMap;
|
|
|
|
instanceMap[ guid ] = pZone;
|
|
|
|
m_instanceIdToZonePtrMap[ guid ] = pZone;
|
|
|
|
m_territoryIdToInstanceGuidMap[ territoryId ] = instanceMap;
|
|
|
|
m_zoneSet.insert( { pZone } );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
bool Core::TerritoryMgr::createHousingTerritories()
|
|
|
|
{
|
|
|
|
//separate housing zones from default
|
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto pLog = g_fw.get< Logger >();
|
|
|
|
for( const auto& territory : m_territoryTypeDetailCacheMap )
|
|
|
|
{
|
|
|
|
auto territoryId = territory.first;
|
|
|
|
auto territoryInfo = territory.second;
|
|
|
|
uint32_t wardNum;
|
|
|
|
uint32_t wardMaxNum = 1;
|
|
|
|
|
|
|
|
if( territoryInfo->name.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto pPlaceName = pExdData->get< Core::Data::PlaceName >( territoryInfo->placeName );
|
|
|
|
|
|
|
|
if( !pPlaceName || pPlaceName->name.empty() || !isHousingTerritory( territoryId ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( wardNum = 0; wardNum < wardMaxNum; wardNum++ )
|
|
|
|
{
|
2018-01-27 23:52:49 +01:00
|
|
|
uint32_t guid = getNextInstanceId();
|
2018-03-09 10:19:38 +01:00
|
|
|
pLog->info( std::to_string( territoryId ) +
|
2018-08-29 21:40:59 +02:00
|
|
|
"\t" + std::to_string( guid ) +
|
|
|
|
"\t" + std::to_string( territoryInfo->territoryIntendedUse ) +
|
|
|
|
"\t" + ( territoryInfo->name.length() <= 4 ? territoryInfo->name + "\t" : territoryInfo->name ) +
|
|
|
|
"\t" + "HOUSING" +
|
|
|
|
"\t" + pPlaceName->name +
|
|
|
|
"#" + std::to_string( wardNum ) );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pHousingZone = make_HousingZone( wardNum, territoryId, guid, territoryInfo->name, pPlaceName->name );
|
|
|
|
pHousingZone->init();
|
|
|
|
wardMaxNum = pHousingZone->m_wardMaxNum;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
|
|
|
InstanceIdToZonePtrMap instanceMap;
|
2018-08-29 21:40:59 +02:00
|
|
|
instanceMap[ guid ] = pHousingZone;
|
|
|
|
m_instanceIdToZonePtrMap[ guid ] = pHousingZone;
|
|
|
|
m_territoryIdToInstanceGuidMap[ territoryId ][ guid ] = pHousingZone;
|
|
|
|
m_zoneSet.insert( { pHousingZone } );
|
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 23:53:58 +11:00
|
|
|
Core::ZonePtr Core::TerritoryMgr::createTerritoryInstance( uint32_t territoryTypeId )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !isValidTerritory( territoryTypeId ) )
|
|
|
|
return nullptr;
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( isInstanceContentTerritory( territoryTypeId ) )
|
|
|
|
return nullptr;
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto pLog = g_fw.get< Logger >();
|
|
|
|
auto pTeri = getTerritoryDetail( territoryTypeId );
|
|
|
|
auto pPlaceName = pExdData->get< Core::Data::PlaceName >( pTeri->placeName );
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pTeri || !pPlaceName )
|
|
|
|
return nullptr;
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
pLog->debug(
|
|
|
|
"Starting instance for territory: " + std::to_string( territoryTypeId ) + " (" + pPlaceName->name + ")" );
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pZone = make_Zone( territoryTypeId, getNextInstanceId(), pTeri->name, pPlaceName->name );
|
|
|
|
pZone->init();
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone;
|
|
|
|
m_territoryIdToInstanceGuidMap[ pZone->getTerritoryId() ][ pZone->getGuId() ] = pZone;
|
|
|
|
m_zoneSet.insert( { pZone } );
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return pZone;
|
2018-01-28 23:53:58 +11:00
|
|
|
}
|
|
|
|
|
2018-01-29 19:40:27 +11:00
|
|
|
Core::ZonePtr Core::TerritoryMgr::createInstanceContent( uint32_t instanceContentId )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pExdData = g_fw.get< Data::ExdDataGenerated >();
|
|
|
|
auto pInstanceContent = pExdData->get< Core::Data::InstanceContent >( instanceContentId );
|
|
|
|
if( !pInstanceContent )
|
|
|
|
return nullptr;
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !isInstanceContentTerritory( pInstanceContent->territoryType ) )
|
|
|
|
return nullptr;
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pTeri = getTerritoryDetail( pInstanceContent->territoryType );
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pTeri || pInstanceContent->name.empty() )
|
|
|
|
return nullptr;
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pLog = g_fw.get< Logger >();
|
|
|
|
pLog->debug( "Starting instance for InstanceContent id: " + std::to_string( instanceContentId ) +
|
|
|
|
" (" + pInstanceContent->name + ")" );
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pZone = make_InstanceContent( pInstanceContent, getNextInstanceId(),
|
|
|
|
pTeri->name, pInstanceContent->name, instanceContentId );
|
|
|
|
pZone->init();
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
m_instanceContentToInstanceMap[ instanceContentId ][ pZone->getGuId() ] = pZone;
|
|
|
|
m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone;
|
|
|
|
m_instanceZoneSet.insert( pZone );
|
2018-01-29 19:40:27 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return pZone;
|
2018-01-29 19:40:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::removeTerritoryInstance( uint32_t instanceId )
|
2018-01-29 00:52:11 +11:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
ZonePtr pZone;
|
|
|
|
if( ( pZone = getInstanceZonePtr( instanceId ) ) == nullptr )
|
|
|
|
return false;
|
2018-01-29 00:52:11 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
m_instanceIdToZonePtrMap.erase( pZone->getGuId() );
|
2018-01-29 20:40:32 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
m_instanceZoneSet.erase( pZone );
|
|
|
|
m_zoneSet.erase( pZone );
|
2018-02-01 23:32:59 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( isInstanceContentTerritory( pZone->getTerritoryId() ) )
|
|
|
|
{
|
|
|
|
auto instance = boost::dynamic_pointer_cast< InstanceContent >( pZone );
|
|
|
|
m_instanceContentToInstanceMap[ instance->getInstanceContentId() ].erase( pZone->getGuId() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_territoryIdToInstanceGuidMap[ pZone->getTerritoryId() ].erase( pZone->getGuId() );
|
2018-01-29 20:40:32 +11:00
|
|
|
|
2018-01-29 00:52:11 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-01-29 00:52:11 +11:00
|
|
|
}
|
|
|
|
|
2018-01-29 19:40:27 +11:00
|
|
|
Core::ZonePtr Core::TerritoryMgr::getInstanceZonePtr( uint32_t instanceId ) const
|
2018-01-28 23:53:58 +11:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = m_instanceIdToZonePtrMap.find( instanceId );
|
|
|
|
if( it == m_instanceIdToZonePtrMap.end() )
|
|
|
|
return nullptr;
|
2018-01-28 23:53:58 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return it->second;
|
2018-01-28 23:53:58 +11:00
|
|
|
}
|
|
|
|
|
2018-01-27 23:52:49 +01:00
|
|
|
void Core::TerritoryMgr::loadTerritoryPositionMap()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
|
|
|
auto pQR = pDb->query( "SELECT id, target_zone_id, pos_x, pos_y, pos_z, pos_o, radius FROM zonepositions;" );
|
|
|
|
|
|
|
|
while( pQR->next() )
|
|
|
|
{
|
|
|
|
uint32_t id = pQR->getUInt( 1 );
|
|
|
|
uint32_t targetZoneId = pQR->getUInt( 2 );
|
|
|
|
Common::FFXIVARR_POSITION3 pos{};
|
|
|
|
pos.x = pQR->getFloat( 3 );
|
|
|
|
pos.y = pQR->getFloat( 4 );
|
|
|
|
pos.z = pQR->getFloat( 5 );
|
|
|
|
float posO = pQR->getFloat( 6 );
|
|
|
|
uint32_t radius = pQR->getUInt( 7 );
|
|
|
|
|
|
|
|
m_territoryPositionMap[ id ] = make_ZonePosition( id, targetZoneId, pos, radius, posO );
|
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::isDefaultTerritory( uint32_t territoryTypeId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pTeri = getTerritoryDetail( territoryTypeId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pTeri )
|
|
|
|
return false;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return pTeri->territoryIntendedUse == TerritoryIntendedUse::Inn ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::Town ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::OpenWorld ||
|
|
|
|
pTeri->territoryIntendedUse == TerritoryIntendedUse::OpeningArea;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
bool Core::TerritoryMgr::isHousingTerritory( uint32_t territoryTypeId ) const
|
2018-07-15 23:59:15 +02:00
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pTeri = getTerritoryDetail( territoryTypeId );
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( !pTeri )
|
|
|
|
return false;
|
2018-07-15 23:59:15 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return pTeri->territoryIntendedUse == TerritoryIntendedUse::HousingArea;
|
2018-07-15 23:59:15 +02:00
|
|
|
}
|
|
|
|
|
2018-01-27 23:52:49 +01:00
|
|
|
Core::ZonePositionPtr Core::TerritoryMgr::getTerritoryPosition( uint32_t territoryPositionId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = m_territoryPositionMap.find( territoryPositionId );
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
if( it != m_territoryPositionMap.end() )
|
|
|
|
return it->second;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return nullptr;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::ZonePtr Core::TerritoryMgr::getZoneByTerriId( uint32_t territoryId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto zoneMap = m_territoryIdToInstanceGuidMap.find( territoryId );
|
|
|
|
if( zoneMap == m_territoryIdToInstanceGuidMap.end() )
|
|
|
|
return nullptr;
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// TODO: actually select the proper one
|
|
|
|
return zoneMap->second.begin()->second;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::TerritoryMgr::updateTerritoryInstances( uint32_t currentTime )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
for( auto& zone : m_zoneSet )
|
|
|
|
{
|
|
|
|
zone->update( currentTime );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& zone : m_instanceZoneSet )
|
|
|
|
{
|
|
|
|
zone->update( currentTime );
|
|
|
|
}
|
2018-01-28 13:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::TerritoryMgr::InstanceIdList Core::TerritoryMgr::getInstanceContentIdList( uint16_t instanceContentId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
std::vector< uint32_t > idList;
|
|
|
|
auto zoneMap = m_instanceContentToInstanceMap.find( instanceContentId );
|
|
|
|
if( zoneMap == m_instanceContentToInstanceMap.end() )
|
|
|
|
return idList;
|
2018-01-28 13:49:51 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( auto& entry : zoneMap->second )
|
|
|
|
{
|
|
|
|
idList.push_back( entry.first );
|
|
|
|
}
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return idList;
|
2018-01-27 23:52:49 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 22:36:43 +01:00
|
|
|
bool Core::TerritoryMgr::movePlayer( uint32_t territoryId, Core::Entity::PlayerPtr pPlayer )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pZone = getZoneByTerriId( territoryId );
|
|
|
|
assert( pZone );
|
|
|
|
return movePlayer( pZone, pPlayer );
|
2018-01-28 22:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::TerritoryMgr::movePlayer( ZonePtr pZone, Core::Entity::PlayerPtr pPlayer )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto pLog = g_fw.get< Logger >();
|
|
|
|
if( !pZone )
|
|
|
|
{
|
|
|
|
pLog->error( "Zone not found on this server." );
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-28 22:36:43 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
pPlayer->initSpawnIdQueue();
|
2018-02-23 23:47:21 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
pPlayer->setTerritoryId( pZone->getTerritoryId() );
|
2018-01-28 22:36:43 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// mark character as zoning in progress
|
|
|
|
pPlayer->setLoadingComplete( false );
|
2018-01-28 22:36:43 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
//if( pPlayer->getLastPing() != 0 )
|
|
|
|
// pPlayer->getCurrentZone()->removeActor( pPlayer );
|
2018-01-28 22:36:43 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
pPlayer->setCurrentZone( pZone );
|
|
|
|
pZone->pushActor( pPlayer );
|
2018-01-28 22:36:43 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
// map player to instanceId so it can be tracked.
|
|
|
|
m_playerIdToInstanceMap[ pPlayer->getId() ] = pZone->getGuId();
|
2018-02-04 17:46:46 +01:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
return true;
|
2018-01-28 22:36:43 +01:00
|
|
|
}
|
|
|
|
|
2018-02-04 17:46:46 +01:00
|
|
|
Core::ZonePtr Core::TerritoryMgr::getLinkedInstance( uint32_t playerId ) const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
auto it = m_playerIdToInstanceMap.find( playerId );
|
|
|
|
if( it != m_playerIdToInstanceMap.end() )
|
|
|
|
{
|
|
|
|
return getInstanceZonePtr( it->second );
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-02-04 17:46:46 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 20:30:05 +11:00
|
|
|
const uint16_t Core::TerritoryMgr::getCurrentFestival() const
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
return m_currentFestival;
|
2018-03-20 20:30:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::TerritoryMgr::setCurrentFestival( uint16_t festivalId )
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
m_currentFestival = festivalId;
|
2018-03-20 20:30:05 +11:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
for( const auto& zone : m_zoneSet )
|
|
|
|
{
|
|
|
|
zone->setCurrentFestival( m_currentFestival );
|
|
|
|
}
|
2018-03-20 20:30:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::TerritoryMgr::disableCurrentFestival()
|
|
|
|
{
|
2018-08-29 21:40:59 +02:00
|
|
|
setCurrentFestival( 0 );
|
2018-03-20 20:30:05 +11:00
|
|
|
}
|
|
|
|
|
2018-01-27 23:52:49 +01:00
|
|
|
|
2018-01-28 13:49:51 +01:00
|
|
|
|