From e418e61b4aa5ab8eb74aeb66e8e8550fa2942447 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 30 Dec 2018 18:48:45 +1100 Subject: [PATCH] #448 - Place character correctly on entering a house --- .../common/eobj/HousingEstateEntrance.cpp | 41 ++++++++++++++++--- src/world/Actor/Player.cpp | 27 ++++++++++++ src/world/Actor/Player.h | 3 ++ src/world/Manager/TerritoryMgr.cpp | 8 ++-- src/world/Manager/TerritoryMgr.h | 2 +- 5 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/scripts/common/eobj/HousingEstateEntrance.cpp b/src/scripts/common/eobj/HousingEstateEntrance.cpp index a576bc19..7461ef1e 100644 --- a/src/scripts/common/eobj/HousingEstateEntrance.cpp +++ b/src/scripts/common/eobj/HousingEstateEntrance.cpp @@ -4,6 +4,7 @@ #include "Actor/EventObject.h" #include "Territory/HousingZone.h" #include "Manager/TerritoryMgr.h" +#include "Territory/Land.h" #include "Framework.h" using namespace Sapphire; @@ -19,8 +20,6 @@ public: void onTalk( uint32_t eventId, Entity::Player& player, Entity::EventObject& eobj ) override { - player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj.getHousingLink() >> 8 ) ); - player.playScene( eventId, 0, 0, [this, eobj]( Entity::Player& player, const Event::SceneResult& result ) { // param2 == 1 when player wants to enter house @@ -42,15 +41,45 @@ public: ident.worldId = 67; auto internalZone = terriMgr->findOrCreateHousingInterior( ident ); - if( internalZone ) + if( !internalZone ) { - player.sendDebug( "created zone with guid: " + std::to_string( internalZone->getGuId() ) + "\nname: " + internalZone->getName() ); + // an error occurred during event movement + // lol + player.sendLogMessage( 1311 ); + player.eventFinish( result.eventId, 1 ); + return; } player.eventFinish( result.eventId, 1 ); - player.setPos( { 0.f, 0.f, 0.f } ); - player.setInstance( internalZone ); + Common::FFXIVARR_POSITION3 pos {}; + + auto land = zone->getLand( eobj.getHousingLink() >> 8 ); + if( !land ) + return; + + switch( land->getSize() ) + { + case 0: + { + pos = { 0.1321167f, 0.f, 2.746273f }; + break; + } + case 1: + { + pos = { 1.337722f, 0.f, 3.995964f }; + break; + } + case 2: + { + pos = { 0.07214607f, 0.f, 8.217761f }; + break; + } + default: + return; + } + + player.setInstance( internalZone, pos ); } ); } }; \ No newline at end of file diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 33bcb871..5696a8a0 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -459,6 +459,33 @@ bool Sapphire::Entity::Player::setInstance( ZonePtr instance ) return true; } +bool Sapphire::Entity::Player::setInstance( ZonePtr instance, Common::FFXIVARR_POSITION3 pos ) +{ + if( !instance ) + return false; + + m_onEnterEventDone = false; + + auto pTeriMgr = m_pFw->get< TerritoryMgr >(); + auto currentZone = getCurrentZone(); + + m_prevPos = m_pos; + m_prevRot = m_rot; + m_prevTerritoryTypeId = currentZone->getTerritoryTypeId(); + m_prevTerritoryId = getTerritoryId(); + + if( pTeriMgr->movePlayer( instance, getAsPlayer() ) ) + { + m_pos = pos; + + sendZonePackets(); + + return true; + } + + return false; +} + bool Sapphire::Entity::Player::exitInstance() { auto pTeriMgr = m_pFw->get< TerritoryMgr >(); diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 2721bba2..218b27f9 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -482,6 +482,9 @@ namespace Sapphire::Entity /*! sets the players instance & initiates zoning process */ bool setInstance( ZonePtr instance ); + /*! sets the players instance & initiates zoning process */ + bool setInstance( Sapphire::ZonePtr instance, Sapphire::Common::FFXIVARR_POSITION3 pos ); + /*! returns the player to their position before zoning into an instance */ bool exitInstance(); diff --git a/src/world/Manager/TerritoryMgr.cpp b/src/world/Manager/TerritoryMgr.cpp index 575c60b7..9e260c61 100644 --- a/src/world/Manager/TerritoryMgr.cpp +++ b/src/world/Manager/TerritoryMgr.cpp @@ -287,7 +287,7 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createInstanceContent( pTeri->name, pInstanceContent->name, instanceContentId, framework() ); pZone->init(); - m_instanceContentToInstanceMap[ instanceContentId ][ pZone->getGuId() ] = pZone; + m_instanceContentIdToInstanceMap[ instanceContentId ][ pZone->getGuId() ] = pZone; m_instanceIdToZonePtrMap[ pZone->getGuId() ] = pZone; m_instanceZoneSet.insert( pZone ); @@ -381,7 +381,7 @@ bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t i if( isInstanceContentTerritory( pZone->getTerritoryTypeId() ) ) { auto instance = std::dynamic_pointer_cast< InstanceContent >( pZone ); - m_instanceContentToInstanceMap[ instance->getInstanceContentId() ].erase( pZone->getGuId() ); + m_instanceContentIdToInstanceMap[ instance->getInstanceContentId() ].erase( pZone->getGuId() ); } else m_territoryTypeIdToInstanceGuidMap[ pZone->getTerritoryTypeId() ].erase( pZone->getGuId() ); @@ -486,8 +486,8 @@ void Sapphire::World::Manager::TerritoryMgr::updateTerritoryInstances( uint32_t Sapphire::World::Manager::TerritoryMgr::InstanceIdList Sapphire::World::Manager::TerritoryMgr::getInstanceContentIdList( uint16_t instanceContentId ) const { std::vector< uint32_t > idList; - auto zoneMap = m_instanceContentToInstanceMap.find( instanceContentId ); - if( zoneMap == m_instanceContentToInstanceMap.end() ) + auto zoneMap = m_instanceContentIdToInstanceMap.find( instanceContentId ); + if( zoneMap == m_instanceContentIdToInstanceMap.end() ) return idList; for( auto& entry : zoneMap->second ) diff --git a/src/world/Manager/TerritoryMgr.h b/src/world/Manager/TerritoryMgr.h index b32c9fcb..1905b7f6 100644 --- a/src/world/Manager/TerritoryMgr.h +++ b/src/world/Manager/TerritoryMgr.h @@ -176,7 +176,7 @@ namespace Sapphire::World::Manager LandSetIdToZonePtrMap m_landSetIdToZonePtrMap; /*! map holding actual instances of InstanceContent */ - InstanceContentIdToInstanceMap m_instanceContentToInstanceMap; + InstanceContentIdToInstanceMap m_instanceContentIdToInstanceMap; /*! flat map for easier lookup of instances by guid */ InstanceIdToZonePtrMap m_instanceIdToZonePtrMap;