1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 14:37:44 +00:00

save & load house state

This commit is contained in:
NotAdam 2018-11-26 23:32:22 +11:00
parent 89c8293eef
commit 345de71494
8 changed files with 115 additions and 23 deletions

View file

@ -181,8 +181,8 @@ void Core::Db::ZoneDbConnection::doPrepareStatements()
"secWeaponModel, aggressionMode, enemyType, pose, " "secWeaponModel, aggressionMode, enemyType, pose, "
"modelChara, displayFlags, Look, Models " "modelChara, displayFlags, Look, Models "
"FROM bnpctemplate WHERE 1;", "FROM bnpctemplate WHERE 1;",
CONNECTION_BOTH); CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_UP, prepareStatement( CHARA_ITEMGLOBAL_UP,
"UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;", "UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;",
CONNECTION_BOTH ); CONNECTION_BOTH );
@ -191,6 +191,15 @@ void Core::Db::ZoneDbConnection::doPrepareStatements()
"UPDATE charaglobalitem SET IS_DELETE = 1 WHERE ItemId = ?;", "UPDATE charaglobalitem SET IS_DELETE = 1 WHERE ItemId = ?;",
CONNECTION_BOTH ); CONNECTION_BOTH );
/// HOUSING
prepareStatement( HOUSING_HOUSE_INS,
"INSERT INTO house ( LandSetId, HouseId ) VALUES ( ?, ? );",
CONNECTION_BOTH );
prepareStatement( HOUSING_HOUSE_UP,
"UPDATE house SET BuildTime = ?, Aetheryte = ?, Comment = ?, HouseName = ?, Endorsements = ?, HousePartModels = ?, HousePartColours = ? WHERE HouseId = ?;",
CONNECTION_BOTH );
/*prepareStatement( LAND_INS, /*prepareStatement( LAND_INS,
"INSERT INTO land ( LandSetId ) VALUES ( ? );", "INSERT INTO land ( LandSetId ) VALUES ( ? );",
CONNECTION_BOTH ); CONNECTION_BOTH );

View file

@ -81,6 +81,9 @@ namespace Core::Db
LAND_INS, LAND_INS,
LAND_SEL, LAND_SEL,
LAND_UP, LAND_UP,
HOUSING_HOUSE_INS,
HOUSING_HOUSE_UP,
HOUSING_HOUSE_DEL,
MAX_STATEMENTS MAX_STATEMENTS

View file

@ -297,7 +297,11 @@ enum ActorControlType : uint16_t
RequestWardLandInfo = 0x453, RequestWardLandInfo = 0x453,
RequestLandRelinquish = 0x454, RequestLandRelinquish = 0x454,
RequestEstateRename = 0x45A, RequestEstateRename = 0x45A,
RequestEstateEditGreeting = 0x45B,
RequestEstateGreeting = 0x45C, // sends FFXIVIpcHousingEstateGreeting in return RequestEstateGreeting = 0x45C, // sends FFXIVIpcHousingEstateGreeting in return
RequestEstateEditGuestAccessSettings = 0x45D,
RequestEstateTagSettings = 0x45F,
RequestHousingItemUI = 0x463, RequestHousingItemUI = 0x463,
RequestSharedEstateSettings = 0x46F, RequestSharedEstateSettings = 0x46F,

View file

@ -4,6 +4,7 @@
#include <Logging/Logger.h> #include <Logging/Logger.h>
#include <Exd/ExdDataGenerated.h> #include <Exd/ExdDataGenerated.h>
#include <Database/DatabaseDef.h> #include <Database/DatabaseDef.h>
#include <Database/ZoneDbConnection.h>
#include "House.h" #include "House.h"
@ -19,25 +20,79 @@ Core::House::House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_
m_wardNum( wardNum ), m_wardNum( wardNum ),
m_territoryTypeId( territoryTypeId ) m_territoryTypeId( territoryTypeId )
{ {
memset( &m_houseParts, 0x00, sizeof( m_houseParts ) );
memset( &m_commentMsg, 0x00, sizeof( m_commentMsg ) );
auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
auto res = pDB->query("SELECT * FROM house WHERE HouseId = " + std::to_string( houseId ) );
// todo: convert to prepared statement
auto res = pDB->query( "SELECT * FROM house WHERE HouseId = " + std::to_string( houseId ) );
if( !res->next() ) if( !res->next() )
{ {
pDB->directExecute("INSERT INTO house ( LandSetId, HouseId ) VALUES ( " + std::to_string( m_landSetId ) + ", " + std::to_string( m_houseId ) + " )" ); g_fw.get< Core::Logger >()->info( "Creating house House#" + std::to_string( houseId ) + " in LandSet#" + std::to_string( landSetId ) );
auto stmt = pDB->getPreparedStatement( Db::HOUSING_HOUSE_INS );
stmt->setUInt( 1, m_landSetId );
stmt->setUInt( 2, m_houseId );
pDB->execute( stmt );
} }
else else
{ {
// todo m_estateMessage = res->getString( "Comment" );
m_houseName = res->getString( "HouseName" );
auto housePartModels = res->getBlobVector( "HousePartModels" );
auto housePartColours = res->getBlobVector( "HousePartColours" );
auto models = reinterpret_cast< uint32_t* >( &housePartModels[ 0 ] );
auto colours = &housePartColours[ 0 ];
for( auto i = 0; i < 8; i++ )
{
m_houseParts[ i ] = { models[ i ], colours[ i ] };
}
} }
} }
Core::House::~House() Core::House::~House()
{ {
}
void Core::House::updateHouseDb()
{
auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
// BuildTime = 1, Aetheryte = 2, Comment = 3, HouseName = 4, Endorsements = 5,
// HousePartModels = 6, HousePartColours = 7, HouseId = 8
auto stmt = pDB->getPreparedStatement( Db::HOUSING_HOUSE_UP );
stmt->setUInt( 8, m_houseId );
stmt->setInt64( 1, m_buildTime );
stmt->setInt( 2, 0 );
stmt->setString( 3, m_estateMessage );
stmt->setString( 4, m_houseName );
stmt->setUInt64( 5, 0 );
std::vector< uint32_t > models;
std::vector< uint8_t > colours;
for( auto i = 0; i < 8; i++ )
{
auto& part = m_houseParts[ i ];
models.push_back( part.first );
colours.push_back( part.second );
}
// todo: this is shit
std::vector< uint8_t > tmpModels( models.size() * 4 );
memcpy( tmpModels.data(), models.data(), tmpModels.size() );
stmt->setBinary( 6, tmpModels );
stmt->setBinary( 7, colours );
pDB->execute( stmt );
} }
uint32_t Core::House::getLandSetId() const uint32_t Core::House::getLandSetId() const
@ -67,22 +122,22 @@ uint32_t Core::House::getHouseId() const
uint8_t Core::House::getHousePartColor( Common::HousePartSlot slot ) const uint8_t Core::House::getHousePartColor( Common::HousePartSlot slot ) const
{ {
return std::get< 1 >( m_houseParts[ slot ] ); return m_houseParts[ slot ].second;
} }
void Core::House::setHousePart( Common::HousePartSlot slot, uint32_t id ) void Core::House::setHousePart( Common::HousePartSlot slot, uint32_t id )
{ {
std::get< 0 >( m_houseParts[ slot ] ) = id; m_houseParts[ slot ].first = id;
} }
void Core::House::setHousePartColor( Common::HousePartSlot slot, uint32_t id ) void Core::House::setHousePartColor( Common::HousePartSlot slot, uint32_t id )
{ {
std::get< 1 >( m_houseParts[ slot ] ) = id; m_houseParts[ slot ].second = id;
} }
uint32_t Core::House::getHousePart( Common::HousePartSlot slot ) const uint32_t Core::House::getHousePart( Common::HousePartSlot slot ) const
{ {
return std::get< 0 >( m_houseParts[ slot ] ); return m_houseParts[ slot ].first;
} }
Core::House::HousePartsArray const& Core::House::getHouseParts() const Core::House::HousePartsArray const& Core::House::getHouseParts() const

View file

@ -15,7 +15,7 @@ namespace Core
House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_t wardNum, uint16_t territoryTypeId ); House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_t wardNum, uint16_t territoryTypeId );
virtual ~House(); virtual ~House();
using HousePart = std::tuple< uint32_t, uint8_t >; using HousePart = std::pair< uint32_t, uint8_t >;
using HousePartsArray = std::array< HousePart, 8 >; using HousePartsArray = std::array< HousePart, 8 >;
//gerneral //gerneral
@ -33,6 +33,8 @@ namespace Core
HousePartsArray const& getHouseParts() const; HousePartsArray const& getHouseParts() const;
void updateHouseDb();
private: private:
uint32_t m_landSetId; uint32_t m_landSetId;
uint8_t m_landId; uint8_t m_landId;
@ -40,9 +42,12 @@ namespace Core
uint16_t m_territoryTypeId; uint16_t m_territoryTypeId;
uint32_t m_houseId; uint32_t m_houseId;
uint64_t m_buildTime;
HousePartsArray m_houseParts; HousePartsArray m_houseParts;
char m_commentMsg[ 193 ]; std::string m_estateMessage;
std::string m_houseName;
}; };
} }

View file

@ -295,10 +295,19 @@ void Core::HousingMgr::buildPresetEstate( Entity::Player& player, uint8_t plotNu
pLand->setState( HouseState::privateHouse ); pLand->setState( HouseState::privateHouse );
pLand->setLandType( LandType::Private ); pLand->setLandType( LandType::Private );
pLand->updateLandDb();
hZone->sendLandUpdate( plotNum ); hZone->sendLandUpdate( plotNum );
auto pSuccessBuildingPacket = makeActorControl142( player.getId(), ActorControl::BuildPresetResponse, plotNum ); auto pSuccessBuildingPacket = makeActorControl142( player.getId(), ActorControl::BuildPresetResponse, plotNum );
player.queuePacket( pSuccessBuildingPacket ); player.queuePacket( pSuccessBuildingPacket );
pLand->updateLandDb();
// start house built event
// CmnDefHousingBuildHouse_00149
player.eventStart( player.getId(), 0x000B0095, Event::EventHandler::EventType::Housing, 1, 1 );
// todo: wtf are these flags
player.playScene( 0x000B0095, 0, 4164955899, 0, 1, plotNum, nullptr );
// todo: send perms/flags for house
} }

View file

@ -145,10 +145,8 @@ void Core::HousingZone::sendLandSet( Entity::Player& player )
for( auto i = 0; i != parts.size(); i++ ) for( auto i = 0; i != parts.size(); i++ )
{ {
auto [ part, colour ] = parts[ i ]; landData.housePart[ i ] = parts[ i ].first;
landData.houseColour[ i ] = parts[ i ].second;
landData.housePart[ i ] = part;
landData.houseColour[ i ] = colour;
} }
} }
} }
@ -183,10 +181,8 @@ void Core::HousingZone::sendLandUpdate( uint8_t landId )
for( auto i = 0; i != parts.size(); i++ ) for( auto i = 0; i != parts.size(); i++ )
{ {
auto [ part, colour ] = parts[ i ]; landData.housePart[ i ] = parts[ i ].first;
landData.houseColour[ i ] = parts[ i ].second;
landData.housePart[ i ] = part;
landData.houseColour[ i ] = colour;
} }
} }

View file

@ -80,6 +80,13 @@ void Core::Land::load()
m_ownerPlayerId = res->getUInt( "OwnerId" ); m_ownerPlayerId = res->getUInt( "OwnerId" );
m_minPrice = m_landInfo->minPrice[ m_landId ]; m_minPrice = m_landInfo->minPrice[ m_landId ];
m_maxPrice = m_landInfo->initialPrice[ m_landId ]; m_maxPrice = m_landInfo->initialPrice[ m_landId ];
auto houseId = res->getUInt( "HouseId" );
// fetch the house if we have one for this land
if( houseId > 0 )
m_pHouse = make_House( houseId, m_landSetId, m_landId, m_wardNum, m_territoryTypeId );
} }
init(); init();
} }
@ -252,6 +259,7 @@ void Core::Land::updateLandDb()
if( getHouse() ) if( getHouse() )
houseId = getHouse()->getHouseId(); houseId = getHouse()->getHouseId();
// todo: change to prepared statement
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
pDb->directExecute( "UPDATE land SET status = " + std::to_string( m_state ) pDb->directExecute( "UPDATE land SET status = " + std::to_string( m_state )
+ ", LandPrice = " + std::to_string( getCurrentPrice() ) + ", LandPrice = " + std::to_string( getCurrentPrice() )
@ -261,6 +269,9 @@ void Core::Land::updateLandDb()
+ ", Type = " + std::to_string( static_cast< uint32_t >( m_type ) ) //TODO: add house id + ", Type = " + std::to_string( static_cast< uint32_t >( m_type ) ) //TODO: add house id
+ " WHERE LandSetId = " + std::to_string( m_landSetId ) + " WHERE LandSetId = " + std::to_string( m_landSetId )
+ " AND LandId = " + std::to_string( m_landId ) + ";" ); + " AND LandId = " + std::to_string( m_landId ) + ";" );
if( auto house = getHouse() )
house->updateHouseDb();
} }
void Core::Land::update( uint32_t currTime ) void Core::Land::update( uint32_t currTime )