1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-28 23:27:45 +00:00

#448 - Place character correctly on entering a house

This commit is contained in:
NotAdam 2018-12-30 18:48:45 +11:00
parent 50276dcbc3
commit e418e61b4a
5 changed files with 70 additions and 11 deletions

View file

@ -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 );
} );
}
};

View file

@ -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 >();

View file

@ -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();

View file

@ -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 )

View file

@ -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;