diff --git a/src/common/Database/ZoneDbConnection.cpp b/src/common/Database/ZoneDbConnection.cpp index 25b8e037..c6902bf4 100644 --- a/src/common/Database/ZoneDbConnection.cpp +++ b/src/common/Database/ZoneDbConnection.cpp @@ -200,6 +200,14 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() "UPDATE house SET BuildTime = ?, Aetheryte = ?, Comment = ?, HouseName = ?, Endorsements = ?, HousePartModels = ?, HousePartColours = ?, HouseInteriorModels = ? WHERE HouseId = ?;", 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, "INSERT INTO land ( LandSetId ) VALUES ( ? );", CONNECTION_BOTH ); diff --git a/src/common/Database/ZoneDbConnection.h b/src/common/Database/ZoneDbConnection.h index df8dfdf1..6f404167 100644 --- a/src/common/Database/ZoneDbConnection.h +++ b/src/common/Database/ZoneDbConnection.h @@ -85,6 +85,11 @@ namespace Sapphire::Db HOUSING_HOUSE_UP, HOUSING_HOUSE_DEL, + LAND_INV_SEL_ALL, + LAND_INV_SEL_HOUSE, + LAND_INV_DEL, + LAND_INV_UP, + MAX_STATEMENTS }; diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index ead5d2d4..8b94b238 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -1618,7 +1618,8 @@ void Sapphire::Entity::Player::sendZonePackets() 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(); diff --git a/src/world/Manager/HousingMgr.cpp b/src/world/Manager/HousingMgr.cpp index 539bd634..02efb7de 100644 --- a/src/world/Manager/HousingMgr.cpp +++ b/src/world/Manager/HousingMgr.cpp @@ -222,7 +222,7 @@ bool Sapphire::World::Manager::HousingMgr::relinquishLand( Entity::Player& playe player.sendLandFlagsSlot( LandFlagsSlot::Private ); auto screenMsgPkt2 = makeActorControl143( player.getId(), ActorControl::LogMsg, 3351, 0x1AA, - pLand->getWardNum() + 1, plot + 1 ); + pLand->getLandIdent().wardNum + 1, plot + 1 ); player.queuePacket( screenMsgPkt2 ); 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.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 ); hZone->registerHouseEntranceEObj( plotNum ); diff --git a/src/world/Territory/House.cpp b/src/world/Territory/House.cpp index d5b20ef2..820a7b1e 100644 --- a/src/world/Territory/House.cpp +++ b/src/world/Territory/House.cpp @@ -13,12 +13,10 @@ 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_landSetId( landSetId ), - m_landId( landId ), - m_wardNum( wardNum ), - m_territoryTypeId( territoryTypeId ) + m_landIdent( ident ) { 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 ); // todo: make this nicer/configurable? - m_houseName = "Estate #" + std::to_string( landId + 1 ); + m_houseName = "Estate #" + std::to_string( m_landIdent.landId + 1 ); } else { @@ -121,19 +119,9 @@ uint32_t Sapphire::House::getLandSetId() const return m_landSetId; } -uint8_t Sapphire::House::getLandId() const +Sapphire::Common::LandIdent Sapphire::House::getLandIdent() const { - return m_landId; -} - -uint8_t Sapphire::House::getWardNum() const -{ - return m_wardNum; -} - -uint16_t Sapphire::House::getTerritoryTypeId() const -{ - return m_territoryTypeId; + return m_landIdent; } uint32_t Sapphire::House::getHouseId() const diff --git a/src/world/Territory/House.h b/src/world/Territory/House.h index 183afd1f..f228874b 100644 --- a/src/world/Territory/House.h +++ b/src/world/Territory/House.h @@ -12,7 +12,7 @@ namespace Sapphire class House { 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(); using HousePart = std::pair< uint32_t, uint8_t >; @@ -20,9 +20,7 @@ namespace Sapphire //gerneral uint32_t getLandSetId() const; - uint8_t getLandId() const; - uint8_t getWardNum() const; - uint16_t getTerritoryTypeId() const; + Common::LandIdent getLandIdent() const; uint32_t getHouseId() const; const std::string& getHouseName() const; @@ -45,9 +43,7 @@ namespace Sapphire private: uint32_t m_landSetId; - uint8_t m_landId; - uint8_t m_wardNum; - uint16_t m_territoryTypeId; + Common::LandIdent m_landIdent; uint32_t m_houseId; uint64_t m_buildTime; diff --git a/src/world/Territory/Land.cpp b/src/world/Territory/Land.cpp index 20035793..cb43cad7 100644 --- a/src/world/Territory/Land.cpp +++ b/src/world/Territory/Land.cpp @@ -28,9 +28,6 @@ using namespace Sapphire::Common; Sapphire::Land::Land( uint16_t territoryTypeId, uint8_t wardNum, uint8_t landId, uint32_t landSetId, Sapphire::Data::HousingLandSetPtr info ) : - m_territoryTypeId( territoryTypeId ), - m_wardNum( wardNum ), - m_landId( landId ), m_currentPrice( 0 ), m_minPrice( 0 ), 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 ); + m_landIdent.landId = landId; + m_landIdent.territoryTypeId = territoryTypeId; + m_landIdent.wardNum = wardNum; + m_landIdent.worldId = 67; // todo: fix this + init(); } -Sapphire::Land::~Land() -{ - -} +Sapphire::Land::~Land() = default; 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 res = pDb->query( "SELECT * FROM land WHERE LandSetId = " + std::to_string( m_landSetId ) + " " - "AND LandId = " + std::to_string( m_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 );" ); + "AND LandId = " + std::to_string( m_landIdent.landId ) ); - m_currentPrice = m_landInfo->initialPrice[ m_landId ]; - m_minPrice = m_landInfo->minPrice[ m_landId ]; - 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 ]; + // we're not going to be building the land table at runtime + assert( res->next() ); - 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 - if( houseId > 0 ) - m_pHouse = make_House( houseId, m_landSetId, m_landId, m_wardNum, m_territoryTypeId ); + 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, getLandIdent() ); 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 ) { m_mapMarkerPosition.x = info->x; @@ -127,11 +114,17 @@ void Sapphire::Land::init() setupContainer( InventoryType::HousingOutdoorStoreroom, m_maxPlacedExternalItems ); 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() { + } uint32_t Sapphire::Land::convertItemIdToHousingItemId( uint32_t itemId ) @@ -192,19 +185,9 @@ uint32_t Sapphire::Land::getLandSetId() const return m_landSetId; } -uint8_t Sapphire::Land::getWardNum() const +Sapphire::Common::LandIdent Sapphire::Land::getLandIdent() const { - return m_wardNum; -} - -uint8_t Sapphire::Land::getLandId() const -{ - return m_landId; -} - -uint16_t Sapphire::Land::getTerritoryTypeId() const -{ - return m_territoryTypeId; + return m_landIdent; } Sapphire::HousePtr Sapphire::Land::getHouse() const @@ -292,7 +275,7 @@ void Sapphire::Land::updateLandDb() + ", 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 ) + ";" ); + + " AND LandId = " + std::to_string( m_landIdent.landId ) + ";" ); if( auto house = getHouse() ) house->updateHouseDb(); @@ -338,7 +321,7 @@ bool Sapphire::Land::setPreset( uint32_t itemId ) { // todo: i guess we'd create a house here? auto newId = getNextHouseId(); - m_pHouse = make_House( newId, getLandSetId(), getLandId(), getWardNum(), getTerritoryTypeId() ); + m_pHouse = make_House( newId, getLandSetId(), getLandIdent() ); } diff --git a/src/world/Territory/Land.h b/src/world/Territory/Land.h index a7b73192..3e5b7ae0 100644 --- a/src/world/Territory/Land.h +++ b/src/world/Territory/Land.h @@ -31,12 +31,10 @@ namespace Sapphire uint8_t getState() const; uint8_t getSharing() const; uint32_t getLandSetId() const; - uint8_t getWardNum() const; - uint8_t getLandId() const; - uint16_t getTerritoryTypeId() const; Common::LandType getLandType() const; Sapphire::HousePtr getHouse() const; Common::FFXIVARR_POSITION3 getMapMarkerPosition(); + Common::LandIdent getLandIdent() const; //Free Comapny void setFreeCompany( uint32_t id, uint32_t icon, uint32_t color ); @@ -69,10 +67,9 @@ namespace Sapphire void init(); uint32_t getNextHouseId(); - uint8_t m_wardNum; - uint8_t m_landId; + Common::LandIdent m_landIdent; + uint32_t m_landSetId; - uint16_t m_territoryTypeId; uint8_t m_size; uint8_t m_state; Common::LandType m_type; @@ -90,8 +87,8 @@ namespace Sapphire //item storage LandInventoryMap m_landInventoryMap; - uint32_t m_maxPlacedExternalItems; - uint32_t m_maxPlacedInternalItems; + uint16_t m_maxPlacedExternalItems; + uint16_t m_maxPlacedInternalItems; //price uint32_t m_initPrice;