From d1a51538a06e6a87d65d68669e86b5b74886cad2 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sat, 1 Dec 2018 18:18:29 +1100 Subject: [PATCH] spawn internal house instances --- .../common/eobj/HousingEstateEntrance.cpp | 25 ++++++- src/servers/sapphire_zone/CMakeLists.txt | 3 +- src/servers/sapphire_zone/ForwardsZone.h | 5 ++ .../sapphire_zone/Manager/TerritoryMgr.cpp | 74 ++++++++++++++++++- .../sapphire_zone/Manager/TerritoryMgr.h | 6 +- .../Housing/HousingInteriorTerritory.cpp | 35 +++++++++ .../Housing/HousingInteriorTerritory.h | 10 ++- 7 files changed, 150 insertions(+), 8 deletions(-) diff --git a/src/servers/Scripts/common/eobj/HousingEstateEntrance.cpp b/src/servers/Scripts/common/eobj/HousingEstateEntrance.cpp index ce3fa0c7..6980d2f6 100644 --- a/src/servers/Scripts/common/eobj/HousingEstateEntrance.cpp +++ b/src/servers/Scripts/common/eobj/HousingEstateEntrance.cpp @@ -2,6 +2,9 @@ #include #include "Actor/EventObject.h" +#include "Territory/HousingZone.h" +#include "Manager/TerritoryMgr.h" +#include "Framework.h" using namespace Sapphire; @@ -18,13 +21,31 @@ public: { 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 ) return; // param2 == 1, zone into instance - } ); } }; \ No newline at end of file diff --git a/src/servers/sapphire_zone/CMakeLists.txt b/src/servers/sapphire_zone/CMakeLists.txt index 56a53413..8b8fe877 100644 --- a/src/servers/sapphire_zone/CMakeLists.txt +++ b/src/servers/sapphire_zone/CMakeLists.txt @@ -19,7 +19,8 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} Network/PacketWrappers/*.c* Script/*.c* StatusEffect/*.c* - Territory/*.c*) + Territory/*.c* + Territory/Housing/*.c*) add_executable( sapphire_zone ${SERVER_SOURCE_FILES} ) diff --git a/src/servers/sapphire_zone/ForwardsZone.h b/src/servers/sapphire_zone/ForwardsZone.h index 66f61e8a..5e2e1e9b 100644 --- a/src/servers/sapphire_zone/ForwardsZone.h +++ b/src/servers/sapphire_zone/ForwardsZone.h @@ -28,6 +28,11 @@ TYPE_FORWARD( Session ); TYPE_FORWARD( ZonePosition ); TYPE_FORWARD( Land ) +namespace World::Territory::Housing +{ +TYPE_FORWARD( HousingInteriorTerritory ); +} + namespace World::Manager { TYPE_FORWARD( HousingMgr ); diff --git a/src/servers/sapphire_zone/Manager/TerritoryMgr.cpp b/src/servers/sapphire_zone/Manager/TerritoryMgr.cpp index 46ca2fe3..4db1441c 100644 --- a/src/servers/sapphire_zone/Manager/TerritoryMgr.cpp +++ b/src/servers/sapphire_zone/Manager/TerritoryMgr.cpp @@ -7,12 +7,16 @@ #include "Actor/Player.h" #include "Territory/Zone.h" -#include "Territory/HousingZone.h" #include "Territory/ZonePosition.h" #include "Territory/InstanceContent.h" #include "TerritoryMgr.h" +#include "HousingMgr.h" #include "Framework.h" +#include "Territory/Land.h" +#include "Territory/House.h" +#include "Territory/Housing/HousingInteriorTerritory.h" + extern Sapphire::Framework g_fw; Sapphire::World::Manager::TerritoryMgr::TerritoryMgr() : @@ -278,9 +282,75 @@ Sapphire::ZonePtr Sapphire::World::Manager::TerritoryMgr::createInstanceContent( 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 ) diff --git a/src/servers/sapphire_zone/Manager/TerritoryMgr.h b/src/servers/sapphire_zone/Manager/TerritoryMgr.h index 554201a5..794c87af 100644 --- a/src/servers/sapphire_zone/Manager/TerritoryMgr.h +++ b/src/servers/sapphire_zone/Manager/TerritoryMgr.h @@ -98,7 +98,7 @@ namespace Sapphire::World::Manager 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 */ bool removeTerritoryInstance( uint32_t territoryTypeId ); @@ -156,6 +156,7 @@ namespace Sapphire::World::Manager using PlayerIdToInstanceIdMap = std::unordered_map< uint32_t, uint32_t >; using PositionMap = std::unordered_map< int32_t, ZonePositionPtr >; using InstanceIdList = std::vector< uint32_t >; + using LandIdentToZonePtrMap = std::unordered_map< uint64_t, ZonePtr >; /*! map holding details for territory templates */ TerritoryTypeDetailCache m_territoryTypeDetailCacheMap; @@ -178,6 +179,9 @@ namespace Sapphire::World::Manager /*! map storing playerIds to instanceIds, used for instanceContent */ PlayerIdToInstanceIdMap m_playerIdToInstanceMap; + /*! map for storing landident to zones, used for internal housing zones */ + LandIdentToZonePtrMap m_landIdentToZonePtrMap; + /*! internal counter for instanceIds */ uint32_t m_lastInstanceId; diff --git a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp index e69de29b..c89a1a1b 100644 --- a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp +++ b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.cpp @@ -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 ) +{ + +} \ No newline at end of file diff --git a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h index d52f102a..539ebba9 100644 --- a/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h +++ b/src/servers/sapphire_zone/Territory/Housing/HousingInteriorTerritory.h @@ -1,4 +1,5 @@ -#include "Zone.h" +#include "ForwardsZone.h" +#include "Territory/Zone.h" namespace Sapphire::World::Territory::Housing { @@ -10,9 +11,14 @@ namespace Sapphire::World::Territory::Housing const std::string& internalName, const std::string& contentName ); + virtual ~HousingInteriorTerritory(); + bool init() override; void onPlayerZoneIn( Entity::Player& player ) override; void onUpdate( uint32_t currTime ) override; - } + + private: + uint64_t m_landIdent; + }; } \ No newline at end of file