diff --git a/src/servers/sapphire_zone/Actor/PlayerInventory.cpp b/src/servers/sapphire_zone/Actor/PlayerInventory.cpp index 90a7fbef..23220637 100644 --- a/src/servers/sapphire_zone/Actor/PlayerInventory.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerInventory.cpp @@ -6,6 +6,7 @@ #include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket143.h" +#include "Network/PacketWrappers/UpdateInventorySlotPacket.h" #include "Inventory/Item.h" #include "Inventory/ItemContainer.h" @@ -232,13 +233,11 @@ void Core::Entity::Player::addCurrency( CurrencyType type, uint32_t amount ) currItem->setStackSize( currentAmount + amount ); updateItemDb( currItem ); - auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); - invUpPacket->data().containerId = Common::InventoryType::Currency; - invUpPacket->data().catalogId = 1; - invUpPacket->data().quantity = getCurrency( type ); - invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; - - queuePacket( invUpPacket ); + auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(), + static_cast< uint8_t >( type ) - 1, + Common::InventoryType::Currency, + *currItem ); + queuePacket( invUpdate ); } void Core::Entity::Player::removeCurrency( Common::CurrencyType type, uint32_t amount ) @@ -254,15 +253,13 @@ void Core::Entity::Player::removeCurrency( Common::CurrencyType type, uint32_t a currItem->setStackSize( 0 ); else currItem->setStackSize( currentAmount - amount ); - updateItemDb( currItem ); - auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); - invUpPacket->data().containerId = Common::InventoryType::Currency; - invUpPacket->data().catalogId = 1; - invUpPacket->data().quantity = getCurrency( type ); - invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; - queuePacket( invUpPacket ); + auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(), + static_cast< uint8_t >( type ) - 1, + Common::InventoryType::Currency, + *currItem ); + queuePacket( invUpdate ); } @@ -284,14 +281,12 @@ void Core::Entity::Player::addCrystal( Common::CrystalType type, uint32_t amount updateItemDb( currItem ); - auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); - invUpPacket->data().containerId = Common::InventoryType::Crystal; - invUpPacket->data().catalogId = static_cast< uint8_t >( type ) + 1; - invUpPacket->data().quantity = getCrystal( type ); - invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; - - queuePacket( invUpPacket ); + auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(), + static_cast< uint8_t >( type ) - 1, + Common::InventoryType::Crystal, + *currItem ); + queuePacket( invUpdate ); queuePacket( boost::make_shared< ActorControlPacket143 >( getId(), ItemObtainIcon, static_cast< uint8_t >( type ) + 1, amount ) ); } @@ -311,13 +306,11 @@ void Core::Entity::Player::removeCrystal( Common::CrystalType type, uint32_t amo updateItemDb( currItem ); - auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); - invUpPacket->data().containerId = Common::InventoryType::Crystal; - invUpPacket->data().catalogId = static_cast< uint8_t >( type ) + 1; - invUpPacket->data().quantity = getCrystal( type ); - invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; - - queuePacket( invUpPacket ); + auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(), + static_cast< uint8_t >( type ) - 1, + Common::InventoryType::Crystal, + *currItem ); + queuePacket( invUpdate ); } bool Core::Entity::Player::tryAddItem( uint16_t catalogId, uint32_t quantity ) @@ -609,14 +602,11 @@ int16_t Core::Entity::Player::addItem( uint16_t inventoryId, int8_t slotId, uint " AND CharacterId = " + std::to_string( getId() ) ); - auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); - invUpPacket->data().containerId = inventoryId; - invUpPacket->data().catalogId = catalogId; - invUpPacket->data().quantity = item->getStackSize(); - invUpPacket->data().hqFlag = item->isHq() ? 1 : 0; - invUpPacket->data().slot = rSlotId; - invUpPacket->data().condition = 30000; - queuePacket( invUpPacket ); + auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(), + rSlotId, + inventoryId, + *item ); + queuePacket( invUpdate ); if( !silent ) queuePacket( boost::make_shared< ActorControlPacket143 >( getId(), ItemObtainIcon, @@ -851,10 +841,10 @@ uint16_t Core::Entity::Player::calculateEquippedGearItemLevel() uint8_t Core::Entity::Player::getFreeSlotsInBags() { uint8_t slots = 0; - for( uint8_t container : { 0, 1, 2, 3 } ) - { - // TODO: this feels hackish at best - slots += 34 - m_inventoryMap[container]->getEntryCount(); + for( uint8_t container : { Bag0, Bag1, Bag2, Bag3 } ) + { + const auto& storage = m_inventoryMap[container]; + slots += ( storage->getMaxSize() - storage->getEntryCount() ); } return slots; } diff --git a/src/servers/sapphire_zone/Inventory/ItemContainer.cpp b/src/servers/sapphire_zone/Inventory/ItemContainer.cpp index 330c77f7..e9a4d28d 100644 --- a/src/servers/sapphire_zone/Inventory/ItemContainer.cpp +++ b/src/servers/sapphire_zone/Inventory/ItemContainer.cpp @@ -55,12 +55,12 @@ void Core::ItemContainer::removeItem( uint8_t slotId ) } } -Core::ItemMap & Core::ItemContainer::getItemMap() +Core::ItemMap& Core::ItemContainer::getItemMap() { return m_itemMap; } -const Core::ItemMap & Core::ItemContainer::getItemMap() const +const Core::ItemMap& Core::ItemContainer::getItemMap() const { return m_itemMap; } diff --git a/src/servers/sapphire_zone/Network/PacketWrappers/UpdateInventorySlotPacket.h b/src/servers/sapphire_zone/Network/PacketWrappers/UpdateInventorySlotPacket.h new file mode 100644 index 00000000..00a9e31a --- /dev/null +++ b/src/servers/sapphire_zone/Network/PacketWrappers/UpdateInventorySlotPacket.h @@ -0,0 +1,60 @@ +#ifndef _INVENTORY_SLOT_UPDATE_PACKET_H +#define _INVENTORY_SLOT_UPDATE_PACKET_H + +#include +#include "Actor/Player.h" +#include "Inventory/Item.h" +#include "Forwards.h" + +namespace Core { +namespace Network { +namespace Packets { +namespace Server { + +/** +* @brief The update inventory-slot packet. +*/ +class UpdateInventorySlotPacket : + public ZoneChannelPacket< FFXIVIpcUpdateInventorySlot > +{ +public: + UpdateInventorySlotPacket( uint32_t playerId, uint8_t slot, uint16_t storageId, const Item& item ) : + ZoneChannelPacket< FFXIVIpcUpdateInventorySlot >( playerId, playerId ) + { + initialize( slot, storageId, item ); + }; + +private: + void initialize( uint8_t slot, uint16_t storageId, const Item& item ) + { + m_data.sequence = 0; + m_data.containerId = storageId; + m_data.slot = slot; + m_data.quantity = item.getStackSize(); + m_data.catalogId = item.getId(); + m_data.reservedFlag = 0; // no idea + m_data.signatureId = 0; + m_data.hqFlag = item.isHq() ? 1 : 0; + m_data.condition = 60000; // 200% + m_data.spiritBond = 0; + m_data.color = 0; + m_data.glamourCatalogId = 0; + m_data.materia1 = 0; + m_data.materia2 = 0; + m_data.materia3 = 0; + m_data.materia4 = 0; + m_data.materia5 = 0; + //m_data.buffer1; + //uint8_t buffer2; + //uint8_t buffer3; + //uint8_t buffer4; + //uint8_t buffer5; + }; +}; + +} +} +} +} + +#endif /*_MODELEQUIPPACKET_H*/