From e52127fd91af291afd5775c62bf3d0df074c4f39 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sat, 22 Dec 2018 15:58:54 +1100 Subject: [PATCH] load housing invs correctly --- src/world/Manager/HousingMgr.cpp | 48 +++++++++++++++- src/world/Territory/House.cpp | 24 ++++---- src/world/Territory/House.h | 8 +-- src/world/Territory/HousingZone.cpp | 28 +++++----- src/world/Territory/Land.cpp | 86 ++++++----------------------- src/world/Territory/Land.h | 4 -- 6 files changed, 93 insertions(+), 105 deletions(-) diff --git a/src/world/Manager/HousingMgr.cpp b/src/world/Manager/HousingMgr.cpp index 8d7c0b92..a4bc4a1b 100644 --- a/src/world/Manager/HousingMgr.cpp +++ b/src/world/Manager/HousingMgr.cpp @@ -25,6 +25,8 @@ #include "ServerMgr.h" #include "Territory/House.h" #include "InventoryMgr.h" +#include "Inventory/Item.h" +#include "Inventory/ItemContainer.h" using namespace Sapphire::Common; using namespace Sapphire::Network; @@ -48,7 +50,7 @@ bool Sapphire::World::Manager::HousingMgr::init() loadLandCache(); - log->info( "HousingMgr: Checking land counts" ); + log->debug( "HousingMgr: Checking land counts" ); uint32_t houseCount = 0; for( auto& landSet : m_landCache ) @@ -80,6 +82,48 @@ bool Sapphire::World::Manager::HousingMgr::loadEstateInventories() log->info( "HousingMgr: Loading inventories for estates" ); + auto pDb = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); + + auto stmt = pDb->getPreparedStatement( Db::LAND_INV_SEL_ALL ); + auto res = pDb->query( stmt ); + + uint32_t itemCount = 0; + while( res->next() ) + { + //uint64_t uId, uint32_t catalogId, uint64_t model1, uint64_t model2, bool isHq + uint64_t ident = res->getUInt64( "LandIdent" ); + uint16_t containerId = res->getUInt16( "ContainerId" ); + uint64_t itemId = res->getUInt64( "ItemId" ); + uint16_t slot = res->getUInt16( "SlotId" ); + uint32_t catalogId = res->getUInt( "catalogId" ); + uint8_t stain = res->getUInt8( "stain" ); + uint64_t characterId = res->getUInt64( "CharacterId" ); + + auto item = make_Item( itemId, catalogId, 0, 0, 0 ); + item->setStain( stain ); + // todo: need to set the owner character id on the item + + ContainerIdToContainerMap estateInv = m_estateInventories[ ident ]; + + // check if containerId exists + auto container = estateInv.find( containerId ); + if( container == estateInv.end() ) + { + // create container + // todo: how to handle this max slot stuff? override it on land init? + auto ic = make_ItemContainer( containerId, 400, "houseiteminventory", true ); + ic->setItem( slot, item ); + + estateInv[ containerId ] = ic; + } + else + container->second->setItem( slot, item ); + + itemCount++; + } + + log->debug( "HousingMgr: Loaded " + std::to_string( itemCount ) + " inventory items" ); + return true; } @@ -580,7 +624,7 @@ void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player& if( targetLand->getOwnerId() != player.getId() ) return; - auto container = targetLand->getItemContainer( inventoryType ); + auto container = getEstateInventory( targetLand->getLandIdent() )[ inventoryType ]; if( !container ) return; diff --git a/src/world/Territory/House.cpp b/src/world/Territory/House.cpp index 9979e501..b4be2e63 100644 --- a/src/world/Territory/House.cpp +++ b/src/world/Territory/House.cpp @@ -51,7 +51,7 @@ Sapphire::House::House( uint32_t houseId, uint32_t landSetId, Common::LandIdent // auto models = reinterpret_cast< uint32_t* >( &housePartModels[ 0 ] ); // for( auto i = 0; i < 8; i++ ) // { -// m_houseParts[ i ] = { models[ i ], housePartColours[ i ] }; +// m_houseModelsCache[ i ] = { models[ i ], housePartColours[ i ] }; // } // // auto houseInteriorModels = res->getBlobVector( "HouseInteriorModels" ); @@ -59,7 +59,7 @@ Sapphire::House::House( uint32_t houseId, uint32_t landSetId, Common::LandIdent // auto interiorModels = reinterpret_cast< uint32_t* >( &houseInteriorModels[ 0 ] ); // for( auto i = 0; i < 10; i++ ) // { -// m_houseInteriorParts[ i ] = interiorModels[ i ]; +// m_houseInteriorModels[ i ] = interiorModels[ i ]; // } // } } @@ -88,7 +88,7 @@ void Sapphire::House::updateHouseDb() for( auto i = 0; i < 8; i++ ) { - auto& part = m_houseParts[ i ]; + auto& part = m_houseModelsCache[ i ]; models.push_back( part.first ); colours.push_back( part.second ); } @@ -104,7 +104,7 @@ void Sapphire::House::updateHouseDb() for( auto i = 0; i < 10; i++ ) { - models.push_back( m_houseInteriorParts[ i ] ); + models.push_back( m_houseInteriorModels[ i ] ); } std::vector< uint8_t > tmp2Models( models.size() * 4 ); @@ -132,37 +132,37 @@ uint32_t Sapphire::House::getHouseId() const uint8_t Sapphire::House::getHousePartColor( Common::HousePartSlot slot ) const { - return m_houseParts[ slot ].second; + return m_houseModelsCache[ slot ].second; } uint32_t Sapphire::House::getHouseInteriorPart( Common::HousingInteriorSlot slot ) const { - return m_houseInteriorParts[ slot ]; + return m_houseInteriorModels[ slot ]; } void Sapphire::House::setHousePart( Common::HousePartSlot slot, uint32_t id ) { - m_houseParts[ slot ].first = id; + m_houseModelsCache[ slot ].first = id; } void Sapphire::House::setHousePartColor( Common::HousePartSlot slot, uint32_t id ) { - m_houseParts[ slot ].second = id; + m_houseModelsCache[ slot ].second = id; } void Sapphire::House::setHouseInteriorPart( Common::HousingInteriorSlot slot, uint32_t id ) { - m_houseInteriorParts[ slot ] = id; + m_houseInteriorModels[ slot ] = id; } uint32_t Sapphire::House::getHousePart( Common::HousePartSlot slot ) const { - return m_houseParts[ slot ].first; + return m_houseModelsCache[ slot ].first; } -Sapphire::House::HousePartsArray const& Sapphire::House::getHouseParts() const +Sapphire::House::HouseModelsArray const& Sapphire::House::getHouseModels() const { - return m_houseParts; + return m_houseModelsCache; } const std::string& Sapphire::House::getHouseName() const diff --git a/src/world/Territory/House.h b/src/world/Territory/House.h index 22726633..f4c71817 100644 --- a/src/world/Territory/House.h +++ b/src/world/Territory/House.h @@ -17,7 +17,7 @@ namespace Sapphire virtual ~House(); using HousePart = std::pair< uint32_t, uint8_t >; - using HousePartsArray = std::array< HousePart, 8 >; + using HouseModelsArray = std::array< HousePart, 8 >; //gerneral uint32_t getLandSetId() const; @@ -38,7 +38,7 @@ namespace Sapphire uint8_t getHousePartColor( Common::HousePartSlot slot ) const; uint32_t getHouseInteriorPart( Common::HousingInteriorSlot slot ) const; - HousePartsArray const& getHouseParts() const; + HouseModelsArray const& getHouseModels() const; void updateHouseDb(); @@ -49,8 +49,8 @@ namespace Sapphire uint64_t m_buildTime; - HousePartsArray m_houseParts; - uint32_t m_houseInteriorParts[10]; + HouseModelsArray m_houseModelsCache; + uint32_t m_houseInteriorModels[10]; std::string m_estateComment; std::string m_estateName; diff --git a/src/world/Territory/HousingZone.cpp b/src/world/Territory/HousingZone.cpp index ec485c72..292344b4 100644 --- a/src/world/Territory/HousingZone.cpp +++ b/src/world/Territory/HousingZone.cpp @@ -83,9 +83,9 @@ bool Sapphire::HousingZone::init() // setup house if( entry.m_houseId ) { - //uint32_t houseId, uint32_t landSetId, Common::LandIdent ident, const std::string& estateName, - // const std::string& estateMessage auto house = make_House( entry.m_houseId, m_landSetId, land->getLandIdent(), entry.m_estateName, entry.m_estateComment ); + + land->setHouse( house ); } land->init( entry.m_type, entry.m_size, entry.m_status, entry.m_currentPrice, entry.m_ownerId, entry.m_houseId ); @@ -115,20 +115,20 @@ void Sapphire::HousingZone::onPlayerZoneIn( Entity::Player& player ) for( yardPacketNum = 0; yardPacketNum < yardPacketTotal; yardPacketNum++ ) { - auto housingObjectInitializPacket = makeZonePacket< FFXIVIpcHousingObjectInitialize >( player.getId() ); - memset( &housingObjectInitializPacket->data().landIdent, 0xFF, sizeof( Common::LandIdent ) ); - housingObjectInitializPacket->data().u1 = 0xFF; - housingObjectInitializPacket->data().packetNum = yardPacketNum; - housingObjectInitializPacket->data().packetTotal = yardPacketTotal; + auto housingObjectInit = makeZonePacket< FFXIVIpcHousingObjectInitialize >( player.getId() ); + memset( &housingObjectInit->data().landIdent, 0xFF, sizeof( Common::LandIdent ) ); + housingObjectInit->data().u1 = 0xFF; + housingObjectInit->data().packetNum = yardPacketNum; + housingObjectInit->data().packetTotal = yardPacketTotal; //TODO: Add Objects here - player.queuePacket( housingObjectInitializPacket ); + player.queuePacket( housingObjectInit ); } auto landSetMap = makeZonePacket< FFXIVIpcLandSetMap >( player.getId() ); - landSetMap->data().subdivision = isPlayerSubInstance( player ) == false ? 2 : 1; - uint8_t startIndex = isPlayerSubInstance( player ) == false ? 0 : 30; + landSetMap->data().subdivision = !isPlayerSubInstance( player ) ? 2 : 1; + uint8_t startIndex = !isPlayerSubInstance( player ) ? 0 : 30; for( uint8_t i = startIndex, count = 0; i < ( startIndex + 30 ); i++, count++ ) { landSetMap->data().landInfo[ count ].status = 1; @@ -147,9 +147,9 @@ void Sapphire::HousingZone::sendLandSet( Entity::Player& player ) landsetInitializePacket->data().landIdent.territoryTypeId = m_territoryTypeId; //TODO: get current WorldId landsetInitializePacket->data().landIdent.worldId = 67; - landsetInitializePacket->data().subInstance = isPlayerSubInstance( player ) == false ? 1 : 2; + landsetInitializePacket->data().subInstance = !isPlayerSubInstance( player ) ? 1 : 2; - uint8_t startIndex = isPlayerSubInstance( player ) == false ? 0 : 30; + uint8_t startIndex = !isPlayerSubInstance( player ) ? 0 : 30; for( uint8_t i = startIndex, count = 0; i < ( startIndex + 30 ); ++i, ++count ) { @@ -169,7 +169,7 @@ void Sapphire::HousingZone::sendLandSet( Entity::Player& player ) { landData.flags = 1; - auto& parts = house->getHouseParts(); + auto& parts = house->getHouseModels(); for( auto i = 0; i != parts.size(); i++ ) { @@ -206,7 +206,7 @@ void Sapphire::HousingZone::sendLandUpdate( uint8_t landId ) { landData.flags = 1; - auto& parts = house->getHouseParts(); + auto& parts = house->getHouseModels(); for( auto i = 0; i != parts.size(); i++ ) { diff --git a/src/world/Territory/Land.cpp b/src/world/Territory/Land.cpp index 019165a2..4a1d075a 100644 --- a/src/world/Territory/Land.cpp +++ b/src/world/Territory/Land.cpp @@ -90,66 +90,23 @@ void Sapphire::Land::init( Common::LandType type, uint8_t size, uint8_t state, u } // init item containers - auto setupContainer = [ this ]( InventoryType type, uint16_t maxSize ) - { - m_landInventoryMap[ type ] = make_ItemContainer( type, maxSize, "houseiteminventory", true, true ); - }; - - setupContainer( InventoryType::HousingOutdoorAppearance, 8 ); - setupContainer( InventoryType::HousingOutdoorPlacedItems, m_maxPlacedExternalItems ); - 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 ); - - loadItemContainerContents(); -} - -void Sapphire::Land::loadItemContainerContents() -{ - if( !m_pHouse ) - return; - - auto ident = *reinterpret_cast< uint64_t* >( &m_landIdent ); - g_fw.get< Sapphire::Logger >()->debug( "Loading housing inventory for ident: " + std::to_string( ident ) ); - - auto pDB = g_fw.get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); - - auto stmt = pDB->getPreparedStatement( Db::LAND_INV_SEL_HOUSE ); - stmt->setUInt64( 1, ident ); - - auto res = pDB->query( stmt ); - - std::unordered_map< uint16_t, std::vector< std::pair< uint16_t, uint32_t > > > items; - - while( res->next() ) - { - auto containerId = res->getUInt( "ContainerId" ); - auto itemId = res->getUInt64( "ItemId" ); - auto slotId = res->getUInt( "SlotId" ); - - items[ containerId ].push_back( std::make_pair( slotId, itemId ) ); - } - - // fuck the query off - res.reset(); - - for( auto it = items.begin(); it != items.end(); it++ ) - { - auto container = m_landInventoryMap[ it->first ]; - - // todo: delet this - for( auto fuck = it->second.begin(); fuck != it->second.end(); fuck++ ) - { - auto item = Sapphire::Items::Util::loadItem( fuck->second ); - if( item ) - container->setItem( fuck->first, item ); - } - } +// auto setupContainer = [ this ]( InventoryType type, uint16_t maxSize ) +// { +// m_landInventoryMap[ type ] = make_ItemContainer( type, maxSize, "houseiteminventory", true, true ); +// }; +// +// setupContainer( InventoryType::HousingOutdoorAppearance, 8 ); +// setupContainer( InventoryType::HousingOutdoorPlacedItems, m_maxPlacedExternalItems ); +// 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 ); +// +// loadItemContainerContents(); } uint32_t Sapphire::Land::convertItemIdToHousingItemId( uint32_t itemId ) @@ -374,13 +331,4 @@ bool Sapphire::Land::setPreset( uint32_t itemId ) return true; -} - -Sapphire::ItemContainerPtr Sapphire::Land::getItemContainer( uint16_t inventoryType ) const -{ - auto container = m_landInventoryMap.find( inventoryType ); - if( container == m_landInventoryMap.end() ) - return nullptr; - - return container->second; } \ No newline at end of file diff --git a/src/world/Territory/Land.h b/src/world/Territory/Land.h index c47bf3bb..19977e77 100644 --- a/src/world/Territory/Land.h +++ b/src/world/Territory/Land.h @@ -61,9 +61,6 @@ namespace Sapphire void setLandTag( uint8_t slot, uint8_t tag ); uint8_t getLandTag( uint8_t slot ); - ItemContainerPtr getItemContainer( uint16_t inventoryType ) const; - void loadItemContainerContents(); - private: uint32_t convertItemIdToHousingItemId( uint32_t itemId ); uint32_t getNextHouseId(); @@ -87,7 +84,6 @@ namespace Sapphire Sapphire::HousePtr m_pHouse; //item storage - LandInventoryMap m_landInventoryMap; uint16_t m_maxPlacedExternalItems; uint16_t m_maxPlacedInternalItems;