1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

change itemcontainer back to use u8s for slots, some cleanup

This commit is contained in:
NotAdam 2019-01-10 22:01:58 +11:00
parent a1b4f98032
commit d3e6514af1
3 changed files with 48 additions and 48 deletions

View file

@ -9,7 +9,7 @@
#include "Forwards.h" #include "Forwards.h"
#include "ItemContainer.h" #include "ItemContainer.h"
Sapphire::ItemContainer::ItemContainer( uint16_t storageId, uint16_t maxSize, const std::string& tableName, Sapphire::ItemContainer::ItemContainer( uint16_t storageId, uint8_t maxSize, const std::string& tableName,
bool isMultiStorage, FrameworkPtr pFw, bool isPersistentStorage ) : bool isMultiStorage, FrameworkPtr pFw, bool isPersistentStorage ) :
m_id( storageId ), m_id( storageId ),
m_size( maxSize ), m_size( maxSize ),
@ -31,15 +31,15 @@ uint16_t Sapphire::ItemContainer::getId() const
return m_id; return m_id;
} }
uint16_t Sapphire::ItemContainer::getEntryCount() const uint8_t Sapphire::ItemContainer::getEntryCount() const
{ {
return static_cast< uint16_t >( m_itemMap.size() ); return static_cast< uint8_t >( m_itemMap.size() );
} }
void Sapphire::ItemContainer::removeItem( uint16_t slotId, bool removeFromDb ) void Sapphire::ItemContainer::removeItem( uint8_t slotId, bool removeFromDb )
{ {
auto pDb = m_pFw->get< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDb = m_pFw->get< Db::DbWorkerPool< Db::ZoneDbConnection > >();
ItemMap::iterator it = m_itemMap.find( slotId ); auto it = m_itemMap.find( slotId );
if( it != m_itemMap.end() ) if( it != m_itemMap.end() )
{ {
@ -66,7 +66,7 @@ const Sapphire::ItemMap& Sapphire::ItemContainer::getItemMap() const
return m_itemMap; return m_itemMap;
} }
int16_t Sapphire::ItemContainer::getFreeSlot() int8_t Sapphire::ItemContainer::getFreeSlot()
{ {
for( uint16_t slotId = 0; slotId < m_size; slotId++ ) for( uint16_t slotId = 0; slotId < m_size; slotId++ )
{ {
@ -78,7 +78,7 @@ int16_t Sapphire::ItemContainer::getFreeSlot()
return -1; return -1;
} }
Sapphire::ItemPtr Sapphire::ItemContainer::getItem( uint16_t slotId ) Sapphire::ItemPtr Sapphire::ItemContainer::getItem( uint8_t slotId )
{ {
if( ( slotId > m_size ) ) if( ( slotId > m_size ) )
@ -90,7 +90,7 @@ Sapphire::ItemPtr Sapphire::ItemContainer::getItem( uint16_t slotId )
return m_itemMap[ slotId ]; return m_itemMap[ slotId ];
} }
void Sapphire::ItemContainer::setItem( uint16_t slotId, ItemPtr pItem ) void Sapphire::ItemContainer::setItem( uint8_t slotId, ItemPtr pItem )
{ {
if( slotId > m_size ) if( slotId > m_size )
return; return;
@ -98,7 +98,7 @@ void Sapphire::ItemContainer::setItem( uint16_t slotId, ItemPtr pItem )
m_itemMap[ slotId ] = pItem; m_itemMap[ slotId ] = pItem;
} }
uint16_t Sapphire::ItemContainer::getMaxSize() const uint8_t Sapphire::ItemContainer::getMaxSize() const
{ {
return m_size; return m_size;
} }

View file

@ -8,34 +8,34 @@
namespace Sapphire namespace Sapphire
{ {
using ItemMap = std::map< uint16_t, ItemPtr >; using ItemMap = std::map< uint8_t, ItemPtr >;
class ItemContainer class ItemContainer
{ {
public: public:
ItemContainer( uint16_t storageId, uint16_t maxSize, const std::string& tableName, bool isMultiStorage, ItemContainer( uint16_t storageId, uint8_t maxSize, const std::string& tableName, bool isMultiStorage,
FrameworkPtr pFw, bool isPersistentStorage = true ); FrameworkPtr pFw, bool isPersistentStorage = true );
~ItemContainer(); ~ItemContainer();
uint16_t getId() const; uint16_t getId() const;
uint16_t getEntryCount() const; uint8_t getEntryCount() const;
void removeItem( uint16_t slotId, bool removeFromDb = true ); void removeItem( uint8_t slotId, bool removeFromDb = true );
ItemMap& getItemMap(); ItemMap& getItemMap();
const ItemMap& getItemMap() const; const ItemMap& getItemMap() const;
ItemPtr getItem( uint16_t slotId ); ItemPtr getItem( uint8_t slotId );
void setItem( uint16_t slotId, ItemPtr item ); void setItem( uint8_t slotId, ItemPtr item );
int16_t getFreeSlot(); int8_t getFreeSlot();
uint16_t getMaxSize() const; uint8_t getMaxSize() const;
std::string getTableName() const; std::string getTableName() const;
@ -45,7 +45,7 @@ namespace Sapphire
private: private:
uint16_t m_id; uint16_t m_id;
uint16_t m_size; uint8_t m_size;
std::string m_tableName; std::string m_tableName;
bool m_bMultiStorage; bool m_bMultiStorage;
FrameworkPtr m_pFw; FrameworkPtr m_pFw;

View file

@ -860,12 +860,12 @@ void Sapphire::World::Manager::HousingMgr::sendEstateInventory( Entity::Player&
return; return;
auto& containers = getEstateInventory( targetLand->getLandIdent() ); auto& containers = getEstateInventory( targetLand->getLandIdent() );
auto needle = containers.find( inventoryType ); auto it = containers.find( inventoryType );
if( needle == containers.end() ) if( it == containers.end() )
return; return;
auto invMgr = framework()->get< Manager::InventoryMgr >(); auto invMgr = framework()->get< Manager::InventoryMgr >();
invMgr->sendInventoryContainer( player, needle->second ); invMgr->sendInventoryContainer( player, it->second );
} }
const Sapphire::World::Manager::HousingMgr::LandSetLandCacheMap& const Sapphire::World::Manager::HousingMgr::LandSetLandCacheMap&
@ -1085,11 +1085,11 @@ void Sapphire::World::Manager::HousingMgr::reqPlaceItemInStore( Sapphire::Entity
{ {
for( auto houseContainer : m_internalStoreroomContainers ) for( auto houseContainer : m_internalStoreroomContainers )
{ {
auto needle = containers.find( houseContainer ); auto it = containers.find( houseContainer );
if( needle == containers.end() ) if( it == containers.end() )
continue; continue;
auto container = needle->second; auto container = it->second;
auto freeSlot = container->getFreeSlot(); auto freeSlot = container->getFreeSlot();
if( freeSlot == -1 ) if( freeSlot == -1 )
{ {
@ -1157,11 +1157,11 @@ bool Sapphire::World::Manager::HousingMgr::placeInteriorItem( Entity::Player& pl
uint8_t containerIdx = 0; uint8_t containerIdx = 0;
for( auto containerId : m_internalPlacedItemContainers ) for( auto containerId : m_internalPlacedItemContainers )
{ {
auto needle = containers.find( containerId ); auto it = containers.find( containerId );
if( needle == containers.end() ) if( it == containers.end() )
continue; continue;
auto container = needle->second; auto container = it->second;
auto freeSlot = container->getFreeSlot(); auto freeSlot = container->getFreeSlot();
if( freeSlot == -1 ) if( freeSlot == -1 )
{ {
@ -1272,11 +1272,11 @@ bool Sapphire::World::Manager::HousingMgr::moveInternalItem( Entity::Player& pla
auto& containers = getEstateInventory( ident ); auto& containers = getEstateInventory( ident );
auto needle = containers.find( containerId ); auto it = containers.find( containerId );
if( needle == containers.end() ) if( it == containers.end() )
return false; return false;
auto container = needle->second; auto container = it->second;
auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slotIdx ) ); auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slotIdx ) );
if( !item ) if( !item )
@ -1310,11 +1310,11 @@ bool Sapphire::World::Manager::HousingMgr::moveExternalItem( Entity::Player& pla
return false; return false;
auto& containers = getEstateInventory( ident ); auto& containers = getEstateInventory( ident );
auto needle = containers.find( InventoryType::HousingExteriorPlacedItems ); auto it = containers.find( InventoryType::HousingExteriorPlacedItems );
if( needle == containers.end() ) if( it == containers.end() )
return false; return false;
auto container = needle->second; auto container = it->second;
auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slot ) ); auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slot ) );
if( !item ) if( !item )
@ -1394,11 +1394,11 @@ bool Sapphire::World::Manager::HousingMgr::removeInternalItem( Entity::Player& p
// eg, remove a permit and reuse it elsewhere // eg, remove a permit and reuse it elsewhere
// I'm not going to bother fixing it for now, but worth noting for future reference // I'm not going to bother fixing it for now, but worth noting for future reference
auto needle = containers.find( containerId ); auto it = containers.find( containerId );
if( needle == containers.end() ) if( it == containers.end() )
return false; return false;
auto container = needle->second; auto container = it->second;
auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slotId ) ); auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( container->getItem( slotId ) );
if( !item ) if( !item )
@ -1461,11 +1461,11 @@ bool Sapphire::World::Manager::HousingMgr::removeExternalItem( Entity::Player& p
{ {
auto& containers = getEstateInventory( land.getLandIdent() ); auto& containers = getEstateInventory( land.getLandIdent() );
auto needle = containers.find( containerType ); auto it = containers.find( containerType );
if( needle == containers.end() ) if( it == containers.end() )
return false; return false;
auto& sourceContainer = needle->second; auto& sourceContainer = it->second;
auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( sourceContainer->getItem( slotId ) ); auto item = std::dynamic_pointer_cast< Inventory::HousingItem >( sourceContainer->getItem( slotId ) );
if( !item ) if( !item )
@ -1522,11 +1522,11 @@ Sapphire::ItemContainerPtr Sapphire::World::Manager::HousingMgr::getFreeEstateIn
for( auto bag : bagList ) for( auto bag : bagList )
{ {
auto needle = estateContainers.find( bag ); auto it = estateContainers.find( bag );
if( needle == estateContainers.end() ) if( it == estateContainers.end() )
continue; continue;
auto container = needle->second; auto container = it->second;
auto freeSlot = container->getFreeSlot(); auto freeSlot = container->getFreeSlot();
@ -1554,13 +1554,13 @@ void Sapphire::World::Manager::HousingMgr::reqEstateExteriorRemodel( Sapphire::E
return; return;
auto& inv = getEstateInventory( land->getLandIdent() ); auto& inv = getEstateInventory( land->getLandIdent() );
auto needle = inv.find( InventoryType::HousingExteriorAppearance ); auto it = inv.find( InventoryType::HousingExteriorAppearance );
if( needle == inv.end() ) if( it == inv.end() )
return; return;
auto invMgr = framework()->get< InventoryMgr >(); auto invMgr = framework()->get< InventoryMgr >();
invMgr->sendInventoryContainer( player, needle->second ); invMgr->sendInventoryContainer( player, it->second );
auto pkt = Server::makeActorControl143( player.getId(), Network::ActorControl::ShowEstateExternalAppearanceUI, plot ); auto pkt = Server::makeActorControl143( player.getId(), Network::ActorControl::ShowEstateExternalAppearanceUI, plot );
player.queuePacket( pkt ); player.queuePacket( pkt );
@ -1584,13 +1584,13 @@ void Sapphire::World::Manager::HousingMgr::reqEstateInteriorRemodel( Sapphire::E
return; return;
auto& inv = getEstateInventory( land->getLandIdent() ); auto& inv = getEstateInventory( land->getLandIdent() );
auto needle = inv.find( InventoryType::HousingInteriorAppearance ); auto it = inv.find( InventoryType::HousingInteriorAppearance );
if( needle == inv.end() ) if( it == inv.end() )
return; return;
auto invMgr = framework()->get< InventoryMgr >(); auto invMgr = framework()->get< InventoryMgr >();
invMgr->sendInventoryContainer( player, needle->second ); invMgr->sendInventoryContainer( player, it->second );
auto pkt = Server::makeActorControl143( player.getId(), Network::ActorControl::ShowEstateInternalAppearanceUI ); auto pkt = Server::makeActorControl143( player.getId(), Network::ActorControl::ShowEstateInternalAppearanceUI );
player.queuePacket( pkt ); player.queuePacket( pkt );