From 0c1bbfb8d0923d531024c6cb642dd5de8b1cbca9 Mon Sep 17 00:00:00 2001 From: Mordred Date: Mon, 10 Jan 2022 23:50:44 +0100 Subject: [PATCH] Removing references to getCurrentTerritory in preparation for further detangleing --- src/common/Common.h | 6 +- src/common/Util/UtilMath.cpp | 2 +- .../common/aethernet/HousingAethernet.cpp | 7 +- .../common/eobj/HousingEstateEntrance.cpp | 3 +- .../common/housing/CmnDefHousingSignboard.cpp | 7 +- src/world/Action/EffectBuilder.cpp | 18 ++- src/world/Actor/BNpc.cpp | 36 +++-- src/world/Actor/Chara.cpp | 5 +- src/world/Actor/GameObject.cpp | 33 ++++- src/world/Actor/GameObject.h | 10 +- src/world/Actor/Player.cpp | 59 ++++---- src/world/Actor/Player.h | 8 -- src/world/Manager/DebugCommandMgr.cpp | 60 ++++---- src/world/Manager/HousingMgr.cpp | 128 +++++++++--------- src/world/Manager/HousingMgr.h | 6 +- src/world/Manager/TerritoryMgr.cpp | 22 +-- src/world/Manager/TerritoryMgr.h | 4 +- src/world/Manager/WarpMgr.h | 47 +++++++ .../Network/Handlers/CommonListHandler.cpp | 9 +- .../Network/Handlers/GMCommandHandlers.cpp | 64 +++++---- .../Network/Handlers/PacketCommandHandler.cpp | 20 +-- src/world/Network/Handlers/PacketHandlers.cpp | 35 +++-- src/world/Network/PacketWrappers/WarpPacket.h | 4 +- src/world/Script/ScriptMgr.cpp | 6 +- src/world/Territory/Territory.cpp | 10 +- src/world/Territory/Territory.h | 3 +- 26 files changed, 353 insertions(+), 259 deletions(-) create mode 100644 src/world/Manager/WarpMgr.h diff --git a/src/common/Common.h b/src/common/Common.h index 88c1b363..5a6efcdc 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -234,7 +234,7 @@ namespace Sapphire::Common Enemy = 4, }; - enum ACTOR_KIND : int32_t + enum ActorKind : int32_t { ACTOR_KIND_PC = 0x0, ACTOR_KIND_NPC = 0x1, @@ -247,7 +247,7 @@ namespace Sapphire::Common ACTOR_KIND_MAX = 0x8, }; - enum OBJECT_TYPE : int32_t + enum ObjectType : int32_t { OBJECT_TYPE_CAMERA = 0x0, OBJECT_TYPE_CAMERA_MAYA = 0x1, @@ -263,7 +263,7 @@ namespace Sapphire::Common OBJECT_TYPE_COUNT_MAX = 0xB, }; - enum WARP_TYPE : uint8_t + enum WarpType : uint8_t { WARP_TYPE_NON = 0x0, WARP_TYPE_NORMAL = 0x1, diff --git a/src/common/Util/UtilMath.cpp b/src/common/Util/UtilMath.cpp index b2255bac..4dd3b60e 100644 --- a/src/common/Util/UtilMath.cpp +++ b/src/common/Util/UtilMath.cpp @@ -139,7 +139,7 @@ float Util::trunc( float value, uint8_t digitsToRemain ) if( digitsToRemain == 0 ) return std::floor( value ); - float factor = std::pow( 10, digitsToRemain ); + float factor = std::powf( 10, digitsToRemain ); return std::floor( value * factor ) / factor; } diff --git a/src/scripts/common/aethernet/HousingAethernet.cpp b/src/scripts/common/aethernet/HousingAethernet.cpp index 8c2e1d51..df094c89 100644 --- a/src/scripts/common/aethernet/HousingAethernet.cpp +++ b/src/scripts/common/aethernet/HousingAethernet.cpp @@ -23,9 +23,8 @@ public: { auto& exdData = Common::Service< Sapphire::Data::ExdData >::ref(); - auto housingZone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); - if( !housingZone ) - return; + auto housingZoneId = player.getTerritoryTypeId(); + auto activeLand = player.getActiveLand(); return; // param2 is the index starting from 0 inside housingaethernet.exd, but the ID column starts at 0x001E0000........ wtf @@ -34,7 +33,7 @@ public: return; // check we're teleporting to the same territorytype - if( player.getCurrentTerritory()->getTerritoryTypeId() != pHousingAethernet->territoryType ) + if( player.getTerritoryTypeId() != pHousingAethernet->territoryType ) return; // todo: this needs to be done properly and used queued zoning + aethernet animation diff --git a/src/scripts/common/eobj/HousingEstateEntrance.cpp b/src/scripts/common/eobj/HousingEstateEntrance.cpp index 1a90ddf0..a0fbbd08 100644 --- a/src/scripts/common/eobj/HousingEstateEntrance.cpp +++ b/src/scripts/common/eobj/HousingEstateEntrance.cpp @@ -31,7 +31,8 @@ public: auto& terriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref(); - auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); + auto pHZone = terriMgr.getZoneByTerritoryTypeId( player.getTerritoryTypeId() ); + auto zone = std::dynamic_pointer_cast< HousingZone >( pHZone ); if( !zone ) return; diff --git a/src/scripts/common/housing/CmnDefHousingSignboard.cpp b/src/scripts/common/housing/CmnDefHousingSignboard.cpp index cfec264c..8153b9e3 100644 --- a/src/scripts/common/housing/CmnDefHousingSignboard.cpp +++ b/src/scripts/common/housing/CmnDefHousingSignboard.cpp @@ -8,6 +8,7 @@ #include #include #include "Manager/PlayerMgr.h" +#include "Manager/TerritoryMgr.h" using namespace Sapphire; using namespace Network; @@ -33,12 +34,12 @@ public: auto activeLand = player.getActiveLand(); auto territoryId = player.getTerritoryId(); - auto pTerritory = player.getCurrentTerritory(); + auto& terriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref(); + auto pTerritory = terriMgr.getZoneByTerritoryTypeId( player.getTerritoryTypeId() ); auto pHousing = std::dynamic_pointer_cast< HousingZone >( pTerritory ); auto& pHouMgr = Common::Service< HousingMgr >::ref(); - LandPurchaseResult res = pHouMgr.purchaseLand( player, activeLand.plot, - static_cast< uint8_t >( result.getResult( 0 ) ) ); + LandPurchaseResult res = pHouMgr.purchaseLand( player, *pHousing, activeLand.plot, static_cast< uint8_t >( result.getResult( 0 ) ) ); auto& server = Common::Service< World::WorldServer >::ref(); switch( res ) diff --git a/src/world/Action/EffectBuilder.cpp b/src/world/Action/EffectBuilder.cpp index 540f5182..b0a9dbbd 100644 --- a/src/world/Action/EffectBuilder.cpp +++ b/src/world/Action/EffectBuilder.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include using namespace Sapphire; using namespace Sapphire::World::Action; @@ -105,6 +107,11 @@ void EffectBuilder::buildAndSendPackets( const std::vector< Entity::CharaPtr >& Logger::debug( "EffectBuilder result: " ); Logger::debug( "Targets afflicted: {}", targetList.size() ); + auto& teriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref(); + auto zone = teriMgr.getZoneByTerritoryTypeId( m_sourceChara->getTerritoryTypeId() ); + + auto globalSequence = zone ? zone->getNextEffectSequence() : 0; + do // we want to send at least one packet even nothing is hit so other players can see { auto packet = buildNextEffectPacket( targetList ); @@ -118,6 +125,9 @@ std::shared_ptr< FFXIVPacketBase > EffectBuilder::buildNextEffectPacket( const s auto remainingTargetCount = targetList.size(); auto globalSequence = m_sourceChara->getCurrentTerritory()->getNextEffectSequence(); + auto& teriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref(); + auto zone = teriMgr.getZoneByTerritoryTypeId( m_sourceChara->getTerritoryTypeId() ); + if( remainingTargetCount > 1 ) // use AoeEffect packets { auto effectPacket = std::make_shared< EffectPacket >( m_sourceChara->getId(), m_actionId ); @@ -145,8 +155,9 @@ std::shared_ptr< FFXIVPacketBase > EffectBuilder::buildNextEffectPacket( const s { effectPacket->addTargetEffect( effect, result->getTarget()->getId() ); } - - m_sourceChara->getCurrentTerritory()->addEffectResult( std::move( result ) ); + + zone->addEffectResult( std::move( result ) ); + } actorResultList.clear(); @@ -161,6 +172,7 @@ std::shared_ptr< FFXIVPacketBase > EffectBuilder::buildNextEffectPacket( const s } else if( remainingTargetCount == 1 ) // use Effect for single target { + Logger::debug( " - id: {}", targetList[0]->getId() ); Logger::debug( "------------------------------------------" ); @@ -188,7 +200,7 @@ std::shared_ptr< FFXIVPacketBase > EffectBuilder::buildNextEffectPacket( const s effectPacket->addTargetEffect( effect ); } - m_sourceChara->getCurrentTerritory()->addEffectResult( std::move( result ) ); + zone->addEffectResult( std::move( result ) ); } actorResultList.clear(); diff --git a/src/world/Actor/BNpc.cpp b/src/world/Actor/BNpc.cpp index 21efd503..3b022dc3 100644 --- a/src/world/Actor/BNpc.cpp +++ b/src/world/Actor/BNpc.cpp @@ -102,7 +102,8 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance m_class = ClassJob::Gladiator; - m_pCurrentTerritory = std::move( pZone ); + m_territoryTypeId = pZone->getTerritoryTypeId(); + m_territoryId = pZone->getGuId(); m_spawnPos = m_pos; @@ -198,6 +199,9 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance m_flags = 0; m_rank = pInfo->BNPCRankId; + m_territoryTypeId = pZone->getTerritoryTypeId(); + m_territoryId = pZone->getGuId(); + if( pInfo->WanderingRange == 0 || pInfo->BoundInstanceID != 0 ) setFlag( Immobile ); @@ -215,8 +219,6 @@ Sapphire::Entity::BNpc::BNpc( uint32_t id, std::shared_ptr< Common::BNPCInstance m_class = ClassJob::Gladiator; - m_pCurrentTerritory = std::move( pZone ); - m_spawnPos = m_pos; m_timeOfDeath = 0; @@ -350,14 +352,14 @@ void Sapphire::Entity::BNpc::setState( BNpcState state ) bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); - auto pNaviProvider = m_pCurrentTerritory->getNaviProvider(); + auto pNaviProvider = pZone->getNaviProvider(); if( !pNaviProvider ) { - Logger::error( "No NaviProvider for zone#{0} - {1}", - m_pCurrentTerritory->getGuId(), - m_pCurrentTerritory->getInternalName() ); + Logger::error( "No NaviProvider for zone#{0} - {1}", pZone->getGuId(), pZone->getInternalName() ); return false; } @@ -374,7 +376,7 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos ) return true; } - m_pCurrentTerritory->updateActorPosition( *this ); + pZone->updateActorPosition( *this ); face( pos ); if( distance > 2.0f ) face( { ( pos.x - pos1.x ) + pos.x, 1.0f, ( pos.z - pos1.z ) + pos.z } ); @@ -388,11 +390,14 @@ bool Sapphire::Entity::BNpc::moveTo( const FFXIVARR_POSITION3& pos ) bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara ) { - auto pNaviProvider = m_pCurrentTerritory->getNaviProvider(); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + + auto pNaviProvider = pZone->getNaviProvider(); if( !pNaviProvider ) { - Logger::error( "No NaviProvider for zone#{0} - {1}", m_pCurrentTerritory->getGuId(), m_pCurrentTerritory->getInternalName() ); + Logger::error( "No NaviProvider for zone#{0} - {1}", pZone->getGuId(), pZone->getInternalName() ); return false; } @@ -410,7 +415,7 @@ bool Sapphire::Entity::BNpc::moveTo( const Entity::Chara& targetChara ) return true; } - m_pCurrentTerritory->updateActorPosition( *this ); + pZone->updateActorPosition( *this ); if( distance > 2.0f ) face( { ( pos1.x - getPos().x ) + pos1.x, 1.0f, ( pos1.z - getPos().z ) + pos1.z } ); else @@ -570,10 +575,13 @@ void Sapphire::Entity::BNpc::onTick() void Sapphire::Entity::BNpc::update( uint64_t tickCount ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + const uint8_t maxDistanceToOrigin = 40; const uint32_t roamTick = 20; - auto pNaviProvider = m_pCurrentTerritory->getNaviProvider(); + auto pNaviProvider = pZone->getNaviProvider(); if( !pNaviProvider ) return; @@ -896,6 +904,8 @@ void Sapphire::Entity::BNpc::setFlag( uint32_t flag ) void Sapphire::Entity::BNpc::autoAttack( CharaPtr pTarget ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); uint64_t tick = Util::getTimeMs(); @@ -918,7 +928,7 @@ void Sapphire::Entity::BNpc::autoAttack( CharaPtr pTarget ) effectEntry.Arg0 = 3; effectEntry.Arg1 = 7; //effectEntry.Arg2 = 0x71; - effectPacket->setSequence( getCurrentTerritory()->getNextEffectSequence() ); + effectPacket->setSequence( pZone->getNextEffectSequence() ); effectPacket->addTargetEffect( effectEntry ); sendToInRangeSet( effectPacket ); diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 4d5924d6..9f3d93da 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -513,6 +513,9 @@ void Sapphire::Entity::Chara::autoAttack( CharaPtr pTarget ) /*! \param StatusEffectPtr to be applied to the actor */ void Sapphire::Entity::Chara::addStatusEffect( StatusEffect::StatusEffectPtr pEffect ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + int8_t nextSlot = getStatusEffectFreeSlot(); // if there is no slot left, do not add the effect if( nextSlot == -1 ) @@ -523,7 +526,7 @@ void Sapphire::Entity::Chara::addStatusEffect( StatusEffect::StatusEffectPtr pEf auto statusEffectAdd = makeZonePacket< FFXIVIpcActionIntegrity >( getId() ); - statusEffectAdd->data().ResultId = getCurrentTerritory()->getNextEffectSequence(); + statusEffectAdd->data().ResultId = pZone->getNextEffectSequence(); statusEffectAdd->data().Target = pEffect->getTargetActorId(); statusEffectAdd->data().Hp = getHp(); statusEffectAdd->data().Mp = static_cast< uint16_t >( getMp() ); diff --git a/src/world/Actor/GameObject.cpp b/src/world/Actor/GameObject.cpp index 75dcf6c7..38ab6c78 100644 --- a/src/world/Actor/GameObject.cpp +++ b/src/world/Actor/GameObject.cpp @@ -67,7 +67,12 @@ void Sapphire::Entity::GameObject::setPos( float x, float y, float z, bool broad m_pos.z = z; if( broadcastUpdate ) - m_pCurrentTerritory->updateActorPosition( *this ); + { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + pZone->updateActorPosition( *this ); + } + } void Sapphire::Entity::GameObject::setPos( const Sapphire::Common::FFXIVARR_POSITION3& pos, bool broadcastUpdate ) @@ -75,7 +80,11 @@ void Sapphire::Entity::GameObject::setPos( const Sapphire::Common::FFXIVARR_POSI m_pos = pos; if( broadcastUpdate ) - m_pCurrentTerritory->updateActorPosition( *this ); + { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + pZone->updateActorPosition( *this ); + } } float Sapphire::Entity::GameObject::getRot() const @@ -338,12 +347,32 @@ Sapphire::TerritoryPtr Sapphire::Entity::GameObject::getCurrentTerritory() const return m_pCurrentTerritory; } +uint32_t Sapphire::Entity::GameObject::getTerritoryTypeId() const +{ + return m_territoryTypeId; +} + /*! \param TerritoryPtr to the zone to be set as current */ void Sapphire::Entity::GameObject::setCurrentZone( TerritoryPtr currZone ) { m_pCurrentTerritory = currZone; } +void Sapphire::Entity::GameObject::setTerritoryTypeId( uint32_t territoryTypeId ) +{ + m_territoryTypeId = territoryTypeId; +} + +uint32_t Sapphire::Entity::GameObject::getTerritoryId() const +{ + return m_territoryId; +} + +void Sapphire::Entity::GameObject::setTerritoryId( uint32_t territoryId ) +{ + m_territoryId = territoryId; +} + /*! \return InstanceContentPtr to the current instance, nullptr if not an instance or not set */ Sapphire::InstanceContentPtr Sapphire::Entity::GameObject::getCurrentInstance() const { diff --git a/src/world/Actor/GameObject.h b/src/world/Actor/GameObject.h index 853b8a38..8f23f68a 100644 --- a/src/world/Actor/GameObject.h +++ b/src/world/Actor/GameObject.h @@ -28,8 +28,10 @@ namespace Sapphire::Entity uint32_t m_id{}; /*! Type of the actor */ Common::ObjKind m_objKind; - /*! Id of the zone the actor currently is in */ + /*! Id of the territory type the actor currently is in */ uint32_t m_territoryTypeId{}; + /*! Specific GUId of the zone the actor currently is in */ + uint32_t m_territoryId{}; /*! Ptr to the ZoneObj the actor belongs to */ TerritoryPtr m_pCurrentTerritory; @@ -123,6 +125,12 @@ namespace Sapphire::Entity TerritoryPtr getCurrentTerritory() const; + uint32_t getTerritoryTypeId() const; + void setTerritoryTypeId( uint32_t territoryTypeId ); + + uint32_t getTerritoryId() const; + void setTerritoryId( uint32_t territoryTypeId ); + void setCurrentZone( TerritoryPtr currZone ); InstanceContentPtr getCurrentInstance() const; diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 82e9df4e..7752dd30 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -156,21 +156,11 @@ uint16_t Sapphire::Entity::Player::getZoneId() const return m_territoryTypeId; } -uint32_t Sapphire::Entity::Player::getTerritoryId() const -{ - return m_territoryId; -} - uint32_t Sapphire::Entity::Player::getPrevTerritoryId() const { return m_prevTerritoryId; } -void Sapphire::Entity::Player::setTerritoryId( uint32_t territoryId ) -{ - m_territoryId = territoryId; -} - uint8_t Sapphire::Entity::Player::getGmRank() const { return m_gmRank; @@ -507,14 +497,17 @@ void Sapphire::Entity::Player::setZone( uint32_t zoneId ) { auto& teriMgr = Common::Service< TerritoryMgr >::ref(); m_onEnterEventDone = false; - if( !teriMgr.movePlayer( zoneId, *this ) ) + + auto pZone = teriMgr.getZoneByTerritoryTypeId( zoneId ); + if( !teriMgr.movePlayer( pZone, *this ) ) { // todo: this will require proper handling, for now just return the player to their previous area m_pos = m_prevPos; m_rot = m_prevRot; m_territoryTypeId = m_prevTerritoryTypeId; - if( !teriMgr.movePlayer( m_territoryTypeId, *this ) ) + auto pZone1 = teriMgr.getZoneByTerritoryTypeId( m_territoryTypeId ); + if( !teriMgr.movePlayer( pZone1, *this ) ) return; } } @@ -538,15 +531,15 @@ bool Sapphire::Entity::Player::setInstance( const TerritoryPtr& instance ) return false; auto& teriMgr = Common::Service< TerritoryMgr >::ref(); - auto currentZone = getCurrentTerritory(); // zoning within the same zone won't cause the prev data to be overwritten if( instance->getTerritoryTypeId() != m_territoryTypeId ) { + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + m_prevTerritoryTypeId = pZone->getTerritoryTypeId(); + m_prevTerritoryId = getTerritoryId(); m_prevPos = m_pos; m_prevRot = m_rot; - m_prevTerritoryTypeId = currentZone->getTerritoryTypeId(); - m_prevTerritoryId = getTerritoryId(); } return teriMgr.movePlayer( instance, *this ); @@ -559,15 +552,15 @@ bool Sapphire::Entity::Player::setInstance( const TerritoryPtr& instance, Common return false; auto& teriMgr = Common::Service< TerritoryMgr >::ref(); - auto currentZone = getCurrentTerritory(); // zoning within the same zone won't cause the prev data to be overwritten if( instance->getTerritoryTypeId() != m_territoryTypeId ) { + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + m_prevTerritoryTypeId = pZone->getTerritoryTypeId(); + m_prevTerritoryId = getTerritoryId(); m_prevPos = m_pos; m_prevRot = m_rot; - m_prevTerritoryTypeId = currentZone->getTerritoryTypeId(); - m_prevTerritoryId = getTerritoryId(); } if( teriMgr.movePlayer( instance, *this ) ) @@ -582,8 +575,7 @@ bool Sapphire::Entity::Player::setInstance( const TerritoryPtr& instance, Common bool Sapphire::Entity::Player::exitInstance() { auto& teriMgr = Common::Service< TerritoryMgr >::ref(); - - auto pZone = getCurrentTerritory(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); auto pInstance = pZone->getAsInstanceContent(); resetHp(); @@ -597,7 +589,8 @@ bool Sapphire::Entity::Player::exitInstance() } else { - if( !teriMgr.movePlayer( m_prevTerritoryTypeId, *this ) ) + auto pPrevZone = teriMgr.getZoneByTerritoryTypeId( m_prevTerritoryTypeId ); + if( !teriMgr.movePlayer( pPrevZone, *this ) ) return false; } @@ -1117,7 +1110,7 @@ void Sapphire::Entity::Player::update( uint64_t tickCount ) if( m_queuedZoneing && ( tickCount - m_queuedZoneing->m_queueTime ) > 800 ) { Common::FFXIVARR_POSITION3 targetPos = m_queuedZoneing->m_targetPosition; - if( getCurrentTerritory()->getTerritoryTypeId() != m_queuedZoneing->m_targetZone ) + if( getTerritoryTypeId() != m_queuedZoneing->m_targetZone ) { performZoning( m_queuedZoneing->m_targetZone, targetPos, m_queuedZoneing->m_targetRotation ); } @@ -1490,6 +1483,9 @@ uint32_t Sapphire::Entity::Player::getPersistentEmote() const void Sapphire::Entity::Player::autoAttack( CharaPtr pTarget ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + auto mainWeap = getItemAt( Common::GearSet0, Common::GearSetSlot::MainHand ); pTarget->onActionHostile( getAsChara() ); @@ -1522,7 +1518,7 @@ void Sapphire::Entity::Player::autoAttack( CharaPtr pTarget ) //entry.Arg2 = 0x73; } - effectPacket->setSequence( getCurrentTerritory()->getNextEffectSequence() ); + effectPacket->setSequence( pZone->getNextEffectSequence() ); effectPacket->setRotation( Util::floatToUInt16Rot( getRot() ) ); effectPacket->addTargetEffect( entry ); @@ -1591,16 +1587,6 @@ void Sapphire::Entity::Player::setEorzeaTimeOffset( uint64_t timestamp ) queuePacket( packet ); } -void Sapphire::Entity::Player::setTerritoryTypeId( uint32_t territoryTypeId ) -{ - m_territoryTypeId = territoryTypeId; -} - -uint32_t Sapphire::Entity::Player::getTerritoryTypeId() const -{ - return m_territoryTypeId; -} - uint32_t Sapphire::Entity::Player::getPrevTerritoryTypeId() const { return m_prevTerritoryTypeId; @@ -1608,6 +1594,9 @@ uint32_t Sapphire::Entity::Player::getPrevTerritoryTypeId() const void Sapphire::Entity::Player::sendZonePackets() { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( getTerritoryId() ); + auto initPacket = makeZonePacket< FFXIVIpcLogin >( getId() ); initPacket->data().playerActorId = getId(); queuePacket( initPacket ); @@ -1664,9 +1653,9 @@ void Sapphire::Entity::Player::sendZonePackets() sendLandFlags(); - queuePacket( makeInitZone( *this, *getCurrentTerritory() ) ); + queuePacket( makeInitZone( *this, *pZone ) ); - getCurrentTerritory()->onPlayerZoneIn( *this ); + pZone->onPlayerZoneIn( *this ); if( isLogin() ) { diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index cc76b759..93600445 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -317,11 +317,7 @@ namespace Sapphire::Entity /*! returns the player to their position before zoning into an instance */ bool exitInstance(); - /*! sets the players territoryTypeId */ - void setTerritoryTypeId( uint32_t territoryTypeId ); - /*! gets the players territoryTypeId */ - uint32_t getTerritoryTypeId() const; uint32_t getPrevTerritoryTypeId() const; void forceZoneing( uint32_t zoneId ); @@ -644,9 +640,6 @@ namespace Sapphire::Entity uint16_t getZoneId() const; - uint32_t getTerritoryId() const; - void setTerritoryId( uint32_t territoryId ); - uint32_t getPrevTerritoryId() const; uint8_t getGmRank() const; @@ -933,7 +926,6 @@ namespace Sapphire::Entity bool m_bAutoattack; Common::ZoneingType m_zoningType; - uint32_t m_territoryId{}; bool m_bMarkedForZoning; bool m_bNewAdventurer{}; diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index 131edd81..64357c0b 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -151,8 +151,9 @@ void Sapphire::World::Manager::DebugCommandMgr::set( char* data, Entity::Player& { auto& server = Sapphire::Common::Service< Sapphire::World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); - auto& terriMgr = Common::Service< TerritoryMgr >::ref(); + auto pCurrentZone = terriMgr.getTerritoryByGuId( player.getTerritoryId() ); + auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); std::string subCommand = ""; std::string params = ""; @@ -270,7 +271,7 @@ void Sapphire::World::Manager::DebugCommandMgr::set( char* data, Entity::Player& sscanf( params.c_str(), "%d", &weatherId ); - player.getCurrentTerritory()->setWeatherOverride( static_cast< Common::Weather >( weatherId ) ); + pCurrentZone->setWeatherOverride( static_cast< Common::Weather >( weatherId ) ); } else if( subCommand == "festival" ) { @@ -387,6 +388,8 @@ void Sapphire::World::Manager::DebugCommandMgr::add( char* data, Entity::Player& { auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); + auto& terriMgr = Common::Service< TerritoryMgr >::ref(); + auto pCurrentZone = terriMgr.getTerritoryByGuId( player.getTerritoryId() ); std::string subCommand; std::string params = ""; @@ -503,7 +506,7 @@ void Sapphire::World::Manager::DebugCommandMgr::add( char* data, Entity::Player& effectPacket->addTargetEffect( entry, static_cast< uint64_t >( player.getId() ) ); - auto sequence = player.getCurrentTerritory()->getNextEffectSequence(); + auto sequence = pCurrentZone->getNextEffectSequence(); effectPacket->setSequence( sequence ); // effectPacket->setAnimationId( param1 ); @@ -546,11 +549,11 @@ void Sapphire::World::Manager::DebugCommandMgr::get( char* data, Entity::Player& if( ( subCommand == "pos" ) ) { - int16_t map_id = exdData.getRow< Component::Excel::TerritoryType >( player.getCurrentTerritory()->getTerritoryTypeId() )->data().Map; + int16_t map_id = exdData.getRow< Component::Excel::TerritoryType >( player.getTerritoryTypeId() )->data().Map; PlayerMgr::sendServerNotice( player, "Pos:\n {0}\n {1}\n {2}\n {3}\n MapId: {4}\n ZoneId:{5}", player.getPos().x, player.getPos().y, player.getPos().z, - player.getRot(), map_id, player.getCurrentTerritory()->getTerritoryTypeId()); + player.getRot(), map_id, player.getTerritoryTypeId() ); } else { @@ -784,6 +787,8 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl std::shared_ptr< DebugCommand > command ) { auto& terriMgr = Common::Service< TerritoryMgr >::ref(); + auto pCurrentZone = terriMgr.getTerritoryByGuId( player.getTerritoryId() ); + std::string cmd( data ), params, subCommand; auto cmdPos = cmd.find_first_of( ' ' ); @@ -890,7 +895,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%d", &mode ); if( mode < 5 ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -899,7 +904,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "todo" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -909,7 +914,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "time" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -922,7 +927,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "fail" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -938,7 +943,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%d %d", &index, &value ); - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -951,7 +956,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%s %hhu", objName, &state ); - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -969,7 +974,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%s %i %i", objName, &state1, &state2 ); - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -988,7 +993,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%hhu", &seq ); - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -1000,7 +1005,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl sscanf( params.c_str(), "%hhu", &flags ); - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -1008,7 +1013,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "qte_start" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -1017,7 +1022,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "event_start" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -1026,7 +1031,7 @@ void Sapphire::World::Manager::DebugCommandMgr::instance( char* data, Entity::Pl } else if( subCommand == "event_end" ) { - auto instance = std::dynamic_pointer_cast< InstanceContent >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< InstanceContent >( pCurrentZone ); if( !instance ) return; @@ -1051,6 +1056,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: std::shared_ptr< DebugCommand > command ) { auto& terriMgr = Common::Service< TerritoryMgr >::ref(); + auto pCurrentZone = terriMgr.getTerritoryByGuId( player.getTerritoryId() ); std::string cmd( data ), params, subCommand; auto cmdPos = cmd.find_first_of( ' ' ); @@ -1083,7 +1089,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: else if( subCommand == "complete" ) { - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1093,7 +1099,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: else if( subCommand == "fail" ) { - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1133,7 +1139,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: sscanf( params.c_str(), "%d %d", &index, &value ); - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1146,7 +1152,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: sscanf( params.c_str(), "%s %hhu", objName, &state ); - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1164,7 +1170,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: sscanf( params.c_str(), "%s %i %i", objName, &state1, &state2 ); - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1183,7 +1189,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: sscanf( params.c_str(), "%hhu", &seq ); - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1195,7 +1201,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: sscanf( params.c_str(), "%hhu", &flags ); - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1203,7 +1209,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: } else if( subCommand == "qte_start" ) { - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1212,7 +1218,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: } else if( subCommand == "event_start" ) { - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; @@ -1221,7 +1227,7 @@ void Sapphire::World::Manager::DebugCommandMgr::questBattle( char* data, Entity: } else if( subCommand == "event_end" ) { - auto instance = std::dynamic_pointer_cast< QuestBattle >( player.getCurrentTerritory() ); + auto instance = std::dynamic_pointer_cast< QuestBattle >( pCurrentZone ); if( !instance ) return; diff --git a/src/world/Manager/HousingMgr.cpp b/src/world/Manager/HousingMgr.cpp index 55ffa0a8..e417de72 100644 --- a/src/world/Manager/HousingMgr.cpp +++ b/src/world/Manager/HousingMgr.cpp @@ -24,6 +24,7 @@ #include "Territory/Housing/HousingInteriorTerritory.h" #include "HousingMgr.h" #include "EventMgr.h" +#include "TerritoryMgr.h" #include "Territory/Land.h" #include "WorldServer.h" #include "Territory/House.h" @@ -370,13 +371,12 @@ void Sapphire::World::Manager::HousingMgr::sendLandSignFree( Entity::Player& pla pSession->getZoneConnection()->queueOutPacket( plotPricePacket ); } -Sapphire::LandPurchaseResult Sapphire::World::Manager::HousingMgr::purchaseLand( Entity::Player& player, uint8_t plot, uint8_t state ) +Sapphire::LandPurchaseResult Sapphire::World::Manager::HousingMgr::purchaseLand( Entity::Player& player, HousingZone& zone, uint8_t plot, uint8_t state ) { - auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); - auto plotPrice = pHousing->getLand( plot )->getCurrentPrice(); + auto plotPrice = zone.getLand( plot )->getCurrentPrice(); auto gilAvailable = player.getCurrency( CurrencyType::Gil ); - auto pLand = pHousing->getLand( plot ); + auto pLand = zone.getLand( plot ); if( !pLand ) return LandPurchaseResult::ERR_INTERNAL; @@ -413,7 +413,7 @@ Sapphire::LandPurchaseResult Sapphire::World::Manager::HousingMgr::purchaseLand( //pLand->setLandName( "Private Estate" + std::to_string( pHousing->getWardNum() ) + "-" + std::to_string( plot ) ); pLand->updateLandDb(); - pHousing->sendLandUpdate( plot ); + zone.sendLandUpdate( plot ); return LandPurchaseResult::SUCCESS; } @@ -423,16 +423,15 @@ Sapphire::LandPurchaseResult Sapphire::World::Manager::HousingMgr::purchaseLand( } -bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& player, uint8_t plot ) +bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& player, HousingZone& zone, uint8_t plot ) { auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); // TODO: Fix "permissions" being sent incorrectly // TODO: Add checks for land state before relinquishing - auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); - auto pLand = pHousing->getLand( plot ); + auto pLand = zone.getLand( plot ); auto plotMaxPrice = pLand->getCurrentPrice(); // can't relinquish when you are not the owner @@ -468,7 +467,7 @@ bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& playe auto screenMsgPkt2 = makeActorControlSelf( player.getId(), ActorControl::LogMsg, 3351, 0x1AA, pLand->getLandIdent().wardNum + 1, plot + 1 ); pSession->getZoneConnection()->queueOutPacket( screenMsgPkt2 ); - pHousing->sendLandUpdate( plot ); + zone.sendLandUpdate( plot ); return true; } @@ -677,17 +676,12 @@ void Sapphire::World::Manager::HousingMgr::createHouse( Sapphire::HousePtr house db.execute( stmt ); } -void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetCatalogId ) +void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& player, HousingZone& zone, uint8_t plotNum, uint32_t presetCatalogId ) { auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); - auto hZone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); - - if( !hZone ) - return; - - auto pLand = hZone->getLand( plotNum ); + auto pLand = zone.getLand( plotNum ); if( !pLand ) return; @@ -714,7 +708,7 @@ void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& pl pLand->setStatus( HouseStatus::PrivateEstate ); pLand->setLandType( LandType::Private ); - hZone->sendLandUpdate( plotNum ); + zone.sendLandUpdate( plotNum ); auto pSuccessBuildingPacket = makeActorControl( player.getId(), ActorControl::BuildPresetResponse, plotNum ); @@ -730,7 +724,7 @@ void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& pl player.setLandFlags( LandFlagsSlot::Private, HOUSING_LAND_STATUS::HOUSING_LAND_STATUS_BUILDHOUSE, ident ); player.sendLandFlagsSlot( LandFlagsSlot::Private ); - hZone->registerEstateEntranceEObj( plotNum ); + zone.registerEstateEntranceEObj( plotNum ); } void Sapphire::World::Manager::HousingMgr::requestEstateRename( Entity::Player& player, const Common::LandIdent ident ) @@ -855,17 +849,17 @@ Sapphire::Common::LandIdent Sapphire::World::Manager::HousingMgr::clientTriggerP return ident; } -void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player& player, uint16_t inventoryType, - uint8_t plotNum ) +void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player& player, uint16_t inventoryType, uint8_t plotNum ) { Sapphire::LandPtr targetLand; + auto& teriMgr = Common::Service< TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); // plotNum will be 255 in the event that it's an internal zone // and we have to switch up our way of getting the LandPtr if( plotNum == 255 ) { - auto internalZone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( - player.getCurrentTerritory() ); + auto internalZone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ); if( !internalZone ) return; @@ -881,7 +875,7 @@ void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player& } else { - auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); + auto zone = std::dynamic_pointer_cast< HousingZone >( pZone ); if( !zone ) return; @@ -903,26 +897,22 @@ void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player& invMgr.sendInventoryContainer( player, it->second ); } -const Sapphire::World::Manager::HousingMgr::LandSetLandCacheMap& - Sapphire::World::Manager::HousingMgr::getLandCacheMap() +const Sapphire::World::Manager::HousingMgr::LandSetLandCacheMap& Sapphire::World::Manager::HousingMgr::getLandCacheMap() { return m_landCache; } -Sapphire::World::Manager::HousingMgr::LandIdentToInventoryContainerMap& - Sapphire::World::Manager::HousingMgr::getEstateInventories() +Sapphire::World::Manager::HousingMgr::LandIdentToInventoryContainerMap& Sapphire::World::Manager::HousingMgr::getEstateInventories() { return m_estateInventories; } -Sapphire::World::Manager::HousingMgr::ContainerIdToContainerMap& - Sapphire::World::Manager::HousingMgr::getEstateInventory( uint64_t ident ) +Sapphire::World::Manager::HousingMgr::ContainerIdToContainerMap& Sapphire::World::Manager::HousingMgr::getEstateInventory( uint64_t ident ) { return m_estateInventories[ ident ]; } -Sapphire::World::Manager::HousingMgr::ContainerIdToContainerMap& - Sapphire::World::Manager::HousingMgr::getEstateInventory( Sapphire::Common::LandIdent ident ) +Sapphire::World::Manager::HousingMgr::ContainerIdToContainerMap& Sapphire::World::Manager::HousingMgr::getEstateInventory( Sapphire::Common::LandIdent ident ) { auto u64ident = *reinterpret_cast< uint64_t* >( &ident ); @@ -962,8 +952,7 @@ void Sapphire::World::Manager::HousingMgr::updateHouseModels( Sapphire::HousePtr { for( auto& item : intContainer->second->getItemMap() ) { - house->setInteriorModel( static_cast< Common::HouseInteriorSlot >( item.first ), - getItemAdditionalData( item.second->getId() ) ); + house->setInteriorModel( static_cast< Common::HouseInteriorSlot >( item.first ), getItemAdditionalData( item.second->getId() ) ); } } else @@ -997,6 +986,9 @@ void Sapphire::World::Manager::HousingMgr::reqPlaceHousingItem( Sapphire::Entity { auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + // retail process is: // - unlink item from current container // - add it to destination container @@ -1008,15 +1000,14 @@ void Sapphire::World::Manager::HousingMgr::reqPlaceHousingItem( Sapphire::Entity bool isOutside = false; // inside housing territory - if( auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ) ) + if( auto zone = std::dynamic_pointer_cast< HousingZone >( pZone ) ) { land = zone->getLand( static_cast< uint8_t >( landId ) ); isOutside = true; } // otherwise, inside a house. landId is 0 when inside a plot - else if( auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( - player.getCurrentTerritory() ) ) + else if( auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ) ) { // todo: this whole process is retarded and needs to be fixed // perhaps maintain a list of estates by ident inside housingmgr? @@ -1075,19 +1066,20 @@ void Sapphire::World::Manager::HousingMgr::reqPlaceHousingItem( Sapphire::Entity PlayerMgr::sendUrgent( player, "An internal error occurred when placing the item." ); } -void Sapphire::World::Manager::HousingMgr::reqPlaceItemInStore( Sapphire::Entity::Player& player, uint16_t landId, - uint16_t containerId, uint8_t slotId ) +void Sapphire::World::Manager::HousingMgr::reqPlaceItemInStore( Sapphire::Entity::Player& player, uint16_t landId, uint16_t containerId, uint8_t slotId ) { LandPtr land; bool isOutside = false; - if( auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ) ) + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + + if( auto zone = std::dynamic_pointer_cast< HousingZone >( pZone ) ) { land = zone->getLand( static_cast< uint8_t >( landId ) ); isOutside = true; } - else if( auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( - player.getCurrentTerritory() ) ) + else if( auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ) ) { // todo: this whole process is retarded and needs to be fixed // perhaps maintain a list of estates by ident inside housingmgr? @@ -1146,9 +1138,7 @@ void Sapphire::World::Manager::HousingMgr::reqPlaceItemInStore( Sapphire::Entity } } -bool Sapphire::World::Manager::HousingMgr::placeExternalItem( Entity::Player& player, - Inventory::HousingItemPtr item, - Common::LandIdent ident ) +bool Sapphire::World::Manager::HousingMgr::placeExternalItem( Entity::Player& player, Inventory::HousingItemPtr item, Common::LandIdent ident ) { auto& invMgr = Service< InventoryMgr >::ref(); @@ -1171,8 +1161,11 @@ bool Sapphire::World::Manager::HousingMgr::placeExternalItem( Entity::Player& pl invMgr.saveHousingContainer( ident, container ); invMgr.updateHousingItemPosition( item ); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + // add to zone and spawn - auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); + auto zone = std::dynamic_pointer_cast< HousingZone >( pZone ); assert( zone ); zone->spawnYardObject( static_cast< uint8_t >( ident.landId ), static_cast< uint16_t >( freeSlot ), *item ); @@ -1184,8 +1177,10 @@ bool Sapphire::World::Manager::HousingMgr::placeInteriorItem( Entity::Player& pl Inventory::HousingItemPtr item ) { auto& invMgr = Service< InventoryMgr >::ref(); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); - auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( player.getCurrentTerritory() ); + auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ); assert( zone ); auto ident = zone->getLandIdent(); @@ -1216,7 +1211,7 @@ bool Sapphire::World::Manager::HousingMgr::placeInteriorItem( Entity::Player& pl invMgr.saveHousingContainer( ident, container ); invMgr.updateHousingItemPosition( item ); - auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( player.getCurrentTerritory() ); + auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ); assert( zone ); zone->spawnHousingObject( containerIdx, static_cast< uint16_t >( freeSlot ), containerId, item ); @@ -1240,10 +1235,12 @@ Sapphire::Common::Furniture Sapphire::World::Manager::HousingMgr::getYardObjectF return obj; } -void Sapphire::World::Manager::HousingMgr::sendInternalEstateInventoryBatch( Sapphire::Entity::Player& player, - bool storeroom ) +void Sapphire::World::Manager::HousingMgr::sendInternalEstateInventoryBatch( Sapphire::Entity::Player& player, bool storeroom ) { - auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( player.getCurrentTerritory() ); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + + auto zone = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ); if( !zone ) return; @@ -1269,9 +1266,8 @@ void Sapphire::World::Manager::HousingMgr::sendInternalEstateInventoryBatch( Sap } } -void Sapphire::World::Manager::HousingMgr::reqMoveHousingItem( Entity::Player& player, - Common::LandIdent ident, uint8_t slot, - Common::FFXIVARR_POSITION3 pos, float rot ) +void Sapphire::World::Manager::HousingMgr::reqMoveHousingItem( Entity::Player& player, Common::LandIdent ident, + uint8_t slot, Common::FFXIVARR_POSITION3 pos, float rot ) { auto landSet = toLandSetId( static_cast< uint16_t >( ident.territoryTypeId ), static_cast< uint8_t >( ident.wardNum ) ); auto land = getHousingZoneByLandSetId( landSet )->getLand( static_cast< uint8_t >( ident.landId ) ); @@ -1282,14 +1278,16 @@ void Sapphire::World::Manager::HousingMgr::reqMoveHousingItem( Entity::Player& p if( !hasPermission( player, *land, 0 ) ) return; + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + // todo: what happens when either of these fail? how does the server let the client know that the moment failed // as is, if it does fail, the client will be locked and unable to move any item until reentering the territory - if( auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( - player.getCurrentTerritory() ) ) + if( auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ) ) { moveInternalItem( player, ident, *terri, slot, pos, rot ); } - else if( auto terri = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ) ) + else if( auto terri = std::dynamic_pointer_cast< HousingZone >( pZone ) ) { moveExternalItem( player, ident, slot, *terri, pos, rot ); } @@ -1387,8 +1385,10 @@ void Sapphire::World::Manager::HousingMgr::reqRemoveHousingItem( Sapphire::Entit uint16_t containerId, uint8_t slot, bool sendToStoreroom ) { - if( auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( - player.getCurrentTerritory() ) ) + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + + if( auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ) ) { auto ident = terri->getLandIdent(); auto landSet = toLandSetId( static_cast< uint16_t >( ident.territoryTypeId ), static_cast< uint8_t >( ident.wardNum ) ); @@ -1402,7 +1402,7 @@ void Sapphire::World::Manager::HousingMgr::reqRemoveHousingItem( Sapphire::Entit removeInternalItem( player, *terri, containerId, slot, sendToStoreroom ); } - else if( auto terri = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ) ) + else if( auto terri = std::dynamic_pointer_cast< HousingZone >( pZone ) ) { auto land = terri->getLand( static_cast< uint8_t >( plot ) ); if( !land ) @@ -1594,7 +1594,10 @@ void Sapphire::World::Manager::HousingMgr::reqEstateExteriorRemodel( Sapphire::E auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); - auto terri = std::dynamic_pointer_cast< HousingZone >( player.getCurrentTerritory() ); + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + + auto terri = std::dynamic_pointer_cast< HousingZone >( pZone ); if( !terri ) return; @@ -1621,10 +1624,13 @@ void Sapphire::World::Manager::HousingMgr::reqEstateExteriorRemodel( Sapphire::E void Sapphire::World::Manager::HousingMgr::reqEstateInteriorRemodel( Sapphire::Entity::Player& player ) { + auto teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + auto& server = Common::Service< World::WorldServer >::ref(); auto pSession = server.getSession( player.getCharacterId() ); - auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( player.getCurrentTerritory() ); + auto terri = std::dynamic_pointer_cast< Territory::Housing::HousingInteriorTerritory >( pZone ); if( !terri ) return; diff --git a/src/world/Manager/HousingMgr.h b/src/world/Manager/HousingMgr.h index be04ca03..324c8cb5 100644 --- a/src/world/Manager/HousingMgr.h +++ b/src/world/Manager/HousingMgr.h @@ -77,7 +77,7 @@ namespace Sapphire::World::Manager void sendLandSignOwned( Entity::Player& player, const Common::LandIdent ident ); void sendLandSignFree( Entity::Player& player, const Common::LandIdent ident ); - LandPurchaseResult purchaseLand( Entity::Player& player, uint8_t plot, uint8_t state ); + LandPurchaseResult purchaseLand( Entity::Player& player, HousingZone& zone, uint8_t plot, uint8_t state ); /*! * @brief Converts param1 of a client trigger into a Common::LandIndent @@ -86,9 +86,9 @@ namespace Sapphire::World::Manager void sendWardLandInfo( Entity::Player& player, uint8_t wardId, uint16_t territoryTypeId ); - bool relinquishLand( Entity::Player& player, uint8_t plot ); + bool relinquishLand( Entity::Player& player, HousingZone& zone, uint8_t plot ); - void buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetCatalogId ); + void buildPresetEstate( Entity::Player& player, HousingZone& zone, uint8_t plotNum, uint32_t presetCatalogId ); void requestEstateRename( Entity::Player& player, const Common::LandIdent ident ); diff --git a/src/world/Manager/TerritoryMgr.cpp b/src/world/Manager/TerritoryMgr.cpp index df61c2af..858b2b53 100644 --- a/src/world/Manager/TerritoryMgr.cpp +++ b/src/world/Manager/TerritoryMgr.cpp @@ -644,15 +644,7 @@ Sapphire::World::Manager::TerritoryMgr::InstanceIdList return idList; } -bool Sapphire::World::Manager::TerritoryMgr::movePlayer( uint32_t territoryTypeId, Sapphire::Entity::Player& player ) -{ - auto pZone = getZoneByTerritoryTypeId( territoryTypeId ); - if( !pZone ) - return false; - return movePlayer( pZone, player ); -} - -bool Sapphire::World::Manager::TerritoryMgr::movePlayer( TerritoryPtr pZone, Sapphire::Entity::Player& player ) +bool Sapphire::World::Manager::TerritoryMgr::movePlayer( const TerritoryPtr& pZone, Sapphire::Entity::Player& player ) { if( !pZone ) { @@ -660,6 +652,8 @@ bool Sapphire::World::Manager::TerritoryMgr::movePlayer( TerritoryPtr pZone, Sap return false; } + auto pPrevZone = getTerritoryByGuId( player.getTerritoryId() ); + player.setStateFlag( Common::PlayerStateFlag::BetweenAreas ); player.initSpawnIdQueue(); @@ -672,13 +666,9 @@ bool Sapphire::World::Manager::TerritoryMgr::movePlayer( TerritoryPtr pZone, Sap if( pHousing ) player.setTerritoryId( pHousing->getLandSetId() ); } - else if( isInstanceContentTerritory( pZone->getTerritoryTypeId() ) ) - { - player.setTerritoryId( pZone->getGuId() ); - } else { - player.setTerritoryId( 0 ); + player.setTerritoryId( pZone->getGuId() ); } bool playerLoaded = player.isLoadingComplete(); @@ -686,8 +676,8 @@ bool Sapphire::World::Manager::TerritoryMgr::movePlayer( TerritoryPtr pZone, Sap // mark character as zoning in progress player.setLoadingComplete( false ); - if( playerLoaded && player.getCurrentTerritory() ) - player.getCurrentTerritory()->removeActor( player.getAsPlayer() ); + if( playerLoaded && pPrevZone ) + pPrevZone->removeActor( player.getAsPlayer() ); player.setCurrentZone( pZone ); pZone->pushActor( player.getAsPlayer() ); diff --git a/src/world/Manager/TerritoryMgr.h b/src/world/Manager/TerritoryMgr.h index 94ae1e02..f9e70546 100644 --- a/src/world/Manager/TerritoryMgr.h +++ b/src/world/Manager/TerritoryMgr.h @@ -136,9 +136,7 @@ namespace Sapphire::World::Manager /*! returns a Zone by landSetId */ TerritoryPtr getZoneByLandSetId( uint32_t landSetId ) const; - bool movePlayer( uint32_t territoryTypeId, Entity::Player& pPlayer ); - - bool movePlayer( TerritoryPtr, Entity::Player& player ); + bool movePlayer( const TerritoryPtr&, Entity::Player& player ); /*! returns an instancePtr if the player is still bound to an isntance */ TerritoryPtr getLinkedInstance( uint32_t playerId ) const; diff --git a/src/world/Manager/WarpMgr.h b/src/world/Manager/WarpMgr.h new file mode 100644 index 00000000..043a2dcf --- /dev/null +++ b/src/world/Manager/WarpMgr.h @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include + +namespace Sapphire::World::Manager +{ + struct QueuedWarp + { + Common::WarpType m_warpType; + uint64_t m_characterId; + uint16_t m_targetZoneId; + Common::FFXIVARR_POSITION3 m_targetPosition; + float m_targetRotation; + uint64_t m_delayTime; + + QueuedWarp( uint64_t characterId, Common::WarpType warpType, uint16_t targetZoneId, + const Common::FFXIVARR_POSITION3& targetPosition, float targetRotation, uint64_t delayTime ) : + m_characterId( characterId ), + m_warpType( warpType ), + m_targetZoneId( targetZoneId ), + m_targetPosition( targetPosition ), + m_targetRotation( targetRotation ), + m_delayTime( delayTime ), + { + } + }; + + class WarpMgr + { + public: + WarpMgr() = default; + + // queue a new warp process to be executed when the delaytime (ms) expired + void queueWarp( uint64_t characterId, Common::WarpType warpType, uint16_t targetZoneId, + const Common::FFXIVARR_POSITION3& targetPosition, float targetRotation, uint64_t delayTime ); + + void update( uint64_t tickCount ); + + private: + uint64_t m_lastTick; + std::vector< std::shared_ptr< QueuedWarp > > m_warpQueue; + + }; + +} diff --git a/src/world/Network/Handlers/CommonListHandler.cpp b/src/world/Network/Handlers/CommonListHandler.cpp index 91d5da3d..466f3706 100644 --- a/src/world/Network/Handlers/CommonListHandler.cpp +++ b/src/world/Network/Handlers/CommonListHandler.cpp @@ -101,13 +101,8 @@ void Sapphire::Network::GameConnection::getCommonlistHandler( const Packets::FFX if( isConnected ) { - // todo: fix odd teri nullptr on login for friendlist etc - auto pTeri = pPlayer->getCurrentTerritory(); - if( pTeri ) - { - entry.TerritoryType = pPlayer->getCurrentTerritory()->getTerritoryTypeId(); - entry.TerritoryID = pPlayer->getCurrentTerritory()->getTerritoryTypeId(); - } + entry.TerritoryType = pPlayer->getTerritoryTypeId(); + entry.TerritoryID = pPlayer->getTerritoryId(); entry.CurrentClassID = static_cast< uint8_t >( pPlayer->getClass() ); entry.SelectClassID = static_cast< uint8_t >( pPlayer->getSearchSelectClass() ); diff --git a/src/world/Network/Handlers/GMCommandHandlers.cpp b/src/world/Network/Handlers/GMCommandHandlers.cpp index bafcbdad..55535b5e 100644 --- a/src/world/Network/Handlers/GMCommandHandlers.cpp +++ b/src/world/Network/Handlers/GMCommandHandlers.cpp @@ -79,13 +79,13 @@ enum GmCommand JumpNpc = 0x025F, }; -void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { if( player.getGmRank() <= 0 ) return; auto& server = Common::Service< World::WorldServer >::ref(); + auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); const auto packet = ZoneChannelPacket< FFXIVIpcGmCommand >( inPacket ); const auto commandId = packet.data().Id; @@ -96,12 +96,10 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR const auto target = packet.data().Target; Logger::info( "{0} used GM1 commandId: {1}, params: {2}, {3}, {4}, {5}, target: {6}", - player.getName(), commandId, - param1, param2, param3, param4, target ); + player.getName(), commandId, param1, param2, param3, param4, target ); Sapphire::Entity::GameObjectPtr targetActor; - if( player.getId() == target ) { targetActor = player.getAsPlayer(); @@ -118,8 +116,11 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR if( !targetActor ) return; + auto targetPlayer = targetActor->getAsPlayer(); + auto pTargetZone = teriMgr.getTerritoryByGuId( targetActor->getTerritoryId() ); + switch( commandId ) { case GmCommand::Lv: @@ -184,9 +185,9 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR } case GmCommand::Weather: { - targetPlayer->getCurrentTerritory()->setWeatherOverride( static_cast< Common::Weather >( param1 ) ); + pTargetZone->setWeatherOverride( static_cast< Common::Weather >( param1 ) ); PlayerMgr::sendServerNotice( player, "Weather in Territory \"{0}\" of {1} set in range.", - targetPlayer->getCurrentTerritory()->getName(), targetPlayer->getName()); + pTargetZone->getName(), targetPlayer->getName() ); break; } case GmCommand::Call: @@ -195,7 +196,7 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR targetPlayer->setZone( player.getZoneId() ); targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, player.getRot() ); - PlayerMgr::sendServerNotice( player, "Calling {0}", targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Calling {0}", targetPlayer->getName() ); break; } case GmCommand::Inspect: @@ -211,13 +212,13 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR "\nPlayTime: {8}", targetPlayer->getName(), targetPlayer->getCurrency( CurrencyType::Gil ), - targetPlayer->getCurrentTerritory()->getName(), + pTargetZone->getName(), targetPlayer->getZoneId(), - static_cast< uint8_t >( targetPlayer->getClass()), + static_cast< uint8_t >( targetPlayer->getClass() ), targetPlayer->getLevel(), targetPlayer->getExp(), targetPlayer->getSearchMessage(), - targetPlayer->getPlayTime()); + targetPlayer->getPlayTime() ); break; } case GmCommand::Speed: @@ -354,7 +355,7 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR case GmCommand::Gil: { targetPlayer->addCurrency( CurrencyType::Gil, param1 ); - PlayerMgr::sendServerNotice( player, "Added {0} Gil for {1}", param1, targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Added {0} Gil for {1}", param1, targetPlayer->getName() ); break; } case GmCommand::Collect: @@ -448,12 +449,12 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR for( uint8_t i = 0; i < 255; i++ ) targetActor->getAsPlayer()->registerAetheryte( i ); - PlayerMgr::sendServerNotice( player, "All Aetherytes for {0} were turned on.", targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "All Aetherytes for {0} were turned on.", targetPlayer->getName() ); } else { targetActor->getAsPlayer()->registerAetheryte( static_cast< uint8_t >( param2 ) ); - PlayerMgr::sendServerNotice( player, "Aetheryte {0} for {1} was turned on.", param2, targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Aetheryte {0} for {1} was turned on.", param2, targetPlayer->getName() ); } } @@ -540,7 +541,7 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR targetPlayer->performZoning( static_cast< uint16_t >( param1 ), targetPlayer->getPos(), 0 ); } - PlayerMgr::sendServerNotice( player, "{0} was warped to zone {1}", targetPlayer->getName(), param1, pZone->getName()); + PlayerMgr::sendServerNotice( player, "{0} was warped to zone {1}", targetPlayer->getName(), param1, pZone->getName() ); } break; } @@ -549,13 +550,12 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR // todo: this doesn't kill their session straight away, should do this properly but its good for when you get stuck for now targetPlayer->setMarkedForRemoval(); - PlayerMgr::sendServerNotice( player, "Kicked {0}", targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Kicked {0}", targetPlayer->getName() ); break; } case GmCommand::TeriInfo: { - auto pCurrentZone = player.getCurrentTerritory(); PlayerMgr::sendServerNotice( player, "ZoneId: {0}" "\nName: {1}" "\nInternalName: {2}" @@ -564,12 +564,12 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR "\nCurrentWeather: {5}" "\nNextWeather: {6}", player.getZoneId(), - pCurrentZone->getName(), - pCurrentZone->getInternalName(), - pCurrentZone->getGuId(), - pCurrentZone->getPopCount(), - static_cast< uint8_t >( pCurrentZone->getCurrentWeather()), - static_cast< uint8_t >( pCurrentZone->getNextWeather())); + pTargetZone->getName(), + pTargetZone->getInternalName(), + pTargetZone->getGuId(), + pTargetZone->getPopCount(), + static_cast< uint8_t >( pTargetZone->getCurrentWeather() ), + static_cast< uint8_t >( pTargetZone->getNextWeather() ) ); break; } case GmCommand::Jump: @@ -591,8 +591,7 @@ void Sapphire::Network::GameConnection::gmCommandHandler( const Packets::FFXIVAR } -void Sapphire::Network::GameConnection::gmCommandNameHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::gmCommandNameHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { if( player.getGmRank() <= 0 ) return; @@ -660,7 +659,7 @@ void Sapphire::Network::GameConnection::gmCommandNameHandler( const Packets::FFX { player.exitInstance(); } - if( targetPlayer->getCurrentTerritory()->getGuId() != player.getCurrentTerritory()->getGuId() ) + if( targetPlayer->getTerritoryId() != player.getTerritoryId() ) { // Checks if the target player is in an InstanceContent to avoid binding to a Territory or PublicContent if( targetPlayer->getCurrentInstance() ) @@ -669,12 +668,11 @@ void Sapphire::Network::GameConnection::gmCommandNameHandler( const Packets::FFX // Not sure if GMs actually get bound to an instance they jump to on retail. It's mostly here to avoid a crash for now pInstanceContent->bindPlayer( player.getId() ); } - player.setInstance( targetPlayer->getCurrentTerritory()->getGuId() ); + player.setInstance( targetPlayer->getTerritoryId() ); } - player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z, - targetActor->getRot() ); + player.changePosition( targetActor->getPos().x, targetActor->getPos().y, targetActor->getPos().z, targetActor->getRot() ); player.sendZoneInPackets( 0x00, 0x00, 0, 0, false ); - PlayerMgr::sendServerNotice( player, "Jumping to {0}", targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Jumping to {0}", targetPlayer->getName() ); break; } case GmCommand::Call: @@ -690,13 +688,13 @@ void Sapphire::Network::GameConnection::gmCommandNameHandler( const Packets::FFX { targetPlayer->exitInstance(); } - if( targetPlayer->getCurrentTerritory()->getGuId() != player.getCurrentTerritory()->getGuId() ) + if( targetPlayer->getTerritoryId() != player.getTerritoryId() ) { - targetPlayer->setInstance( player.getCurrentTerritory()->getGuId() ); + targetPlayer->setInstance( player.getTerritoryId() ); } targetPlayer->changePosition( player.getPos().x, player.getPos().y, player.getPos().z, player.getRot() ); targetPlayer->sendZoneInPackets( 0x00, 0x00, 0, 0, false ); - PlayerMgr::sendServerNotice( player, "Calling {0}", targetPlayer->getName()); + PlayerMgr::sendServerNotice( player, "Calling {0}", targetPlayer->getName() ); break; } default: diff --git a/src/world/Network/Handlers/PacketCommandHandler.cpp b/src/world/Network/Handlers/PacketCommandHandler.cpp index 028bdcb6..017aa1e4 100644 --- a/src/world/Network/Handlers/PacketCommandHandler.cpp +++ b/src/world/Network/Handlers/PacketCommandHandler.cpp @@ -23,6 +23,7 @@ #include "WorldServer.h" #include "Forwards.h" #include +#include using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; @@ -54,12 +55,13 @@ void examineHandler( Sapphire::Entity::Player& player, uint32_t targetId ) } } -void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { const auto packet = ZoneChannelPacket< FFXIVIpcClientTrigger >( inPacket ); auto& server = Service< World::WorldServer >::ref(); + auto& teriMgr = Service< World::Manager::TerritoryMgr >::ref(); + auto pZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); const auto commandId = packet.data().Id; const auto param1 = *reinterpret_cast< const uint64_t* >( &packet.data().Arg0 ); @@ -271,12 +273,12 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ }*/ case PacketCommand::DIRECTOR_INIT_RETURN: // Director init finish { - player.getCurrentTerritory()->onInitDirector( player ); + pZone->onInitDirector( player ); break; } case PacketCommand::SYNC_DIRECTOR: // Director init finish { - player.getCurrentTerritory()->onDirectorSync( player ); + pZone->onDirectorSync( player ); break; } /* case PacketCommand::EnterTerritoryEventFinished:// this may still be something else. I think i have seen it elsewhere @@ -286,7 +288,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ }*/ case PacketCommand::EVENT_HANDLER: { - player.getCurrentTerritory()->onEventHandlerOrder( player, param11, param12, param2, param3, param4 ); + pZone->onEventHandlerOrder( player, param11, param12, param2, param3, param4 ); break; } @@ -297,8 +299,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ } case PacketCommand::HOUSING_LOCK_LAND_BY_BUILD: { - auto zone = player.getCurrentTerritory(); - auto hZone = std::dynamic_pointer_cast< HousingZone >( zone ); + auto hZone = std::dynamic_pointer_cast< HousingZone >( pZone ); if (!hZone) return; @@ -338,9 +339,12 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ case PacketCommand::HOUSING_RELEASE: { auto& housingMgr = Service< HousingMgr >::ref(); + auto hZone = std::dynamic_pointer_cast< HousingZone >( pZone ); + if (!hZone) + return; auto plot = static_cast< uint8_t >( param12 & 0xFF ); - housingMgr.relinquishLand( player, plot ); + housingMgr.relinquishLand( player, *hZone, plot ); break; } diff --git a/src/world/Network/Handlers/PacketHandlers.cpp b/src/world/Network/Handlers/PacketHandlers.cpp index e879d85c..7f1881c0 100644 --- a/src/world/Network/Handlers/PacketHandlers.cpp +++ b/src/world/Network/Handlers/PacketHandlers.cpp @@ -301,8 +301,7 @@ void Sapphire::Network::GameConnection::moveHandler( const Packets::FFXIVARR_PAC } void -Sapphire::Network::GameConnection::configHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +Sapphire::Network::GameConnection::configHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { const auto packet = ZoneChannelPacket< Client::FFXIVIpcConfig >( inPacket ); @@ -310,8 +309,7 @@ Sapphire::Network::GameConnection::configHandler( const Packets::FFXIVARR_PACKET Service< World::Manager::PlayerMgr >::ref().onEquipDisplayFlagsChanged( player ); } -void Sapphire::Network::GameConnection::zoneJumpHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::zoneJumpHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { const auto packet = ZoneChannelPacket< Client::FFXIVIpcZoneJump >( inPacket ); auto& data = packet.data(); @@ -320,7 +318,9 @@ void Sapphire::Network::GameConnection::zoneJumpHandler( const Packets::FFXIVARR auto& teriMgr = Common::Service< TerritoryMgr >::ref(); auto& instanceObjectCache = Common::Service< InstanceObjectCache >::ref(); auto& server = Common::Service< World::WorldServer >::ref(); - auto tInfo = player.getCurrentTerritory()->getTerritoryTypeInfo(); + + auto pTeri = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + auto tInfo = pTeri->getTerritoryTypeInfo(); auto pExitRange = instanceObjectCache.getExitRange( player.getTerritoryTypeId(), exitBoxId ); @@ -382,8 +382,10 @@ void Sapphire::Network::GameConnection::newDiscoveryHandler( const Packets::FFXI Entity::Player& player ) { auto& server = Common::Service< World::WorldServer >::ref(); + auto& teriMgr = Common::Service< TerritoryMgr >::ref(); auto& instanceObjectCache = Common::Service< InstanceObjectCache >::ref(); - auto tInfo = player.getCurrentTerritory()->getTerritoryTypeInfo(); + auto pTeri = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + auto tInfo = pTeri->getTerritoryTypeInfo(); const auto packet = ZoneChannelPacket< Client::FFXIVIpcNewDiscovery >( inPacket ); const auto layoutId = packet.data().LayoutId; @@ -435,6 +437,9 @@ void Sapphire::Network::GameConnection::setLanguageHandler( const Packets::FFXIV questMgr.sendQuestsInfo( player ); } + auto& teriMgr = Common::Service< TerritoryMgr >::ref(); + auto pCurrentZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + auto& playerMgr = Common::Service< World::Manager::PlayerMgr >::ref(); /* // TODO: load and save this data instead of hardcoding @@ -445,7 +450,7 @@ void Sapphire::Network::GameConnection::setLanguageHandler( const Packets::FFXIV gcPacket->data().gcRank[ 2 ] = player.getGcRankArray()[ 2 ]; player.queuePacket( gcPacket );*/ - player.getCurrentTerritory()->onFinishLoading( player ); + pCurrentZone->onFinishLoading( player ); // player is done zoning player.setLoadingComplete( true ); @@ -461,7 +466,7 @@ void Sapphire::Network::GameConnection::setLanguageHandler( const Packets::FFXIV player.spawn( player.getAsPlayer() ); // notify the zone of a change in position to force an "inRangeActor" update - player.getCurrentTerritory()->updateActorPosition( player ); + pCurrentZone->updateActorPosition( player ); } void Sapphire::Network::GameConnection::pcSearchHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, @@ -504,14 +509,16 @@ void Sapphire::Network::GameConnection::pcSearchHandler( const Packets::FFXIVARR queueOutPacket( pcSearchResultPacket ); } -void Sapphire::Network::GameConnection::chatHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, - Entity::Player& player ) +void Sapphire::Network::GameConnection::chatHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) { auto& debugCommandMgr = Common::Service< DebugCommandMgr >::ref(); + auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); const auto packet = ZoneChannelPacket< Client::FFXIVIpcChatHandler >( inPacket ); auto& data = packet.data(); + auto pCurrentZone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + if( data.message[ 0 ] == '!' ) { // execute game console command @@ -531,7 +538,7 @@ void Sapphire::Network::GameConnection::chatHandler( const Packets::FFXIVARR_PAC if( player.isActingAsGm() ) chatPacket->data().type = static_cast< uint16_t >( ChatType::GMSay ); - player.getCurrentTerritory()->queuePacketForRange( player, 50.f, chatPacket ); + pCurrentZone->queuePacketForRange( player, 50.f, chatPacket ); break; } case ChatType::Yell: @@ -539,7 +546,7 @@ void Sapphire::Network::GameConnection::chatHandler( const Packets::FFXIVARR_PAC if( player.isActingAsGm() ) chatPacket->data().type = static_cast< uint16_t >( ChatType::GMYell ); - player.getCurrentTerritory()->queuePacketForRange( player, 6000.f, chatPacket ); + pCurrentZone->queuePacketForRange( player, 6000.f, chatPacket ); break; } case ChatType::Shout: @@ -547,12 +554,12 @@ void Sapphire::Network::GameConnection::chatHandler( const Packets::FFXIVARR_PAC if( player.isActingAsGm() ) chatPacket->data().type = static_cast< uint16_t >( ChatType::GMShout ); - player.getCurrentTerritory()->queuePacketForRange( player, 6000.f, chatPacket ); + pCurrentZone->queuePacketForRange( player, 6000.f, chatPacket ); break; } default: { - player.getCurrentTerritory()->queuePacketForRange( player, 50.f, chatPacket ); + pCurrentZone->queuePacketForRange( player, 50.f, chatPacket ); break; } } diff --git a/src/world/Network/PacketWrappers/WarpPacket.h b/src/world/Network/PacketWrappers/WarpPacket.h index 539d659d..c375dfe6 100644 --- a/src/world/Network/PacketWrappers/WarpPacket.h +++ b/src/world/Network/PacketWrappers/WarpPacket.h @@ -16,14 +16,14 @@ namespace Sapphire::Network::Packets::WorldPackets::Server class WarpPacket : public ZoneChannelPacket< FFXIVIpcWarp > { public: - WarpPacket( Entity::Player& player, Common::WARP_TYPE warpType, Common::FFXIVARR_POSITION3& targetPos, float rotation ) : + WarpPacket( Entity::Player& player, Common::WarpType warpType, Common::FFXIVARR_POSITION3& targetPos, float rotation ) : ZoneChannelPacket< FFXIVIpcWarp >( player.getId(), player.getId() ) { initialize( player, warpType, targetPos, rotation ); }; private: - void initialize( Entity::Player& player, Common::WARP_TYPE warpType, Common::FFXIVARR_POSITION3& targetPos, float rotation ) + void initialize( Entity::Player& player, Common::WarpType warpType, Common::FFXIVARR_POSITION3& targetPos, float rotation ) { m_data.Dir = Sapphire::Common::Util::floatToUInt16Rot( rotation ); m_data.Type = warpType; diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index d9ebdff8..679a0722 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -15,6 +15,7 @@ #include "Manager/EventMgr.h" #include "Manager/PlayerMgr.h" +#include "Manager/TerritoryMgr.h" #include "StatusEffect/StatusEffect.h" @@ -204,8 +205,9 @@ bool Sapphire::Scripting::ScriptMgr::onTalk( Entity::Player& player, uint64_t ac // all other types.... // check if the actor is an eobj and call its script if we have one - auto zone = player.getCurrentTerritory(); - if( auto eobj = zone->getEObj( actorId ) ) + auto& teriMgr = Common::Service< World::Manager::TerritoryMgr >::ref(); + auto zone = teriMgr.getTerritoryByGuId( player.getTerritoryId() ); + if( auto eobj = zone ? zone->getEObj( actorId ) : nullptr ) { auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventObjectScript >( eobj->getObjectId() ); if( script ) diff --git a/src/world/Territory/Territory.cpp b/src/world/Territory/Territory.cpp index caf84feb..a1290659 100644 --- a/src/world/Territory/Territory.cpp +++ b/src/world/Territory/Territory.cpp @@ -507,7 +507,7 @@ void Sapphire::Territory::updateSessions( uint64_t tickCount, bool changedWeathe } // this session is not linked to this area anymore, remove it from zone session list - if( ( !pPlayer->getCurrentTerritory() ) || ( pPlayer->getCurrentTerritory() != shared_from_this() ) ) + if( pPlayer->getTerritoryId() != m_guId ) { Logger::debug( "[{}] removeActor( pPlayer );", pPlayer->getId() ); removeActor( pPlayer ); @@ -530,7 +530,7 @@ void Sapphire::Territory::updateSessions( uint64_t tickCount, bool changedWeathe } // this session is not linked to this area anymore, remove it from zone session list - if( ( !pPlayer->getCurrentTerritory() ) || ( pPlayer->getCurrentTerritory() != shared_from_this() ) ) + if( pPlayer->getTerritoryId() != getGuId() ) return; } } @@ -612,7 +612,7 @@ void Sapphire::Territory::updateCellActivity( uint32_t x, uint32_t y, int32_t ra void Sapphire::Territory::updateActorPosition( Entity::GameObject& actor ) { - if( actor.getCurrentTerritory() != shared_from_this() ) + if( actor.getTerritoryTypeId() != getTerritoryTypeId() ) return; //actor.checkInRangeActors(); @@ -704,9 +704,7 @@ void Sapphire::Territory::updateInRangeSet( Entity::GameObjectPtr pActor, CellPt float distance = Util::distance( pCurAct->getPos(), pActor->getPos() ); - bool isInRange = ( fRange == 0.0f || distance <= fRange ) && - ( pCurAct->getCurrentTerritory() && pActor->getCurrentTerritory() ) && - ( pCurAct->getCurrentTerritory()->getGuId() == pActor->getCurrentTerritory()->getGuId() ); + bool isInRange = ( fRange == 0.0f || distance <= fRange ); bool isInRangeSet = pActor->isInRangeSet( pCurAct ); diff --git a/src/world/Territory/Territory.h b/src/world/Territory/Territory.h index 243e55d6..64b7e7f1 100644 --- a/src/world/Territory/Territory.h +++ b/src/world/Territory/Territory.h @@ -80,8 +80,7 @@ namespace Sapphire public: Territory(); - Territory( uint16_t territoryTypeId, uint32_t guId, const std::string& internalName, - const std::string& placeName ); + Territory( uint16_t territoryTypeId, uint32_t guId, const std::string& internalName, const std::string& placeName ); virtual ~Territory();