1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

Merge pull request #445 from NotAdam/housing

spawn internal house instances
This commit is contained in:
Mordred 2018-12-01 14:29:27 +01:00 committed by GitHub
commit 1a18f1a9ce
7 changed files with 150 additions and 8 deletions

View file

@ -2,6 +2,9 @@
#include <Actor/Player.h> #include <Actor/Player.h>
#include "Actor/EventObject.h" #include "Actor/EventObject.h"
#include "Territory/HousingZone.h"
#include "Manager/TerritoryMgr.h"
#include "Framework.h"
using namespace Sapphire; using namespace Sapphire;
@ -18,13 +21,31 @@ public:
{ {
player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj.getHousingLink() >> 8 ) ); player.sendDebug( "Found plot entrance for plot: " + std::to_string( eobj.getHousingLink() >> 8 ) );
player.playScene( eventId, 0, 0, []( Entity::Player& player, const Event::SceneResult& result ) player.playScene( eventId, 0, 0, [this, eobj]( Entity::Player& player, const Event::SceneResult& result )
{ {
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() );
}
if( result.param2 != 1 ) if( result.param2 != 1 )
return; return;
// param2 == 1, zone into instance // param2 == 1, zone into instance
} ); } );
} }
}; };

View file

@ -19,7 +19,8 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Network/PacketWrappers/*.c* Network/PacketWrappers/*.c*
Script/*.c* Script/*.c*
StatusEffect/*.c* StatusEffect/*.c*
Territory/*.c*) Territory/*.c*
Territory/Housing/*.c*)
add_executable( sapphire_zone ${SERVER_SOURCE_FILES} ) add_executable( sapphire_zone ${SERVER_SOURCE_FILES} )

View file

@ -28,6 +28,11 @@ TYPE_FORWARD( Session );
TYPE_FORWARD( ZonePosition ); TYPE_FORWARD( ZonePosition );
TYPE_FORWARD( Land ) TYPE_FORWARD( Land )
namespace World::Territory::Housing
{
TYPE_FORWARD( HousingInteriorTerritory );
}
namespace World::Manager namespace World::Manager
{ {
TYPE_FORWARD( HousingMgr ); TYPE_FORWARD( HousingMgr );

View file

@ -7,12 +7,16 @@
#include "Actor/Player.h" #include "Actor/Player.h"
#include "Territory/Zone.h" #include "Territory/Zone.h"
#include "Territory/HousingZone.h"
#include "Territory/ZonePosition.h" #include "Territory/ZonePosition.h"
#include "Territory/InstanceContent.h" #include "Territory/InstanceContent.h"
#include "TerritoryMgr.h" #include "TerritoryMgr.h"
#include "HousingMgr.h"
#include "Framework.h" #include "Framework.h"
#include "Territory/Land.h"
#include "Territory/House.h"
#include "Territory/Housing/HousingInteriorTerritory.h"
extern Sapphire::Framework g_fw; extern Sapphire::Framework g_fw;
Sapphire::World::Manager::TerritoryMgr::TerritoryMgr() : Sapphire::World::Manager::TerritoryMgr::TerritoryMgr() :
@ -278,9 +282,75 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createInstanceContent(
return pZone; return pZone;
} }
Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createHousingInterior( const Common::LandIdent& landIdent ) Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::findOrCreateHousingInterior( const Common::LandIdent landIdent )
{ {
// check if zone already spawned first
auto ident = *reinterpret_cast< const uint64_t* >( &landIdent );
auto it = m_landIdentToZonePtrMap.find( ident );
if( it != m_landIdentToZonePtrMap.end() )
{
return it->second;
}
// otherwise, create it
auto housingMgr = g_fw.get< Manager::HousingMgr >();
auto parentZone = std::dynamic_pointer_cast< HousingZone >(
getZoneByLandSetId( housingMgr->toLandSetId( landIdent.territoryTypeId, landIdent.wardNum ) ) );
if( !parentZone )
return nullptr;
auto land = parentZone->getLand( landIdent.landId );
if( !land )
return nullptr;
auto house = land->getHouse();
if( !house )
return nullptr;
// get house instance id
uint16_t territoryTypeId = 0;
switch( landIdent.territoryTypeId )
{
case 339: // mist
territoryTypeId = 282;
break;
case 340: // lavender beds
territoryTypeId = 342;
break;
case 341: // goblet
territoryTypeId = 345;
break;
case 641: // shirogane
territoryTypeId = 649;
break;
default:
return nullptr;
}
// zones are sequential in the exd for small, med, large
territoryTypeId += land->getSize();
auto terriInfo = getTerritoryDetail( territoryTypeId );
if( !terriInfo )
return nullptr;
auto zone = World::Territory::Housing::make_HousingInteriorTerritory( ident, territoryTypeId, getNextInstanceId(),
terriInfo->name, house->getHouseName() );
zone->init();
m_landIdentToZonePtrMap[ ident ] = zone;
m_instanceIdToZonePtrMap[ zone->getGuId() ] = zone;
m_zoneSet.insert( { zone } );
return zone;
} }
bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t instanceId ) bool Sapphire::World::Manager::TerritoryMgr::removeTerritoryInstance( uint32_t instanceId )

View file

@ -98,7 +98,7 @@ namespace Sapphire::World::Manager
ZonePtr createInstanceContent( uint32_t contentFinderConditionId ); ZonePtr createInstanceContent( uint32_t contentFinderConditionId );
ZonePtr createHousingInterior( const Common::LandIdent& landIdent ); ZonePtr findOrCreateHousingInterior( const Common::LandIdent landIdent );
/*! removes instance by instanceId, return true if successful */ /*! removes instance by instanceId, return true if successful */
bool removeTerritoryInstance( uint32_t territoryTypeId ); bool removeTerritoryInstance( uint32_t territoryTypeId );
@ -156,6 +156,7 @@ namespace Sapphire::World::Manager
using PlayerIdToInstanceIdMap = std::unordered_map< uint32_t, uint32_t >; using PlayerIdToInstanceIdMap = std::unordered_map< uint32_t, uint32_t >;
using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >; using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >;
using InstanceIdList = std::vector< uint32_t >; using InstanceIdList = std::vector< uint32_t >;
using LandIdentToZonePtrMap = std::unordered_map< uint64_t, ZonePtr >;
/*! map holding details for territory templates */ /*! map holding details for territory templates */
TerritoryTypeDetailCache m_territoryTypeDetailCacheMap; TerritoryTypeDetailCache m_territoryTypeDetailCacheMap;
@ -178,6 +179,9 @@ namespace Sapphire::World::Manager
/*! map storing playerIds to instanceIds, used for instanceContent */ /*! map storing playerIds to instanceIds, used for instanceContent */
PlayerIdToInstanceIdMap m_playerIdToInstanceMap; PlayerIdToInstanceIdMap m_playerIdToInstanceMap;
/*! map for storing landident to zones, used for internal housing zones */
LandIdentToZonePtrMap m_landIdentToZonePtrMap;
/*! internal counter for instanceIds */ /*! internal counter for instanceIds */
uint32_t m_lastInstanceId; uint32_t m_lastInstanceId;

View file

@ -0,0 +1,35 @@
#include "HousingInteriorTerritory.h"
#include "Common.h"
using namespace Sapphire;
using namespace Sapphire::World::Territory;
Housing::HousingInteriorTerritory::HousingInteriorTerritory( uint64_t ident, uint16_t territoryTypeId,
uint32_t guId,
const std::string& internalName,
const std::string& contentName ) :
Zone( territoryTypeId, guId, internalName, contentName ),
m_landIdent( ident )
{
}
Housing::HousingInteriorTerritory::~HousingInteriorTerritory()
{
}
bool Housing::HousingInteriorTerritory::init()
{
}
void Housing::HousingInteriorTerritory::onPlayerZoneIn( Entity::Player& player )
{
}
void Housing::HousingInteriorTerritory::onUpdate( uint32_t currTime )
{
}

View file

@ -1,4 +1,5 @@
#include "Zone.h" #include "ForwardsZone.h"
#include "Territory/Zone.h"
namespace Sapphire::World::Territory::Housing namespace Sapphire::World::Territory::Housing
{ {
@ -10,9 +11,14 @@ namespace Sapphire::World::Territory::Housing
const std::string& internalName, const std::string& internalName,
const std::string& contentName ); const std::string& contentName );
virtual ~HousingInteriorTerritory();
bool init() override; bool init() override;
void onPlayerZoneIn( Entity::Player& player ) override; void onPlayerZoneIn( Entity::Player& player ) override;
void onUpdate( uint32_t currTime ) override; void onUpdate( uint32_t currTime ) override;
}
private:
uint64_t m_landIdent;
};
} }