diff --git a/src/servers/Scripts/common/CmnDefHousingSignboard.cpp b/src/servers/Scripts/common/CmnDefHousingSignboard.cpp index b107ec66..fd4fb907 100644 --- a/src/servers/Scripts/common/CmnDefHousingSignboard.cpp +++ b/src/servers/Scripts/common/CmnDefHousingSignboard.cpp @@ -2,8 +2,10 @@ #include #include #include +#include #include #include +#include "Framework.h" using namespace Core; @@ -22,6 +24,9 @@ public: { auto callback = [ this ]( Entity::Player& player, const Event::SceneResult& result ) { + auto pFw = getFramework(); + if( !pFw ) + return LandPurchaseResult::ERR_INTERNAL; // Purchase Land if( result.param2 == 2 ) { @@ -30,8 +35,9 @@ public: auto pTerritory = player.getCurrentZone(); auto pHousing = std::dynamic_pointer_cast< HousingZone >( pTerritory ); + auto pHouMgr = pFw->get< Core::HousingMgr >(); - LandPurchaseResult res = pHousing->purchseLand( player, activeLand.plot, + LandPurchaseResult res = pHouMgr->purchseLand( player, activeLand.plot, static_cast< uint8_t >( result.param2 ) ); switch( res ) @@ -87,4 +93,4 @@ public: { Scene00000( player ); } -}; \ No newline at end of file +}; diff --git a/src/servers/sapphire_zone/Zone/HousingMgr.cpp b/src/servers/sapphire_zone/Zone/HousingMgr.cpp index fe6b2c22..8c1af62a 100644 --- a/src/servers/sapphire_zone/Zone/HousingMgr.cpp +++ b/src/servers/sapphire_zone/Zone/HousingMgr.cpp @@ -1,5 +1,4 @@ #include "HousingMgr.h" -#include "HousingMgr.h" #include #include #include @@ -145,3 +144,54 @@ void Core::HousingMgr::sendLandSignFree( Entity::Player& player, uint8_t ward, u plotPricePacket->data().timeLeft = land->getDevaluationTime(); player.queuePacket( plotPricePacket ); } + +Core::LandPurchaseResult Core::HousingMgr::purchseLand( Entity::Player& player, uint8_t plot, uint8_t state ) +{ + auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() ); + + auto plotPrice = pHousing->getLand( plot )->getCurrentPrice(); + auto gilAvailable = player.getCurrency( CurrencyType::Gil ); + auto pLand = pHousing->getLand( plot ); + + if( !pLand ) + return LandPurchaseResult::ERR_INTERNAL; + + if( pLand->getState() != HouseState::forSale ) + return LandPurchaseResult::ERR_NOT_AVAILABLE; + + if( gilAvailable < plotPrice ) + return LandPurchaseResult::ERR_NOT_ENOUGH_GIL; + + + switch( static_cast< LandPurchaseMode >( state ) ) + { + case LandPurchaseMode::FC: + player.sendDebug( "Free company house purchase aren't supported at this time." ); + return LandPurchaseResult::ERR_INTERNAL; + + case LandPurchaseMode::PRIVATE: + { + + auto pOldLand = getLandByOwnerId( player.getId() ); + + if( pOldLand ) + return LandPurchaseResult::ERR_NO_MORE_LANDS_FOR_CHAR; + player.removeCurrency( CurrencyType::Gil, plotPrice ); + pLand->setPlayerOwner( player.getId() ); + pLand->setState( HouseState::sold ); + pLand->setLandType( Common::LandType::Private ); + player.setLandPermissions( LandPermissionSlot::Private, 0x00, plot, + pHousing->getWardNum(), pHousing->getTerritoryTypeId() ); + player.sendLandPermissions(); + //pLand->setLandName( "Private Estate" + std::to_string( pHousing->getWardNum() ) + "-" + std::to_string( plot ) ); + pLand->updateLandDb(); + pHousing->sendLandUpdate( plot ); + return LandPurchaseResult::SUCCESS; + } + + default: + return LandPurchaseResult::ERR_INTERNAL; + } + +} + diff --git a/src/servers/sapphire_zone/Zone/HousingMgr.h b/src/servers/sapphire_zone/Zone/HousingMgr.h index 6089cf27..03b12bac 100644 --- a/src/servers/sapphire_zone/Zone/HousingMgr.h +++ b/src/servers/sapphire_zone/Zone/HousingMgr.h @@ -30,6 +30,7 @@ namespace Core void sendLandSignOwned( Entity::Player& player, uint8_t ward, uint8_t plot ); void sendLandSignFree( Entity::Player& player, uint8_t ward, uint8_t plot ); + LandPurchaseResult purchseLand( Entity::Player& player, uint8_t plot, uint8_t state ); private: using HousingZonePtrMap = std::unordered_map< uint16_t, Core::Data::HousingZonePtr >; diff --git a/src/servers/sapphire_zone/Zone/HousingZone.cpp b/src/servers/sapphire_zone/Zone/HousingZone.cpp index d02ce81f..bff2aa7f 100644 --- a/src/servers/sapphire_zone/Zone/HousingZone.cpp +++ b/src/servers/sapphire_zone/Zone/HousingZone.cpp @@ -129,13 +129,14 @@ void Core::HousingZone::sendLandSet( Entity::Player& player ) for( uint8_t i = startIndex, count = 0; i < ( startIndex + 30 ); ++i, ++count ) { - landsetInitializePacket->data().land[ count ].plotSize = getLand( i )->getSize(); - landsetInitializePacket->data().land[ count ].houseState = getLand( i )->getState(); - landsetInitializePacket->data().land[ count ].type = static_cast< uint8_t >( getLand( i )->getLandType() ); - landsetInitializePacket->data().land[ count ].iconAddIcon = getLand( i )->getSharing(); - landsetInitializePacket->data().land[ count ].fcId = getLand( i )->getFcId(); - landsetInitializePacket->data().land[ count ].fcIcon = getLand( i )->getFcIcon(); - landsetInitializePacket->data().land[ count ].fcIconColor = getLand( i )->getFcColor(); + auto pLand = getLand( i ); + landsetInitializePacket->data().land[ count ].plotSize = pLand->getSize(); + landsetInitializePacket->data().land[ count ].houseState = pLand->getState(); + landsetInitializePacket->data().land[ count ].type = static_cast< uint8_t >( pLand->getLandType() ); + landsetInitializePacket->data().land[ count ].iconAddIcon = pLand->getSharing(); + landsetInitializePacket->data().land[ count ].fcId = pLand->getFcId(); + landsetInitializePacket->data().land[ count ].fcIcon = pLand->getFcIcon(); + landsetInitializePacket->data().land[ count ].fcIconColor = pLand->getFcColor(); } player.queuePacket( landsetInitializePacket ); @@ -167,63 +168,11 @@ bool Core::HousingZone::isPlayerSubInstance( Entity::Player& player ) return player.getPos().x < -15000.0f; //ToDo: get correct pos } -Core::LandPurchaseResult Core::HousingZone::purchseLand( Entity::Player& player, uint8_t plot, uint8_t state ) -{ - - auto plotPrice = getLand( plot )->getCurrentPrice(); - auto gilAvailable = player.getCurrency( CurrencyType::Gil ); - auto pLand = getLand( plot ); - - if( !pLand ) - return LandPurchaseResult::ERR_INTERNAL; - - if( pLand->getState() != HouseState::forSale ) - return LandPurchaseResult::ERR_NOT_AVAILABLE; - - if( gilAvailable < plotPrice ) - return LandPurchaseResult::ERR_NOT_ENOUGH_GIL; - - auto pHousing = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() ); - - switch( static_cast< LandPurchaseMode >( state ) ) - { - case LandPurchaseMode::FC: - player.sendDebug( "Free company house purchase aren't supported at this time." ); - return LandPurchaseResult::ERR_INTERNAL; - - case LandPurchaseMode::PRIVATE: - { - - auto pHousingMgr = g_fw.get< HousingMgr >(); - auto pOldLand = pHousingMgr->getLandByOwnerId( player.getId() ); - - if( pOldLand ) - return LandPurchaseResult::ERR_NO_MORE_LANDS_FOR_CHAR; - - player.removeCurrency( CurrencyType::Gil, plotPrice ); - pLand->setPlayerOwner( player.getId() ); - pLand->setState( HouseState::sold ); - pLand->setLandType( Common::LandType::Private ); - player.setLandPermissions( LandPermissionSlot::Private, 0x00, plot, - pHousing->getWardNum(), pHousing->getTerritoryTypeId() ); - player.sendLandPermissions(); - //pLand->setLandName( "Private Estate" + std::to_string( pHousing->getWardNum() ) + "-" + std::to_string( plot ) ); - pLand->UpdateLandDb(); - sendLandUpdate( plot ); - return LandPurchaseResult::SUCCESS; - } - - default: - return LandPurchaseResult::ERR_INTERNAL; - } - -} - void Core::HousingZone::onUpdate( uint32_t currTime ) { - for( uint8_t i = 0; i < 60; i++ ) + for( auto pLandItr : m_landPtrMap ) { - getLand( i )->Update( currTime ); + pLandItr.second->update( currTime ); } } diff --git a/src/servers/sapphire_zone/Zone/HousingZone.h b/src/servers/sapphire_zone/Zone/HousingZone.h index ef321b98..919d69df 100644 --- a/src/servers/sapphire_zone/Zone/HousingZone.h +++ b/src/servers/sapphire_zone/Zone/HousingZone.h @@ -42,8 +42,6 @@ namespace Core void sendLandUpdate( uint8_t landId ); bool isPlayerSubInstance( Entity::Player& player ); - LandPurchaseResult purchseLand( Entity::Player& player, uint8_t plot, uint8_t state ); - /* returns current ward number for this zone */ uint8_t getWardNum() const; @@ -60,4 +58,4 @@ namespace Core }; } -#endif //SAPPHIRE_HOUSINGZONE_H \ No newline at end of file +#endif //SAPPHIRE_HOUSINGZONE_H diff --git a/src/servers/sapphire_zone/Zone/Land.cpp b/src/servers/sapphire_zone/Zone/Land.cpp index 99f19548..1b263e8f 100644 --- a/src/servers/sapphire_zone/Zone/Land.cpp +++ b/src/servers/sapphire_zone/Zone/Land.cpp @@ -224,7 +224,7 @@ void Core::Land::init() } } -void Core::Land::UpdateLandDb() +void Core::Land::updateLandDb() { auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); pDb->directExecute( "UPDATE land SET status = " + std::to_string( m_state ) @@ -237,7 +237,7 @@ void Core::Land::UpdateLandDb() + " AND LandId = " + std::to_string( m_landId ) + ";" ); } -void Core::Land::Update( uint32_t currTime ) +void Core::Land::update( uint32_t currTime ) { if( getState() == HouseState::forSale ) { @@ -245,7 +245,7 @@ void Core::Land::Update( uint32_t currTime ) { m_nextDrop = currTime + 21600; m_currentPrice = ( m_currentPrice / 100 ) * 99.58; - UpdateLandDb(); + updateLandDb(); } } } diff --git a/src/servers/sapphire_zone/Zone/Land.h b/src/servers/sapphire_zone/Zone/Land.h index 41557cca..5522255b 100644 --- a/src/servers/sapphire_zone/Zone/Land.h +++ b/src/servers/sapphire_zone/Zone/Land.h @@ -47,8 +47,8 @@ namespace Core uint32_t getPlayerOwner(); //Housing Functions void setPreset( uint32_t itemId ); - void UpdateLandDb(); - void Update( uint32_t currTime ); + void updateLandDb(); + void update( uint32_t currTime ); uint32_t getMaxItems(); uint32_t getCurrentPrice() const;