1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-24 13:47:46 +00:00

Inventory code cleanup number 2, packetWrapper for slot update

This commit is contained in:
Mordred Admin 2018-07-26 14:09:09 +02:00
parent 62494b4b9a
commit cdb30f1f9c
3 changed files with 92 additions and 42 deletions

View file

@ -6,6 +6,7 @@
#include "Network/PacketWrappers/ActorControlPacket142.h" #include "Network/PacketWrappers/ActorControlPacket142.h"
#include "Network/PacketWrappers/ActorControlPacket143.h" #include "Network/PacketWrappers/ActorControlPacket143.h"
#include "Network/PacketWrappers/UpdateInventorySlotPacket.h"
#include "Inventory/Item.h" #include "Inventory/Item.h"
#include "Inventory/ItemContainer.h" #include "Inventory/ItemContainer.h"
@ -232,13 +233,11 @@ void Core::Entity::Player::addCurrency( CurrencyType type, uint32_t amount )
currItem->setStackSize( currentAmount + amount ); currItem->setStackSize( currentAmount + amount );
updateItemDb( currItem ); updateItemDb( currItem );
auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
invUpPacket->data().containerId = Common::InventoryType::Currency; static_cast< uint8_t >( type ) - 1,
invUpPacket->data().catalogId = 1; Common::InventoryType::Currency,
invUpPacket->data().quantity = getCurrency( type ); *currItem );
invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; queuePacket( invUpdate );
queuePacket( invUpPacket );
} }
void Core::Entity::Player::removeCurrency( Common::CurrencyType type, uint32_t amount ) 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 ); currItem->setStackSize( 0 );
else else
currItem->setStackSize( currentAmount - amount ); currItem->setStackSize( currentAmount - amount );
updateItemDb( currItem ); 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 ); 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, queuePacket( boost::make_shared< ActorControlPacket143 >( getId(), ItemObtainIcon,
static_cast< uint8_t >( type ) + 1, amount ) ); static_cast< uint8_t >( type ) + 1, amount ) );
} }
@ -311,13 +306,11 @@ void Core::Entity::Player::removeCrystal( Common::CrystalType type, uint32_t amo
updateItemDb( currItem ); updateItemDb( currItem );
auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
invUpPacket->data().containerId = Common::InventoryType::Crystal; static_cast< uint8_t >( type ) - 1,
invUpPacket->data().catalogId = static_cast< uint8_t >( type ) + 1; Common::InventoryType::Crystal,
invUpPacket->data().quantity = getCrystal( type ); *currItem );
invUpPacket->data().slot = static_cast< uint8_t >( type ) - 1; queuePacket( invUpdate );
queuePacket( invUpPacket );
} }
bool Core::Entity::Player::tryAddItem( uint16_t catalogId, uint32_t quantity ) 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() ) ); " AND CharacterId = " + std::to_string( getId() ) );
auto invUpPacket = makeZonePacket< FFXIVIpcUpdateInventorySlot >( getId() ); auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
invUpPacket->data().containerId = inventoryId; rSlotId,
invUpPacket->data().catalogId = catalogId; inventoryId,
invUpPacket->data().quantity = item->getStackSize(); *item );
invUpPacket->data().hqFlag = item->isHq() ? 1 : 0; queuePacket( invUpdate );
invUpPacket->data().slot = rSlotId;
invUpPacket->data().condition = 30000;
queuePacket( invUpPacket );
if( !silent ) if( !silent )
queuePacket( boost::make_shared< ActorControlPacket143 >( getId(), ItemObtainIcon, 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 Core::Entity::Player::getFreeSlotsInBags()
{ {
uint8_t slots = 0; uint8_t slots = 0;
for( uint8_t container : { 0, 1, 2, 3 } ) for( uint8_t container : { Bag0, Bag1, Bag2, Bag3 } )
{ {
// TODO: this feels hackish at best const auto& storage = m_inventoryMap[container];
slots += 34 - m_inventoryMap[container]->getEntryCount(); slots += ( storage->getMaxSize() - storage->getEntryCount() );
} }
return slots; return slots;
} }

View file

@ -0,0 +1,60 @@
#ifndef _INVENTORY_SLOT_UPDATE_PACKET_H
#define _INVENTORY_SLOT_UPDATE_PACKET_H
#include <Network/GamePacketNew.h>
#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*/