diff --git a/src/common/Common.h b/src/common/Common.h index 29296509..9363426d 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -791,7 +791,7 @@ namespace Sapphire::Common ExteriorFence }; - enum HousingInteriorSlot + enum HouseInteriorSlot { InteriorWall, InteriorFloor, diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index ce11587c..2721bba2 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -916,7 +916,7 @@ namespace Sapphire::Entity uint32_t getNextInventorySequence(); - void send(); + bool findFirstItemWithId( uint32_t catalogId, Inventory::InventoryContainerPair& location ); uint8_t getFreeSlotsInBags(); diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index d0b9cf82..df42dc8d 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -932,4 +932,25 @@ void Sapphire::Entity::Player::insertInventoryItem( Sapphire::Common::InventoryT auto slotUpdate = std::make_shared< UpdateInventorySlotPacket >( getId(), slot, type, *item ); queuePacket( slotUpdate ); +} + +bool Sapphire::Entity::Player::findFirstItemWithId( uint32_t catalogId, + Inventory::InventoryContainerPair& location ) +{ + for( auto bagId : { Bag0, Bag1, Bag2, Bag3 } ) + { + auto& container = m_storageMap[ bagId ]; + + for( const auto& item : container->getItemMap() ) + { + if( item.second->getId() != catalogId ) + continue; + + location = std::make_pair( bagId, item.first ); + + return true; + } + } + + return false; } \ No newline at end of file diff --git a/src/world/Manager/HousingMgr.cpp b/src/world/Manager/HousingMgr.cpp index b14ac88b..1d3d079b 100644 --- a/src/world/Manager/HousingMgr.cpp +++ b/src/world/Manager/HousingMgr.cpp @@ -564,6 +564,18 @@ bool Sapphire::World::Manager::HousingMgr::initHouseModels( Entity::Player& play if( !preset ) return false; + // remove preset item + Inventory::InventoryContainerPair foundItem; + if( !player.findFirstItemWithId( presetCatalogId, foundItem ) ) + return false; + + auto item = player.dropInventoryItem( foundItem.first, foundItem.second ); + if( !item ) + return false; + + // move preset item into ext appearance container + houseInventory[ InventoryType::HousingExteriorAppearance ]->setItem( HouseExteriorSlot::HousePermit, item ); + // high iq shit auto invMap = std::map< uint16_t, std::map< uint32_t, int32_t > > { @@ -583,19 +595,19 @@ bool Sapphire::World::Manager::HousingMgr::initHouseModels( Entity::Player& play InventoryType::HousingInteriorAppearance, { // lobby/middle floor - { HousingInteriorSlot::InteriorWall, preset->interiorWall }, - { HousingInteriorSlot::InteriorFloor, preset->interiorFlooring }, - { HousingInteriorSlot::InteriorLight, preset->interiorLighting }, + { HouseInteriorSlot::InteriorWall, preset->interiorWall }, + { HouseInteriorSlot::InteriorFloor, preset->interiorFlooring }, + { HouseInteriorSlot::InteriorLight, preset->interiorLighting }, // attic - { HousingInteriorSlot::InteriorWall_Attic, preset->otherFloorWall }, - { HousingInteriorSlot::InteriorFloor_Attic, preset->otherFloorFlooring }, - { HousingInteriorSlot::InteriorLight_Attic, preset->otherFloorLighting }, + { HouseInteriorSlot::InteriorWall_Attic, preset->otherFloorWall }, + { HouseInteriorSlot::InteriorFloor_Attic, preset->otherFloorFlooring }, + { HouseInteriorSlot::InteriorLight_Attic, preset->otherFloorLighting }, // basement - { HousingInteriorSlot::InteriorWall_Basement, preset->basementWall }, - { HousingInteriorSlot::InteriorFloor_Basement, preset->basementFlooring }, - { HousingInteriorSlot::InteriorLight_Basement, preset->basementLighting }, + { HouseInteriorSlot::InteriorWall_Basement, preset->basementWall }, + { HouseInteriorSlot::InteriorFloor_Basement, preset->basementFlooring }, + { HouseInteriorSlot::InteriorLight_Basement, preset->basementLighting }, } } }; @@ -641,7 +653,7 @@ void Sapphire::World::Manager::HousingMgr::createHouse( Sapphire::HousePtr house pDb->execute( stmt ); } -void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetItem ) +void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetCatalogId ) { auto hZone = std::dynamic_pointer_cast< HousingZone >( player.getCurrentZone() ); @@ -656,8 +668,6 @@ void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& pl if( pLand->getOwnerId() != player.getId() ) return; - // todo: check if permit is in inventory and remove one - // create house auto ident = pLand->getLandIdent(); auto house = make_House( getNextHouseId(), pLand->getLandSetId(), ident, @@ -666,8 +676,11 @@ void Sapphire::World::Manager::HousingMgr::buildPresetEstate( Entity::Player& pl pLand->setHouse( house ); // create inventory items - if( !initHouseModels( player, pLand, presetItem ) ) + if( !initHouseModels( player, pLand, presetCatalogId ) ) + { + pLand->setHouse( nullptr ); return; + } createHouse( house ); @@ -913,7 +926,7 @@ void Sapphire::World::Manager::HousingMgr::updateHouseModels( Sapphire::HousePtr { for( auto& item : intContainer->second->getItemMap() ) { - house->setInteriorModel( static_cast< Common::HousingInteriorSlot >( item.first ), + house->setInteriorModel( static_cast< Common::HouseInteriorSlot >( item.first ), getItemAdditionalData( item.second->getId() ) ); } } diff --git a/src/world/Manager/HousingMgr.h b/src/world/Manager/HousingMgr.h index 9dd0bd23..4f2a6898 100644 --- a/src/world/Manager/HousingMgr.h +++ b/src/world/Manager/HousingMgr.h @@ -91,7 +91,7 @@ namespace Sapphire::World::Manager bool relinquishLand( Entity::Player& player, uint8_t plot ); - void buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetItem ); + void buildPresetEstate( Entity::Player& player, uint8_t plotNum, uint32_t presetCatalogId ); void requestEstateRename( Entity::Player& player, const Common::LandIdent ident ); diff --git a/src/world/Territory/House.cpp b/src/world/Territory/House.cpp index 396e763e..fe08783d 100644 --- a/src/world/Territory/House.cpp +++ b/src/world/Territory/House.cpp @@ -96,12 +96,12 @@ Sapphire::House::HousePart Sapphire::House::getExteriorModel( Sapphire::Common:: return m_exteriorModelCache[ slot ]; } -void Sapphire::House::setInteriorModel( Sapphire::Common::HousingInteriorSlot slot, uint32_t modelId ) +void Sapphire::House::setInteriorModel( Sapphire::Common::HouseInteriorSlot slot, uint32_t modelId ) { m_interiorModelCache[ slot ] = modelId; } -uint32_t Sapphire::House::getInteriorModel( Sapphire::Common::HousingInteriorSlot slot ) +uint32_t Sapphire::House::getInteriorModel( Sapphire::Common::HouseInteriorSlot slot ) { return m_interiorModelCache[ slot ]; } diff --git a/src/world/Territory/House.h b/src/world/Territory/House.h index 3229e0e0..21d3ea86 100644 --- a/src/world/Territory/House.h +++ b/src/world/Territory/House.h @@ -34,8 +34,8 @@ namespace Sapphire void setExteriorModel( Common::HouseExteriorSlot slot, uint32_t modelId, uint16_t stain ); HousePart getExteriorModel( Common::HouseExteriorSlot slot ); - void setInteriorModel( Common::HousingInteriorSlot slot, uint32_t modelId ); - uint32_t getInteriorModel( Common::HousingInteriorSlot slot ); + void setInteriorModel( Common::HouseInteriorSlot slot, uint32_t modelId ); + uint32_t getInteriorModel( Common::HouseInteriorSlot slot ); HouseModelsArray const& getHouseModels() const; diff --git a/src/world/Territory/Housing/HousingInteriorTerritory.cpp b/src/world/Territory/Housing/HousingInteriorTerritory.cpp index dddbd86d..1ad7b57e 100644 --- a/src/world/Territory/Housing/HousingInteriorTerritory.cpp +++ b/src/world/Territory/Housing/HousingInteriorTerritory.cpp @@ -71,7 +71,7 @@ void Sapphire::World::Territory::Housing::HousingInteriorTerritory::onPlayerZone for( auto i = 0; i < 10; i++ ) { indoorInitPacket->data().indoorItems[ i ] = pHouse->getInteriorModel( - static_cast< Common::HousingInteriorSlot >( i ) ); + static_cast< Common::HouseInteriorSlot >( i ) ); } player.queuePacket( indoorInitPacket );