1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-05 10:17:46 +00:00

Move land/house to use LandIdent instead of storing terri/plot/ward

This commit is contained in:
NotAdam 2018-12-21 22:08:05 +11:00
parent 2b89c1a3cb
commit 419a61f8ff
8 changed files with 64 additions and 84 deletions

View file

@ -200,6 +200,14 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
"UPDATE house SET BuildTime = ?, Aetheryte = ?, Comment = ?, HouseName = ?, Endorsements = ?, HousePartModels = ?, HousePartColours = ?, HouseInteriorModels = ? WHERE HouseId = ?;", "UPDATE house SET BuildTime = ?, Aetheryte = ?, Comment = ?, HouseName = ?, Endorsements = ?, HousePartModels = ?, HousePartColours = ?, HouseInteriorModels = ? WHERE HouseId = ?;",
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( LAND_INV_SEL_ALL,
"SELECT LandIdent, ContainerId, ItemId, SlotId FROM houseiteminventory;",
CONNECTION_BOTH );
prepareStatement( LAND_INV_SEL_HOUSE,
"SELECT LandIdent, ContainerId, ItemId, SlotId FROM houseiteminventory WHERE LandIdent = ?",
CONNECTION_BOTH );
/*prepareStatement( LAND_INS, /*prepareStatement( LAND_INS,
"INSERT INTO land ( LandSetId ) VALUES ( ? );", "INSERT INTO land ( LandSetId ) VALUES ( ? );",
CONNECTION_BOTH ); CONNECTION_BOTH );

View file

@ -85,6 +85,11 @@ namespace Sapphire::Db
HOUSING_HOUSE_UP, HOUSING_HOUSE_UP,
HOUSING_HOUSE_DEL, HOUSING_HOUSE_DEL,
LAND_INV_SEL_ALL,
LAND_INV_SEL_HOUSE,
LAND_INV_DEL,
LAND_INV_UP,
MAX_STATEMENTS MAX_STATEMENTS
}; };

View file

@ -1618,7 +1618,8 @@ void Sapphire::Entity::Player::sendZonePackets()
state |= HasAetheryte; state |= HasAetheryte;
} }
setLandFlags( LandFlagsSlot::Private, state, pLand->getLandId(), pLand->getWardNum(), pLand->getTerritoryTypeId() ); auto ident = pLand->getLandIdent();
setLandFlags( LandFlagsSlot::Private, state, ident.landId, ident.wardNum, ident.territoryTypeId );
} }
sendLandFlags(); sendLandFlags();

View file

@ -222,7 +222,7 @@ bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& playe
player.sendLandFlagsSlot( LandFlagsSlot::Private ); player.sendLandFlagsSlot( LandFlagsSlot::Private );
auto screenMsgPkt2 = makeActorControl143( player.getId(), ActorControl::LogMsg, 3351, 0x1AA, auto screenMsgPkt2 = makeActorControl143( player.getId(), ActorControl::LogMsg, 3351, 0x1AA,
pLand->getWardNum() + 1, plot + 1 ); pLand->getLandIdent().wardNum + 1, plot + 1 );
player.queuePacket( screenMsgPkt2 ); player.queuePacket( screenMsgPkt2 );
pHousing->sendLandUpdate( plot ); pHousing->sendLandUpdate( plot );
@ -351,7 +351,9 @@ void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& pl
player.eventStart( player.getId(), 0x000B0095, Event::EventHandler::EventType::Housing, 1, 1 ); player.eventStart( player.getId(), 0x000B0095, Event::EventHandler::EventType::Housing, 1, 1 );
player.playScene( 0x000B0095, 0, SET_BASE | HIDE_HOTBAR , 0, 1, plotNum, nullptr ); player.playScene( 0x000B0095, 0, SET_BASE | HIDE_HOTBAR , 0, 1, plotNum, nullptr );
player.setLandFlags( LandFlagsSlot::Private, EstateBuilt, pLand->getLandId(), pLand->getWardNum(), pLand->getTerritoryTypeId() ); auto ident = pLand->getLandIdent();
player.setLandFlags( LandFlagsSlot::Private, EstateBuilt, ident.landId, ident.wardNum, ident.territoryTypeId );
player.sendLandFlagsSlot( LandFlagsSlot::Private ); player.sendLandFlagsSlot( LandFlagsSlot::Private );
hZone->registerHouseEntranceEObj( plotNum ); hZone->registerHouseEntranceEObj( plotNum );

View file

@ -13,12 +13,10 @@
extern Sapphire::Framework g_fw; extern Sapphire::Framework g_fw;
Sapphire::House::House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_t wardNum, uint16_t territoryTypeId ) : Sapphire::House::House( uint32_t houseId, uint32_t landSetId, Common::LandIdent ident ) :
m_houseId( houseId ), m_houseId( houseId ),
m_landSetId( landSetId ), m_landSetId( landSetId ),
m_landId( landId ), m_landIdent( ident )
m_wardNum( wardNum ),
m_territoryTypeId( territoryTypeId )
{ {
auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
@ -37,7 +35,7 @@ Sapphire::House::House( uint32_t houseId, uint32_t landSetId, uint8_t landId, ui
pDB->execute( stmt ); pDB->execute( stmt );
// todo: make this nicer/configurable? // todo: make this nicer/configurable?
m_houseName = "Estate #" + std::to_string( landId + 1 ); m_houseName = "Estate #" + std::to_string( m_landIdent.landId + 1 );
} }
else else
{ {
@ -121,19 +119,9 @@ uint32_t Sapphire::House::getLandSetId() const
return m_landSetId; return m_landSetId;
} }
uint8_t Sapphire::House::getLandId() const Sapphire::Common::LandIdent Sapphire::House::getLandIdent() const
{ {
return m_landId; return m_landIdent;
}
uint8_t Sapphire::House::getWardNum() const
{
return m_wardNum;
}
uint16_t Sapphire::House::getTerritoryTypeId() const
{
return m_territoryTypeId;
} }
uint32_t Sapphire::House::getHouseId() const uint32_t Sapphire::House::getHouseId() const

View file

@ -12,7 +12,7 @@ namespace Sapphire
class House class House
{ {
public: public:
House( uint32_t houseId, uint32_t landSetId, uint8_t landId, uint8_t wardNum, uint16_t territoryTypeId ); House( uint32_t houseId, uint32_t landSetId, Common::LandIdent ident );
virtual ~House(); virtual ~House();
using HousePart = std::pair< uint32_t, uint8_t >; using HousePart = std::pair< uint32_t, uint8_t >;
@ -20,9 +20,7 @@ namespace Sapphire
//gerneral //gerneral
uint32_t getLandSetId() const; uint32_t getLandSetId() const;
uint8_t getLandId() const; Common::LandIdent getLandIdent() const;
uint8_t getWardNum() const;
uint16_t getTerritoryTypeId() const;
uint32_t getHouseId() const; uint32_t getHouseId() const;
const std::string& getHouseName() const; const std::string& getHouseName() const;
@ -45,9 +43,7 @@ namespace Sapphire
private: private:
uint32_t m_landSetId; uint32_t m_landSetId;
uint8_t m_landId; Common::LandIdent m_landIdent;
uint8_t m_wardNum;
uint16_t m_territoryTypeId;
uint32_t m_houseId; uint32_t m_houseId;
uint64_t m_buildTime; uint64_t m_buildTime;

View file

@ -28,9 +28,6 @@ using namespace Sapphire::Common;
Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId,
Sapphire::Data::HousingLandSetPtr info ) : Sapphire::Data::HousingLandSetPtr info ) :
m_territoryTypeId( territoryTypeId ),
m_wardNum( wardNum ),
m_landId( landId ),
m_currentPrice( 0 ), m_currentPrice( 0 ),
m_minPrice( 0 ), m_minPrice( 0 ),
m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ), m_nextDrop( static_cast< uint32_t >( Util::getTimeSeconds() ) + 21600 ),
@ -45,52 +42,42 @@ Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId,
{ {
memset( &m_tag, 0x00, 3 ); memset( &m_tag, 0x00, 3 );
m_landIdent.landId = landId;
m_landIdent.territoryTypeId = territoryTypeId;
m_landIdent.wardNum = wardNum;
m_landIdent.worldId = 67; // todo: fix this
init(); init();
} }
Sapphire::Land::~Land() Sapphire::Land::~Land() = default;
{
}
void Sapphire::Land::init() void Sapphire::Land::init()
{ {
// todo: move this loading logic outside of land and fetch all houses in 1 query
auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
auto res = pDb->query( "SELECT * FROM land WHERE LandSetId = " + std::to_string( m_landSetId ) + " " auto res = pDb->query( "SELECT * FROM land WHERE LandSetId = " + std::to_string( m_landSetId ) + " "
"AND LandId = " + std::to_string( m_landId ) ); "AND LandId = " + std::to_string( m_landIdent.landId ) );
if( !res->next() )
{
pDb->directExecute( "INSERT INTO land ( landsetid, landid, type, size, status, landprice, UpdateTime, OwnerId, HouseId ) "
"VALUES ( " + std::to_string( m_landSetId ) + "," + std::to_string( m_landId ) + ","
+ std::to_string( static_cast< uint8_t >( m_type ) ) + ","
+ std::to_string( m_landInfo->plotSize[ m_landId ] ) + ","
+ " 1, " + std::to_string( m_landInfo->initialPrice[ m_landId ] ) + ", 0, 0, 0 );" );
m_currentPrice = m_landInfo->initialPrice[ m_landId ]; // we're not going to be building the land table at runtime
m_minPrice = m_landInfo->minPrice[ m_landId ]; assert( res->next() );
m_size = m_landInfo->plotSize[ m_landId ];
m_state = HouseState::forSale;
}
else
{
m_type = static_cast< Common::LandType >( res->getUInt( "Type" ) );
m_size = res->getUInt( "Size" );
m_state = res->getUInt( "Status" );
m_currentPrice = res->getUInt( "LandPrice" );
m_ownerId = res->getUInt64( "OwnerId" );
m_minPrice = m_landInfo->minPrice[ m_landId ];
m_maxPrice = m_landInfo->initialPrice[ m_landId ];
auto houseId = res->getUInt( "HouseId" ); m_type = static_cast< Common::LandType >( res->getUInt( "Type" ) );
m_size = res->getUInt( "Size" );
m_state = res->getUInt( "Status" );
m_currentPrice = res->getUInt( "LandPrice" );
m_ownerId = res->getUInt64( "OwnerId" );
m_minPrice = m_landInfo->minPrice[ m_landIdent.landId ];
m_maxPrice = m_landInfo->initialPrice[ m_landIdent.landId ];
// fetch the house if we have one for this land auto houseId = res->getUInt( "HouseId" );
if( houseId > 0 )
m_pHouse = make_House( houseId, m_landSetId, m_landId, m_wardNum, m_territoryTypeId );
} // fetch the house if we have one for this land
if( houseId > 0 )
m_pHouse = make_House( houseId, m_landSetId, getLandIdent() );
auto pExdData = g_fw.get< Data::ExdDataGenerated >(); auto pExdData = g_fw.get< Data::ExdDataGenerated >();
auto info = pExdData->get< Sapphire::Data::HousingMapMarkerInfo >( getTerritoryTypeId(), getLandId() ); auto info = pExdData->get< Sapphire::Data::HousingMapMarkerInfo >( m_landIdent.territoryTypeId, m_landIdent.landId );
if( info ) if( info )
{ {
m_mapMarkerPosition.x = info->x; m_mapMarkerPosition.x = info->x;
@ -127,11 +114,17 @@ void Sapphire::Land::init()
setupContainer( InventoryType::HousingOutdoorStoreroom, m_maxPlacedExternalItems ); setupContainer( InventoryType::HousingOutdoorStoreroom, m_maxPlacedExternalItems );
setupContainer( InventoryType::HousingInteriorAppearance, 9 ); setupContainer( InventoryType::HousingInteriorAppearance, 9 );
// nb: so we're going to store these internally in one container because SE is fucked in the head
// but when an inventory is requested, we will split them into groups of 50
setupContainer( InventoryType::HousingInteriorPlacedItems1, m_maxPlacedInternalItems );
setupContainer( InventoryType::HousingInteriorStoreroom1, m_maxPlacedInternalItems );
} }
void Sapphire::Land::loadItemContainerContents() void Sapphire::Land::loadItemContainerContents()
{ {
} }
uint32_t Sapphire::Land::convertItemIdToHousingItemId( uint32_t itemId ) uint32_t Sapphire::Land::convertItemIdToHousingItemId( uint32_t itemId )
@ -192,19 +185,9 @@ uint32_t Sapphire::Land::getLandSetId() const
return m_landSetId; return m_landSetId;
} }
uint8_t Sapphire::Land::getWardNum() const Sapphire::Common::LandIdent Sapphire::Land::getLandIdent() const
{ {
return m_wardNum; return m_landIdent;
}
uint8_t Sapphire::Land::getLandId() const
{
return m_landId;
}
uint16_t Sapphire::Land::getTerritoryTypeId() const
{
return m_territoryTypeId;
} }
Sapphire::HousePtr Sapphire::Land::getHouse() const Sapphire::HousePtr Sapphire::Land::getHouse() const
@ -292,7 +275,7 @@ void Sapphire::Land::updateLandDb()
+ ", HouseId = " + std::to_string( houseId ) + ", HouseId = " + std::to_string( houseId )
+ ", 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_landIdent.landId ) + ";" );
if( auto house = getHouse() ) if( auto house = getHouse() )
house->updateHouseDb(); house->updateHouseDb();
@ -338,7 +321,7 @@ bool Sapphire::Land::setPreset( uint32_t itemId )
{ {
// todo: i guess we'd create a house here? // todo: i guess we'd create a house here?
auto newId = getNextHouseId(); auto newId = getNextHouseId();
m_pHouse = make_House( newId, getLandSetId(), getLandId(), getWardNum(), getTerritoryTypeId() ); m_pHouse = make_House( newId, getLandSetId(), getLandIdent() );
} }

View file

@ -31,12 +31,10 @@ namespace Sapphire
uint8_t getState() const; uint8_t getState() const;
uint8_t getSharing() const; uint8_t getSharing() const;
uint32_t getLandSetId() const; uint32_t getLandSetId() const;
uint8_t getWardNum() const;
uint8_t getLandId() const;
uint16_t getTerritoryTypeId() const;
Common::LandType getLandType() const; Common::LandType getLandType() const;
Sapphire::HousePtr getHouse() const; Sapphire::HousePtr getHouse() const;
Common::FFXIVARR_POSITION3 getMapMarkerPosition(); Common::FFXIVARR_POSITION3 getMapMarkerPosition();
Common::LandIdent getLandIdent() const;
//Free Comapny //Free Comapny
void setFreeCompany( uint32_t id, uint32_t icon, uint32_t color ); void setFreeCompany( uint32_t id, uint32_t icon, uint32_t color );
@ -69,10 +67,9 @@ namespace Sapphire
void init(); void init();
uint32_t getNextHouseId(); uint32_t getNextHouseId();
uint8_t m_wardNum; Common::LandIdent m_landIdent;
uint8_t m_landId;
uint32_t m_landSetId; uint32_t m_landSetId;
uint16_t m_territoryTypeId;
uint8_t m_size; uint8_t m_size;
uint8_t m_state; uint8_t m_state;
Common::LandType m_type; Common::LandType m_type;
@ -90,8 +87,8 @@ namespace Sapphire
//item storage //item storage
LandInventoryMap m_landInventoryMap; LandInventoryMap m_landInventoryMap;
uint32_t m_maxPlacedExternalItems; uint16_t m_maxPlacedExternalItems;
uint32_t m_maxPlacedInternalItems; uint16_t m_maxPlacedInternalItems;
//price //price
uint32_t m_initPrice; uint32_t m_initPrice;