1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 00:27:44 +00:00

More zone refactoring, general style fixes

This commit is contained in:
Mordred 2018-02-14 21:11:23 +01:00
parent e8ab570502
commit ddb4247588
4 changed files with 61 additions and 46 deletions

View file

@ -463,6 +463,7 @@ namespace Common {
//Weather.exd //Weather.exd
enum class Weather : uint8_t enum class Weather : uint8_t
{ {
None = 0,
ClearSkies = 1, ClearSkies = 1,
FairSkies = 2, FairSkies = 2,
Clouds = 3, Clouds = 3,

View file

@ -139,7 +139,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
player.sendNotice( "Race for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); player.sendNotice( "Race for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) );
targetPlayer->spawn( targetPlayer ); targetPlayer->spawn( targetPlayer );
auto inRange = targetPlayer->getInRangeActors(); auto inRange = targetPlayer->getInRangeActors();
for ( auto actor : inRange ) for( auto actor : inRange )
{ {
targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->despawn( actor->getAsPlayer() );
targetPlayer->spawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() );
@ -152,7 +152,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
player.sendNotice( "Tribe for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); player.sendNotice( "Tribe for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) );
targetPlayer->spawn( targetPlayer ); targetPlayer->spawn( targetPlayer );
auto inRange = targetPlayer->getInRangeActors(); auto inRange = targetPlayer->getInRangeActors();
for ( auto actor : inRange ) for( auto actor : inRange )
{ {
targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->despawn( actor->getAsPlayer() );
targetPlayer->spawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() );
@ -165,7 +165,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
player.sendNotice( "Sex for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) ); player.sendNotice( "Sex for " + targetPlayer->getName() + " was set to " + std::to_string( param1 ) );
targetPlayer->spawn( targetPlayer ); targetPlayer->spawn( targetPlayer );
auto inRange = targetActor->getInRangeActors(); auto inRange = targetActor->getInRangeActors();
for ( auto actor : inRange ) for( auto actor : inRange )
{ {
targetPlayer->despawn( actor->getAsPlayer() ); targetPlayer->despawn( actor->getAsPlayer() );
targetPlayer->spawn( actor->getAsPlayer() ); targetPlayer->spawn( actor->getAsPlayer() );
@ -180,14 +180,14 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Weather: case GmCommand::Weather:
{ {
targetPlayer->getCurrentZone()->setWeatherOverride( param1 ); targetPlayer->getCurrentZone()->setWeatherOverride( static_cast< Common::Weather >( param1 ) );
player.sendNotice( "Weather in Zone \"" + targetPlayer->getCurrentZone()->getName() + "\" of " + player.sendNotice( "Weather in Zone \"" + targetPlayer->getCurrentZone()->getName() + "\" of " +
targetPlayer->getName() + " set in range." ); targetPlayer->getName() + " set in range." );
break; break;
} }
case GmCommand::Call: case GmCommand::Call:
{ {
if ( targetPlayer->getZoneId() != player.getZoneId() ) if( targetPlayer->getZoneId() != player.getZoneId() )
targetPlayer->setZone( player.getZoneId() ); targetPlayer->setZone( player.getZoneId() );
targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z,
@ -266,7 +266,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Inv: case GmCommand::Inv:
{ {
if ( targetActor->getInvincibilityType() == Common::InvincibilityType::InvincibilityRefill ) if( targetActor->getInvincibilityType() == Common::InvincibilityType::InvincibilityRefill )
targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityNone ); targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityNone );
else else
targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityRefill ); targetActor->setInvincibilityType( Common::InvincibilityType::InvincibilityRefill );
@ -277,11 +277,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Orchestrion: case GmCommand::Orchestrion:
{ {
if ( param1 == 1 ) if( param1 == 1 )
{ {
if ( param2 == 0 ) if( param2 == 0 )
{ {
for ( uint8_t i = 0; i < 255; i++ ) for( uint8_t i = 0; i < 255; i++ )
targetActor->getAsPlayer()->learnSong( i, 0 ); targetActor->getAsPlayer()->learnSong( i, 0 );
player.sendNotice( "All Songs for " + targetPlayer->getName() + player.sendNotice( "All Songs for " + targetPlayer->getName() +
@ -324,7 +324,7 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
{ {
uint32_t gil = targetPlayer->getCurrency( 1 ); uint32_t gil = targetPlayer->getCurrency( 1 );
if ( gil < param1 ) if( gil < param1 )
{ {
player.sendUrgent( "Player does not have enough Gil(" + std::to_string( gil ) + ")" ); player.sendUrgent( "Player does not have enough Gil(" + std::to_string( gil ) + ")" );
} }
@ -379,11 +379,11 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Aetheryte: case GmCommand::Aetheryte:
{ {
if ( param1 == 0 ) if( param1 == 0 )
{ {
if ( param2 == 0 ) if( param2 == 0 )
{ {
for ( uint8_t i = 0; i < 255; i++ ) for( uint8_t i = 0; i < 255; i++ )
targetActor->getAsPlayer()->registerAetheryte( i ); targetActor->getAsPlayer()->registerAetheryte( i );
player.sendNotice( "All Aetherytes for " + targetPlayer->getName() + player.sendNotice( "All Aetherytes for " + targetPlayer->getName() +
@ -427,23 +427,23 @@ void Core::Network::GameConnection::gm1Handler( const Packets::GamePacket& inPac
} }
case GmCommand::TeriInfo: case GmCommand::TeriInfo:
{ {
auto pCurrentZone = player.getCurrentZone();
player.sendNotice( "ZoneId: " + std::to_string( player.getZoneId() ) + "\nName: " + player.sendNotice( "ZoneId: " + std::to_string( player.getZoneId() ) + "\nName: " +
player.getCurrentZone()->getName() + "\nInternalName: " + pCurrentZone->getName() + "\nInternalName: " +
player.getCurrentZone()->getInternalName() + "\nPopCount: " + pCurrentZone->getInternalName() + "\nPopCount: " +
std::to_string( player.getCurrentZone()->getPopCount() ) + std::to_string( pCurrentZone->getPopCount() ) +
"\nCurrentWeather:" + std::to_string( player.getCurrentZone()->getCurrentWeather() ) + "\nCurrentWeather:" + std::to_string( static_cast< uint8_t >( pCurrentZone->getCurrentWeather() ) ) +
"\nNextWeather:" + std::to_string( player.getCurrentZone()->getNextWeather() ) ); "\nNextWeather:" + std::to_string( static_cast< uint8_t >( pCurrentZone->getNextWeather() ) ) );
break; break;
} }
case GmCommand::Jump: case GmCommand::Jump:
{ {
auto inRange = player.getInRangeActors(); auto inRange = player.getInRangeActors();
for( auto actor : inRange )
{ player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z,
player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z, targetActor->getRotation() );
targetActor->getRotation() );
}
player.sendNotice( "Jumping to " + targetPlayer->getName() + " in range." ); player.sendNotice( "Jumping to " + targetPlayer->getName() + " in range." );
break; break;
} }
@ -517,7 +517,7 @@ void Core::Network::GameConnection::gm2Handler( const Packets::GamePacket& inPac
} }
case GmCommand::Call: case GmCommand::Call:
{ {
if ( targetPlayer->getZoneId() != player.getZoneId() ) if( targetPlayer->getZoneId() != player.getZoneId() )
targetPlayer->setZone( player.getZoneId() ); targetPlayer->setZone( player.getZoneId() );
targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z,

View file

@ -44,15 +44,15 @@ extern Core::TerritoryMgr g_territoryMgr;
Core::Zone::Zone() : Core::Zone::Zone() :
m_territoryId( 0 ), m_territoryId( 0 ),
m_guId( 0 ), m_guId( 0 ),
m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ), m_currentWeather( Common::Weather::FairSkies ),
m_weatherOverride( 0 ), m_weatherOverride( Common::Weather::None ),
m_lastMobUpdate( 0 ), m_lastMobUpdate( 0 ),
m_currentFestivalId( 0 ) m_currentFestivalId( 0 )
{ {
} }
Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName ) : Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& internalName, const std::string& placeName ) :
m_currentWeather( static_cast< uint8_t >( Common::Weather::FairSkies ) ) m_currentWeather( Common::Weather::FairSkies )
{ {
m_guId = guId; m_guId = guId;
@ -61,9 +61,22 @@ Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& intern
m_placeName = placeName; m_placeName = placeName;
m_lastMobUpdate = 0; m_lastMobUpdate = 0;
m_weatherOverride = 0; m_weatherOverride = Common::Weather::None;
m_territoryTypeInfo = g_exdDataGen.get< Core::Data::TerritoryType >( territoryId ); m_territoryTypeInfo = g_exdDataGen.get< Core::Data::TerritoryType >( territoryId );
loadWeatherRates();
m_currentWeather = getNextWeather();
}
void Core::Zone::loadWeatherRates()
{
if( !m_territoryTypeInfo )
{
g_log.error( std::string( __FUNCTION__ ) + " TerritoryTypeInfo not loaded!" );
return;
}
uint8_t weatherRateId = m_territoryTypeInfo->weatherRate > g_exdDataGen.getWeatherRateIdList().size() ? uint8_t weatherRateId = m_territoryTypeInfo->weatherRate > g_exdDataGen.getWeatherRateIdList().size() ?
uint8_t{ 0 } : m_territoryTypeInfo->weatherRate; uint8_t{ 0 } : m_territoryTypeInfo->weatherRate;
@ -80,8 +93,6 @@ Core::Zone::Zone( uint16_t territoryId, uint32_t guId, const std::string& intern
m_weatherRateMap[sumPc] = weatherId; m_weatherRateMap[sumPc] = weatherId;
i += 2; i += 2;
} }
m_currentWeather = getNextWeather();
} }
Core::Zone::~Zone() Core::Zone::~Zone()
@ -102,12 +113,12 @@ bool Core::Zone::init()
return true; return true;
} }
void Core::Zone::setWeatherOverride( uint8_t weather ) void Core::Zone::setWeatherOverride( Common::Weather weather )
{ {
m_weatherOverride = weather; m_weatherOverride = weather;
} }
uint8_t Core::Zone::getCurrentWeather() const Core::Common::Weather Core::Zone::getCurrentWeather() const
{ {
return m_currentWeather; return m_currentWeather;
} }
@ -227,7 +238,7 @@ void Core::Zone::loadCellCache()
} }
uint8_t Core::Zone::getNextWeather() Core::Common::Weather Core::Zone::getNextWeather()
{ {
uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() ); uint32_t unixTime = static_cast< uint32_t >( Util::getTimeSeconds() );
// Get Eorzea hour for weather start // Get Eorzea hour for weather start
@ -248,13 +259,13 @@ uint8_t Core::Zone::getNextWeather()
for( auto entry : m_weatherRateMap ) for( auto entry : m_weatherRateMap )
{ {
uint8_t sRate = entry.first; uint8_t sRate = entry.first;
auto weatherId = static_cast< uint8_t >( entry.second ); auto weatherId = static_cast< Common::Weather >( entry.second );
if( rate <= sRate ) if( rate <= sRate )
return weatherId; return weatherId;
} }
return 1; return Common::Weather::FairSkies;
} }
void Core::Zone::pushActor( Entity::ActorPtr pActor ) void Core::Zone::pushActor( Entity::ActorPtr pActor )
@ -407,22 +418,24 @@ std::size_t Core::Zone::getPopCount() const
bool Core::Zone::checkWeather() bool Core::Zone::checkWeather()
{ {
if ( m_weatherOverride != 0 ) if( m_weatherOverride != Common::Weather::None )
{ {
if ( m_weatherOverride != m_currentWeather ) if( m_weatherOverride != m_currentWeather )
{ {
m_currentWeather = m_weatherOverride; m_currentWeather = m_weatherOverride;
g_log.debug( "[Zone:" + m_internalName + "] overriding weather to : " + std::to_string( m_weatherOverride ) ); g_log.debug( "[Zone:" + m_internalName + "] overriding weather to : " +
std::to_string( static_cast< uint8_t >( m_weatherOverride ) ) );
return true; return true;
} }
} }
else else
{ {
auto nextWeather = getNextWeather(); auto nextWeather = getNextWeather();
if ( nextWeather != m_currentWeather ) if( nextWeather != m_currentWeather )
{ {
m_currentWeather = nextWeather; m_currentWeather = nextWeather;
g_log.debug( "[Zone:" + m_internalName + "] changing weather to : " + std::to_string( nextWeather ) ); g_log.debug( "[Zone:" + m_internalName + "] changing weather to : " +
std::to_string( static_cast< uint8_t >( nextWeather ) ) );
return true; return true;
} }
} }
@ -522,7 +535,7 @@ void Core::Zone::updateSessions( bool changedWeather )
{ {
Core::Network::Packets::ZoneChannelPacket< Core::Network::Packets::Server::FFXIVIpcWeatherChange > Core::Network::Packets::ZoneChannelPacket< Core::Network::Packets::Server::FFXIVIpcWeatherChange >
weatherChangePacket( pSession->getPlayer()->getId() ); weatherChangePacket( pSession->getPlayer()->getId() );
weatherChangePacket.data().weatherId = m_currentWeather; weatherChangePacket.data().weatherId = static_cast< uint8_t >( m_currentWeather );
weatherChangePacket.data().delay = 5.0f; weatherChangePacket.data().delay = 5.0f;
pSession->getPlayer()->queuePacket( weatherChangePacket ); pSession->getPlayer()->queuePacket( weatherChangePacket );
} }

View file

@ -44,8 +44,8 @@ protected:
CellCache** m_pCellCache[_sizeX]; CellCache** m_pCellCache[_sizeX];
uint8_t m_currentWeather; Common::Weather m_currentWeather;
uint8_t m_weatherOverride; Common::Weather m_weatherOverride;
uint64_t m_lastMobUpdate; uint64_t m_lastMobUpdate;
@ -65,9 +65,9 @@ public:
bool init(); bool init();
/*! overrides the zone's weather, set to 0 to unlock */ /*! overrides the zone's weather, set to 0 to unlock */
void setWeatherOverride( uint8_t weather ); void setWeatherOverride( Common::Weather weather );
uint8_t getCurrentWeather() const; Common::Weather getCurrentWeather() const;
uint16_t getCurrentFestival() const; uint16_t getCurrentFestival() const;
void setCurrentFestival( uint16_t festivalId ); void setCurrentFestival( uint16_t festivalId );
@ -84,7 +84,7 @@ public:
virtual void onLeaveTerritory( Entity::Player& player ); virtual void onLeaveTerritory( Entity::Player& player );
virtual void onUpdate( uint32_t currTime ); virtual void onUpdate( uint32_t currTime );
uint8_t getNextWeather(); Common::Weather getNextWeather();
void pushActor( Entity::ActorPtr pActor ); void pushActor( Entity::ActorPtr pActor );
@ -106,6 +106,7 @@ public:
const std::string& getInternalName() const; const std::string& getInternalName() const;
std::size_t getPopCount() const; std::size_t getPopCount() const;
void loadWeatherRates();
bool checkWeather(); bool checkWeather();
void updateBnpcs( int64_t tickCount ); void updateBnpcs( int64_t tickCount );