diff --git a/src/servers/Scripts/common/CmnDefHousingSignboard.cpp b/src/servers/Scripts/common/CmnDefHousingSignboard.cpp index fd4fb907..4fa2d53f 100644 --- a/src/servers/Scripts/common/CmnDefHousingSignboard.cpp +++ b/src/servers/Scripts/common/CmnDefHousingSignboard.cpp @@ -35,10 +35,10 @@ public: auto pTerritory = player.getCurrentZone(); auto pHousing = std::dynamic_pointer_cast< HousingZone >( pTerritory ); - auto pHouMgr = pFw->get< Core::HousingMgr >(); + auto pHouMgr = pFw->get< Core::HousingMgr >(); LandPurchaseResult res = pHouMgr->purchseLand( player, activeLand.plot, - static_cast< uint8_t >( result.param2 ) ); + static_cast< uint8_t >( result.param2 ) ); switch( res ) { @@ -73,7 +73,6 @@ public: break; } - case LandPurchaseResult::ERR_INTERNAL: { auto errorMsg = makeActorControl143( player.getId(), ActorControl::LogMsg, 1995 ); diff --git a/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp b/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp index 96bacd66..aed5e18b 100644 --- a/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/ClientTriggerHandler.cpp @@ -328,25 +328,28 @@ void Core::Network::GameConnection::clientTriggerHandler( const Packets::FFXIVAR { auto ward = static_cast< uint8_t >( ( param12 & 0xFF00 ) >> 8 ); auto plot = static_cast< uint8_t >( param12 & 0xFF ); + auto territoryId = static_cast< uint16_t >( param11 & 0xFFFF ); + auto pHousingMgr = g_fw.get< HousingMgr >(); - pHousingMgr->sendLandSignFree( player, ward, plot ); + pHousingMgr->sendLandSignFree( player, ward, plot, territoryId ); break; } case ClientTriggerType::RequestLandSignOwned: { auto ward = static_cast< uint8_t >( ( param12 & 0xFF00 ) >> 8 ); auto plot = static_cast< uint8_t >( param12 & 0xFF ); + auto territoryId = static_cast< uint16_t >( param11 & 0xFFFF ); + auto pHousingMgr = g_fw.get< HousingMgr >(); - pHousingMgr->sendLandSignOwned( player, ward, plot ); + pHousingMgr->sendLandSignOwned( player, ward, plot, territoryId ); break; } case ClientTriggerType::RequestLandRelinquish: { - auto ward = static_cast< uint8_t >( ( param12 & 0xFF00 ) >> 8 ); auto plot = static_cast< uint8_t >( param12 & 0xFF ); auto pHousingMgr = g_fw.get< HousingMgr >(); - pLog->debug( "Request to relinquish plot " + std::to_string( plot ) ); - // TODO: do stuff! + pHousingMgr->relinquishLand( player, plot ); + break; } case ClientTriggerType::RequestEstateRename: diff --git a/src/servers/sapphire_zone/Zone/HousingMgr.cpp b/src/servers/sapphire_zone/Zone/HousingMgr.cpp index fd2222da..d4521106 100644 --- a/src/servers/sapphire_zone/Zone/HousingMgr.cpp +++ b/src/servers/sapphire_zone/Zone/HousingMgr.cpp @@ -48,6 +48,11 @@ uint16_t Core::HousingMgr::getNexLandId() return ++m_lastLandId; } +uint32_t Core::HousingMgr::toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const +{ + return ( static_cast< uint32_t >( territoryTypeId ) << 16 ) | wardId; +} + void Core::HousingMgr::insertHousingZone( Core::Data::HousingZonePtr hZone ) { uint16_t id = getNexLandId(); @@ -95,18 +100,17 @@ Core::LandPtr Core::HousingMgr::getLandByOwnerId( uint32_t id ) return nullptr; } -void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t ward, uint8_t plot ) +void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId ) { - player.setActiveLand( plot, ward ); + player.setActiveLand( plotId, wardId ); - auto zone = player.getCurrentZone(); - - auto hZone = std::dynamic_pointer_cast< HousingZone >( zone ); + auto landSetId = toLandSetId( territoryTypeId, wardId ); + auto hZone = getHousingZoneByLandSetId( landSetId ); if( !hZone ) return; - auto land = hZone->getLand( plot ); + auto land = hZone->getLand( plotId ); if( !land ) { land = getLandByOwnerId( player.getId() ); @@ -128,17 +132,17 @@ void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t ward, player.queuePacket( landInfoSignPacket ); } -void Core::HousingMgr::sendLandSignFree( Entity::Player& player, uint8_t ward, uint8_t plot ) +void Core::HousingMgr::sendLandSignFree( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId ) { - player.setActiveLand( plot, ward ); + player.setActiveLand( plotId, wardId ); - auto zone = player.getCurrentZone(); - auto hZone = std::dynamic_pointer_cast< HousingZone >( zone ); + auto landSetId = toLandSetId( territoryTypeId, wardId ); + auto hZone = getHousingZoneByLandSetId( landSetId ); if( !hZone ) return; - auto land = hZone->getLand( plot ); + auto land = hZone->getLand( plotId ); auto plotPricePacket = makeZonePacket< Server::FFXIVIpcLandPriceUpdate >( player.getId() ); plotPricePacket->data().price = land->getCurrentPrice(); plotPricePacket->data().timeLeft = land->getDevaluationTime(); @@ -201,3 +205,30 @@ Core::LandPurchaseResult Core::HousingMgr::purchseLand( Entity::Player& player, } +bool Core::HousingMgr::relinquishLand( Entity::Player& player, uint8_t plot ) +{ + // TODO: Fix "permissions" being sent incorrectly + // TODO: Add checks for land state before relinquishing + auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() ); + + auto pLand = pHousing->getLand( plot ); + auto plotMaxPrice = pLand->getCurrentPrice(); + + pLand->setCurrentPrice( pLand->getMaxPrice() ); + pLand->setPlayerOwner( 0 ); + pLand->setState( HouseState::forSale ); + pLand->setLandType( Common::LandType::none ); + pLand->updateLandDb(); + + player.setLandPermissions( LandPermissionSlot::Private, 0x00, 0xFF, 0xFF, 0xFF ); + + player.sendLandPermissionSlot( static_cast< uint8_t >( LandType::Private ), 0xFF, 0xFF, 0xFF ); + + auto screenMsgPkt2 = makeActorControl143( player.getId(), ActorControl::LogMsg, 3351, 0x1AA, + pLand->getWardNum() + 1, plot + 1 ); + player.queuePacket( screenMsgPkt2 ); + pHousing->sendLandUpdate( plot ); + + return true; +} + diff --git a/src/servers/sapphire_zone/Zone/HousingMgr.h b/src/servers/sapphire_zone/Zone/HousingMgr.h index 03b12bac..156fd18c 100644 --- a/src/servers/sapphire_zone/Zone/HousingMgr.h +++ b/src/servers/sapphire_zone/Zone/HousingMgr.h @@ -22,16 +22,19 @@ namespace Core bool init(); + uint32_t toLandSetId( uint16_t territoryTypeId, uint8_t wardId ) const; uint16_t getNexLandId(); void insertHousingZone( Core::Data::HousingZonePtr hZone ); Core::Data::HousingZonePtr getHousingZone( uint16_t id ); Core::Data::HousingZonePtr getHousingZoneByLandSetId( uint32_t id ); Core::LandPtr getLandByOwnerId( uint32_t id ); - void sendLandSignOwned( Entity::Player& player, uint8_t ward, uint8_t plot ); - void sendLandSignFree( Entity::Player& player, uint8_t ward, uint8_t plot ); + void sendLandSignOwned( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId ); + void sendLandSignFree( Entity::Player& player, uint8_t wardId, uint8_t plotId, uint16_t territoryTypeId ); LandPurchaseResult purchseLand( Entity::Player& player, uint8_t plot, uint8_t state ); + bool relinquishLand( Entity::Player& player, uint8_t plot ); + private: using HousingZonePtrMap = std::unordered_map< uint16_t, Core::Data::HousingZonePtr >; uint16_t m_lastLandId; diff --git a/src/servers/sapphire_zone/Zone/Land.cpp b/src/servers/sapphire_zone/Zone/Land.cpp index 1b263e8f..62e8242f 100644 --- a/src/servers/sapphire_zone/Zone/Land.cpp +++ b/src/servers/sapphire_zone/Zone/Land.cpp @@ -74,6 +74,7 @@ void Core::Land::load() m_currentPrice = res->getUInt( "LandPrice" ); m_ownerPlayerId = res->getUInt( "OwnerId" ); m_minPrice = m_landInfo->minPrices[ m_landId ]; + m_maxPrice = m_landInfo->prices[ m_landId ]; } init(); } @@ -90,6 +91,11 @@ uint32_t Core::Land::getCurrentPrice() const return m_currentPrice; } +uint32_t Core::Land::getMaxPrice() const +{ + return m_maxPrice; +} + //Primary State void Core::Land::setSize( uint8_t size ) { @@ -195,6 +201,11 @@ uint32_t Core::Land::getDevaluationTime() return m_nextDrop - static_cast< uint32_t >( Util::getTimeSeconds() ); } +void Core::Land::setCurrentPrice( uint32_t currentPrice ) +{ + m_currentPrice = currentPrice; +} + void Core::Land::setLandTag( uint8_t slot, uint8_t tag ) { m_tag[ slot ] = tag; diff --git a/src/servers/sapphire_zone/Zone/Land.h b/src/servers/sapphire_zone/Zone/Land.h index 5522255b..95f4b6ce 100644 --- a/src/servers/sapphire_zone/Zone/Land.h +++ b/src/servers/sapphire_zone/Zone/Land.h @@ -46,12 +46,14 @@ namespace Core void setPlayerOwner( uint32_t id ); uint32_t getPlayerOwner(); //Housing Functions + void setCurrentPrice( uint32_t currentPrice ); void setPreset( uint32_t itemId ); void updateLandDb(); void update( uint32_t currTime ); uint32_t getMaxItems(); uint32_t getCurrentPrice() const; + uint32_t getMaxPrice() const; uint32_t getDevaluationTime(); //House tags @@ -86,6 +88,7 @@ namespace Core uint32_t m_nextDrop; uint32_t m_currentPrice; uint32_t m_minPrice; + uint32_t m_maxPrice; //information char fcTag[7];