1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 08:57:44 +00:00

broken housing

This commit is contained in:
NotAdam 2018-11-25 01:55:53 +11:00
parent b739b154b9
commit 12eadd02e9
7 changed files with 79 additions and 13 deletions

View file

@ -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,

View file

@ -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();

View file

@ -3,6 +3,7 @@
#include <Logging/Logger.h>
#include <Exd/ExdDataGenerated.h>
#include <Database/DatabaseDef.h>
#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()

View file

@ -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();

View file

@ -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 );
}
}

View file

@ -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;
}

View file

@ -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;