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

Fix dyeing and implement removeItem method

This commit is contained in:
Lucy 2023-02-08 21:44:51 +01:00
parent 1e3fe5e9c2
commit dac6c63414
5 changed files with 64 additions and 5 deletions

View file

@ -548,6 +548,7 @@ namespace Sapphire::Network::ActorControl
REQUEST_SALVAGE_SUCCESS_RATE = 0x1B2,
MOBHUNT_RECEIPT_ORDER = 0x1B3,
MOBHUNT_BREAK_ORDER = 0x1B4,
DYE_ITEM = 0x1B5,
EMOTE = 0x1F4,
EMOTE_WITH_WARP = 0x1F5,
EMOTE_CANCEL = 0x1F6,

View file

@ -1624,13 +1624,19 @@ void Player::dyeItemFromDyeingInfo()
if( !itemToDye || !dyeToUse )
return;
uint32_t stainColorID = dyeToUse->getAdditionalData();
itemToDye->setStain( stainColorID );
if( !removeItem( dyeToUse->getId() ) )
return;
// TODO: subtract/remove dye used
uint32_t stainColorID = dyeToUse->getAdditionalData();
bool shouldDye = stainColorID != 0;
bool invalidateGearSet = stainColorID != itemToDye->getStain();
itemToDye->setStain( stainColorID );
insertInventoryItem( static_cast< Sapphire::Common::InventoryType >( itemToDyeContainer ), static_cast< uint16_t >( itemToDyeSlot ), itemToDye );
writeItem( itemToDye );
auto dyePkt = makeActorControlSelf( getId(), DyeMsg, itemToDye->getId(), shouldDye, invalidateGearSet );
queuePacket( dyePkt );
}
void Player::resetObjSpawnIndex()

View file

@ -722,6 +722,8 @@ namespace Sapphire::Entity
ItemPtr addItem( uint32_t catalogId, uint32_t quantity = 1, bool isHq = false, bool slient = false, bool canMerge = true );
bool removeItem( uint32_t catalogId, uint32_t quantity = 1, bool isHq = false );
void moveItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot );
void swapItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot );

View file

@ -720,6 +720,54 @@ Sapphire::ItemPtr Sapphire::Entity::Player::addItem( uint32_t catalogId, uint32_
return item;
}
bool Sapphire::Entity::Player::removeItem( uint32_t catalogId, uint32_t quantity, bool isHq )
{
std::vector< uint16_t > bags = { Bag0, Bag1, Bag2, Bag3 };
for( auto bag : bags )
{
auto storage = m_storageMap[ bag ];
for( uint16_t slot = 0; slot < storage->getMaxSize(); slot++ )
{
if( quantity == 0 )
break;
auto item = storage->getItem( slot );
// remove any matching items
if( item && item->getId() == catalogId )
{
uint32_t count = item->getStackSize();
uint32_t maxStack = item->getMaxStackSize();
// check slot is same quality
if( item->isHq() != isHq )
continue;
// update stack
int32_t newStackSize = count - quantity;
if( newStackSize <= 0 )
{
quantity = std::abs( newStackSize );
discardItem( bag, slot );
}
else
{
quantity = 0;
item->setStackSize( newStackSize );
insertInventoryItem( static_cast< Sapphire::Common::InventoryType >( bag ), slot, item );
writeItem( item );
}
}
}
}
return quantity == 0;
}
void
Sapphire::Entity::Player::moveItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot )
{

View file

@ -182,6 +182,8 @@ const char* packetCommandToString( uint16_t commandId )
return "MOBHUNT_RECEIPT_ORDER";
case MOBHUNT_BREAK_ORDER:
return "MOBHUNT_BREAK_ORDER";
case DYE_ITEM:
return "DYE_ITEM";
case EMOTE:
return "EMOTE";
case EMOTE_WITH_WARP:
@ -623,7 +625,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_
player.teleportQuery( static_cast< uint16_t >( param11 ) );
break;
}
/* case PacketCommand::DyeItem: // Dye item
case PacketCommand::DYE_ITEM: // Dye item
{
// param11 = item to dye container
// param12 = item to dye slot
@ -631,7 +633,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_
// param4 = dye bag slot
player.setDyeingInfo( param11, param12, param2, param4 );
break;
}*/
}
case PacketCommand::DIRECTOR_INIT_RETURN: // Director init finish
{
pZone->onInitDirector( player );