2018-11-30 22:52:08 +11:00
|
|
|
#include <ScriptObject.h>
|
|
|
|
#include <Actor/Player.h>
|
|
|
|
|
|
|
|
#include "Actor/EventObject.h"
|
2018-12-01 18:18:29 +11:00
|
|
|
#include "Territory/HousingZone.h"
|
|
|
|
#include "Manager/TerritoryMgr.h"
|
|
|
|
#include "Framework.h"
|
2018-11-30 22:52:08 +11:00
|
|
|
|
|
|
|
using namespace Sapphire;
|
|
|
|
|
2018-12-01 00:27:16 +11:00
|
|
|
class HousingEstateEntrance :
|
2018-11-30 23:15:58 +11:00
|
|
|
public Sapphire::ScriptAPI::EventObjectScript
|
2018-11-30 22:52:08 +11:00
|
|
|
{
|
|
|
|
public:
|
2018-12-01 00:27:16 +11:00
|
|
|
HousingEstateEntrance() :
|
2018-11-30 23:15:58 +11:00
|
|
|
Sapphire::ScriptAPI::EventObjectScript( 2002737 )
|
2018-11-30 22:52:08 +11:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:15:58 +11:00
|
|
|
void onTalk( uint32_t eventId, Entity::Player& player, Entity::EventObject& eobj ) override
|
2018-11-30 22:52:08 +11:00
|
|
|
{
|
2018-11-30 23:15:58 +11:00
|
|
|
player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj.getHousingLink() >> 8 ) );
|
2018-11-30 22:52:08 +11:00
|
|
|
|
2018-12-01 18:18:29 +11:00
|
|
|
player.playScene( eventId, 0, 0, [this, eobj]( Entity::Player& player, const Event::SceneResult& result )
|
2018-11-30 22:52:08 +11:00
|
|
|
{
|
2018-12-01 18:18:29 +11:00
|
|
|
auto terriMgr = getFramework()->get< Sapphire::World::Manager::TerritoryMgr >();
|
|
|
|
if( !terriMgr )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto zone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() );
|
|
|
|
if( !zone )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Common::LandIdent ident;
|
|
|
|
ident.landId = eobj.getHousingLink() >> 8;
|
|
|
|
ident.territoryTypeId = zone->getTerritoryTypeId();
|
|
|
|
ident.wardNum = zone->getWardNum();
|
|
|
|
|
|
|
|
auto internalZone = terriMgr->findOrCreateHousingInterior( ident );
|
|
|
|
if( internalZone )
|
|
|
|
{
|
|
|
|
player.sendDebug( "created zone with guid: " + std::to_string( internalZone->getGuId() ) + "\nname: " + internalZone->getName() );
|
|
|
|
}
|
|
|
|
|
2018-12-02 14:59:24 +11:00
|
|
|
// param2 == 1 when player wants to enter house
|
2018-11-30 22:52:08 +11:00
|
|
|
if( result.param2 != 1 )
|
|
|
|
return;
|
|
|
|
|
2018-12-02 14:59:24 +11:00
|
|
|
player.eventFinish( result.eventId, 1 );
|
|
|
|
|
|
|
|
player.setPos( { 0.f, 0.f, 0.f } );
|
|
|
|
player.setInstance( internalZone );
|
2018-11-30 22:52:08 +11:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|