1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-17 16:07:45 +00:00
sapphire/src/world/Territory/House.cpp

120 lines
2.7 KiB
C++
Raw Normal View History

2018-11-19 09:40:44 +01:00
#include <set>
2018-11-19 10:04:54 +01:00
#include <string.h>
2018-11-19 09:40:44 +01:00
#include <Logging/Logger.h>
#include <Exd/ExdDataGenerated.h>
2018-11-25 01:55:53 +11:00
#include <Database/DatabaseDef.h>
2018-11-26 23:32:22 +11:00
#include <Database/ZoneDbConnection.h>
2018-11-19 09:40:44 +01:00
#include "House.h"
#include <unordered_map>
2020-03-01 01:00:57 +11:00
#include <Service.h>
2018-11-19 09:40:44 +01:00
Sapphire::House::House( uint32_t houseId, uint32_t landSetId, Common::LandIdent ident, const std::string& estateName,
2020-03-01 01:00:57 +11:00
const std::string& estateComment ) :
2018-11-19 09:40:44 +01:00
m_houseId( houseId ),
m_landSetId( landSetId ),
m_landIdent( ident ),
m_estateName( estateName ),
2020-03-01 01:00:57 +11:00
m_estateComment( estateComment )
{
m_interiorModelCache.fill( 0 );
m_exteriorModelCache.fill( std::make_pair( 0, 0 ) );
}
Sapphire::House::~House() = default;
2018-11-26 23:32:22 +11:00
void Sapphire::House::updateHouseDb()
2018-11-26 23:32:22 +11:00
{
2020-03-01 01:00:57 +11:00
auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref();
2018-11-26 23:32:22 +11:00
2018-12-22 17:29:40 +11:00
// BuildTime = 1, Aetheryte = 2, Comment = 3, HouseName = 4, Endorsements = 5, HouseId = 6
2020-03-01 01:00:57 +11:00
auto stmt = db.getPreparedStatement( Db::HOUSING_HOUSE_UP );
2018-12-22 17:29:40 +11:00
stmt->setUInt( 6, m_houseId );
2018-11-26 23:32:22 +11:00
stmt->setInt64( 1, static_cast< int64_t >( m_buildTime ) );
2018-12-29 19:38:29 +11:00
stmt->setBool( 2, m_hasAetheryte );
2018-11-26 23:32:22 +11:00
stmt->setString( 3, m_estateComment );
stmt->setString( 4, m_estateName );
2018-11-26 23:32:22 +11:00
stmt->setUInt64( 5, 0 );
2020-03-01 01:00:57 +11:00
db.execute( stmt );
2018-11-19 09:40:44 +01:00
}
uint32_t Sapphire::House::getLandSetId() const
2018-11-19 09:40:44 +01:00
{
return m_landSetId;
}
Sapphire::Common::LandIdent Sapphire::House::getLandIdent() const
2018-11-19 09:40:44 +01:00
{
return m_landIdent;
2018-11-19 10:32:58 +01:00
}
2018-12-23 20:54:21 +11:00
uint32_t Sapphire::House::getId() const
2018-11-19 09:40:44 +01:00
{
return m_houseId;
}
Sapphire::House::ExteriorModelsArray const& Sapphire::House::getHouseModels() const
2018-11-19 09:40:44 +01:00
{
return m_exteriorModelCache;
2018-11-19 09:40:44 +01:00
}
const std::string& Sapphire::House::getHouseName() const
2018-12-01 21:40:30 +01:00
{
return m_estateName;
2018-12-01 21:40:30 +01:00
}
const std::string& Sapphire::House::getHouseGreeting() const
2018-11-19 09:40:44 +01:00
{
return m_estateComment;
2018-11-19 09:40:44 +01:00
}
void Sapphire::House::setHouseGreeting( const std::string& greeting )
2018-11-19 09:40:44 +01:00
{
m_estateComment = greeting;
2018-11-19 09:40:44 +01:00
updateHouseDb();
2018-12-01 21:40:30 +01:00
}
void Sapphire::House::setHouseName( const std::string& name )
2018-11-19 09:40:44 +01:00
{
m_estateName = name;
updateHouseDb();
2018-11-27 21:11:02 +11:00
}
void Sapphire::House::setExteriorModel( Sapphire::Common::HouseExteriorSlot slot, uint32_t modelId, uint16_t stain )
2018-11-27 21:11:02 +11:00
{
m_exteriorModelCache[ slot ] = std::make_pair( modelId, stain );
2018-11-27 21:11:02 +11:00
}
Sapphire::House::HousePart Sapphire::House::getExteriorModel( Sapphire::Common::HouseExteriorSlot slot )
2018-11-27 21:11:02 +11:00
{
return m_exteriorModelCache[ slot ];
2018-11-28 00:05:57 +11:00
}
2018-12-30 17:44:03 +11:00
void Sapphire::House::setInteriorModel( Sapphire::Common::HouseInteriorSlot slot, uint32_t modelId )
2018-11-28 00:05:57 +11:00
{
m_interiorModelCache[ slot ] = modelId;
2018-11-28 00:05:57 +11:00
}
2018-12-30 17:44:03 +11:00
uint32_t Sapphire::House::getInteriorModel( Sapphire::Common::HouseInteriorSlot slot )
2018-11-28 00:05:57 +11:00
{
return m_interiorModelCache[ slot ];
2018-12-29 19:38:29 +11:00
}
bool Sapphire::House::getHasAetheryte() const
{
return m_hasAetheryte;
}
void Sapphire::House::setHasAetheryte( bool hasAetheryte )
{
m_hasAetheryte = hasAetheryte;
}