From 12eadd02e93a6b8223257a7e903561af72961619 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 25 Nov 2018 01:55:53 +1100 Subject: [PATCH] broken housing --- src/common/Network/CommonActorControl.h | 1 + src/servers/sapphire_zone/Actor/Player.cpp | 2 +- src/servers/sapphire_zone/Zone/House.cpp | 15 +++++- src/servers/sapphire_zone/Zone/HousingMgr.cpp | 6 ++- .../sapphire_zone/Zone/HousingZone.cpp | 15 +++++- src/servers/sapphire_zone/Zone/Land.cpp | 48 ++++++++++++++++--- src/servers/sapphire_zone/Zone/Land.h | 5 +- 7 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/common/Network/CommonActorControl.h b/src/common/Network/CommonActorControl.h index 72ff77f3..5d126c49 100644 --- a/src/common/Network/CommonActorControl.h +++ b/src/common/Network/CommonActorControl.h @@ -290,6 +290,7 @@ enum ActorControlType : uint16_t AchievementList = 0x3E9, RequestHousingBuildPreset = 0x44C, + RequestEstateHallRemoval = 0x44F, RequestBuildPreset = 0x450, // no idea what this is, it gets sent with BuildPresetHandler and has the plot id in param1 RequestLandSignFree = 0x451, RequestLandSignOwned = 0x452, diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp index 7aba3e56..62e6143a 100644 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ b/src/servers/sapphire_zone/Actor/Player.cpp @@ -1580,7 +1580,7 @@ void Core::Entity::Player::sendZonePackets() auto pHousingMgr = g_fw.get< HousingMgr >(); if( Core::LandPtr pLand = pHousingMgr->getLandByOwnerId( getId() ) ) { - setLandPermissions( LandPermissionSlot::Private, 0x00, pLand->getLandId(), pLand->getWardNum(), pLand->getZoneId() ); + setLandPermissions( LandPermissionSlot::Private, 0x00, pLand->getLandId(), pLand->getWardNum(), pLand->getTerritoryTypeId() ); } sendLandPermissions(); diff --git a/src/servers/sapphire_zone/Zone/House.cpp b/src/servers/sapphire_zone/Zone/House.cpp index 7b9a74b3..55ca5b1d 100644 --- a/src/servers/sapphire_zone/Zone/House.cpp +++ b/src/servers/sapphire_zone/Zone/House.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "House.h" @@ -20,6 +21,18 @@ Core::House::House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_ { memset( &m_houseParts, 0x00, sizeof( m_houseParts ) ); memset( &m_commentMsg, 0x00, sizeof( m_commentMsg ) ); + + auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); + auto res = pDB->query("SELECT * FROM house WHERE HouseId = " + std::to_string( houseId ) ); + + if( !res->next() ) + { + pDB->directExecute("INSERT INTO house ( LandSetId, HouseId ) VALUES ( " + std::to_string( m_landSetId ) + ", " + std::to_string( m_houseId ) + " )" ); + } + else + { + // todo + } } Core::House::~House() @@ -70,4 +83,4 @@ void Core::House::setHousePartColor( Common::HousePartSlot slot, uint32_t id ) uint32_t Core::House::getHousePart( Common::HousePartSlot slot ) const { return m_houseParts[ slot ]; -} +} \ 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 8b52c753..28c18adf 100644 --- a/src/servers/sapphire_zone/Zone/HousingMgr.cpp +++ b/src/servers/sapphire_zone/Zone/HousingMgr.cpp @@ -98,7 +98,7 @@ void Core::HousingMgr::sendLandSignOwned( Entity::Player& player, uint8_t wardId memcpy( &landInfoSignPacket->data().ownerName, playerName.c_str(), playerName.size() ); landInfoSignPacket->data().wardNum = land->getWardNum(); landInfoSignPacket->data().worldId = 67; - landInfoSignPacket->data().zoneId = land->getZoneId(); + landInfoSignPacket->data().zoneId = land->getTerritoryTypeId(); player.queuePacket( landInfoSignPacket ); } @@ -290,7 +290,9 @@ void Core::HousingMgr::buildPresetEstate( Entity::Player& player, uint8_t plotNu // todo: check if permit is in inventory and remove one - pLand->setPreset( presetItem ); + if( !pLand->setPreset( presetItem ) ) + return; + pLand->setState( HouseState::privateHouse ); pLand->setLandType( LandType::Private ); pLand->updateLandDb(); diff --git a/src/servers/sapphire_zone/Zone/HousingZone.cpp b/src/servers/sapphire_zone/Zone/HousingZone.cpp index 9d52a1f4..8ca52012 100644 --- a/src/servers/sapphire_zone/Zone/HousingZone.cpp +++ b/src/servers/sapphire_zone/Zone/HousingZone.cpp @@ -10,6 +10,7 @@ #include "Actor/Player.h" #include "Actor/Actor.h" #include "Land.h" +#include "House.h" #include "Forwards.h" #include "HousingZone.h" @@ -149,12 +150,24 @@ void Core::HousingZone::sendLandUpdate( uint8_t landId ) landUpdatePacket->data().landId = landId; landUpdatePacket->data().land.plotSize = pLand->getSize(); landUpdatePacket->data().land.houseState = pLand->getState(); - landUpdatePacket->data().land.type = static_cast< uint8_t >( pLand->getLandType() ); + landUpdatePacket->data().land.type = 0; landUpdatePacket->data().land.iconAddIcon = pLand->getSharing(); landUpdatePacket->data().land.fcId = pLand->getFcId(); landUpdatePacket->data().land.fcIcon = pLand->getFcIcon(); landUpdatePacket->data().land.fcIconColor = pLand->getFcColor(); + if( auto house = pLand->getHouse() ) + { + // todo: this is retarded, need a getter to the internal array + for( int i = 0; i < 8; i++ ) + { + auto slot = static_cast< Common::HousePartSlot >( i ); + auto part = pLand->getHouse()->getHousePart( slot ); + + landUpdatePacket->data().land.housePart[ slot ] = part; + } + } + pPlayer->queuePacket( landUpdatePacket ); } } diff --git a/src/servers/sapphire_zone/Zone/Land.cpp b/src/servers/sapphire_zone/Zone/Land.cpp index 8488c139..3fbcd3ae 100644 --- a/src/servers/sapphire_zone/Zone/Land.cpp +++ b/src/servers/sapphire_zone/Zone/Land.cpp @@ -20,14 +20,15 @@ #include "Forwards.h" #include "Land.h" #include "Framework.h" +#include "House.h" extern Core::Framework g_fw; using namespace Core::Common; -Core::Land::Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, +Core::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Core::Data::HousingLandSetPtr info ) : - m_zoneId( zoneId ), + m_territoryTypeId( territoryTypeId ), m_wardNum( wardNum ), m_landId( landId ), m_currentPrice( 0 ), @@ -36,7 +37,11 @@ Core::Land::Land( uint16_t zoneId, uint8_t wardNum, uint8_t landId, uint32_t lan m_ownerPlayerId( 0 ), m_landSetId( landSetId ), m_landInfo( info ), - m_type( Common::LandType::Private ) + m_type( Common::LandType::Private ), + m_fcIcon( 0 ), + m_fcIconColor( 0 ), + m_fcId( 0 ), + m_iconAddIcon( 0 ) { memset( &m_tag, 0x00, 3 ); @@ -147,9 +152,9 @@ uint8_t Core::Land::getLandId() const return m_landId; } -uint16_t Core::Land::getZoneId() const +uint16_t Core::Land::getTerritoryTypeId() const { - return m_zoneId; + return m_territoryTypeId; } Core::HousePtr Core::Land::getHouse() const @@ -242,12 +247,17 @@ void Core::Land::init() void Core::Land::updateLandDb() { + uint32_t houseId = 0; + + if( getHouse() ) + houseId = getHouse()->getHouseId(); + auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); pDb->directExecute( "UPDATE land SET status = " + std::to_string( m_state ) + ", LandPrice = " + std::to_string( getCurrentPrice() ) + ", UpdateTime = " + std::to_string( getDevaluationTime() ) + ", OwnerId = " + std::to_string( getPlayerOwner() ) - + ", HouseId = " + std::to_string( 0 ) //TODO: add house id + + ", HouseId = " + std::to_string( houseId ) + ", Type = " + std::to_string( static_cast< uint32_t >( m_type ) ) //TODO: add house id + " WHERE LandSetId = " + std::to_string( m_landSetId ) + " AND LandId = " + std::to_string( m_landId ) + ";" ); @@ -266,6 +276,17 @@ void Core::Land::update( uint32_t currTime ) } } +uint32_t Core::Land::getNextHouseId() +{ + auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); + auto pQR = pDb->query( "SELECT MAX( HouseId ) FROM house" ); + + if( !pQR->next() ) + return 0; + + return pQR->getUInt( 1 ) + 1; +} + bool Core::Land::setPreset( uint32_t itemId ) { auto housingItemId = convertItemIdToHousingItemId( itemId ); @@ -275,5 +296,20 @@ bool Core::Land::setPreset( uint32_t itemId ) return false; auto housingPreset = exdData->get< Core::Data::HousingPreset >( housingItemId ); + if( !housingPreset ) + return false; + if( !getHouse() ) + { + // todo: i guess we'd create a house here? + auto newId = getNextHouseId(); + m_pHouse = make_House( newId, getLandSetId(), getLandId(), getWardNum(), getTerritoryTypeId() ); + } + + getHouse()->setHousePart( Common::HousePartSlot::ExteriorRoof, housingPreset->exteriorRoof ); + getHouse()->setHousePart( Common::HousePartSlot::ExteriorWall, housingPreset->exteriorWall ); + getHouse()->setHousePart( Common::HousePartSlot::ExteriorWindow, housingPreset->exteriorWindow ); + getHouse()->setHousePart( Common::HousePartSlot::ExteriorDoor, housingPreset->exteriorDoor ); + + return true; } diff --git a/src/servers/sapphire_zone/Zone/Land.h b/src/servers/sapphire_zone/Zone/Land.h index 243ca62c..3bf792d2 100644 --- a/src/servers/sapphire_zone/Zone/Land.h +++ b/src/servers/sapphire_zone/Zone/Land.h @@ -33,7 +33,7 @@ namespace Core uint32_t getLandSetId() const; uint8_t getWardNum() const; uint8_t getLandId() const; - uint16_t getZoneId() const; + uint16_t getTerritoryTypeId() const; Common::LandType getLandType() const; Core::HousePtr getHouse() const; @@ -64,11 +64,12 @@ namespace Core private: uint32_t convertItemIdToHousingItemId( uint32_t itemId ); void init(); + uint32_t getNextHouseId(); uint8_t m_wardNum; uint8_t m_landId; uint32_t m_landSetId; - uint16_t m_zoneId; + uint16_t m_territoryTypeId; uint8_t m_size; uint8_t m_state; Common::LandType m_type;