1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 22:17:45 +00:00

Merge pull request #731 from collett8192/patch

prevent writing an invalid intermediate state to db when inventory action happens inside a single container
This commit is contained in:
Adam 2021-09-17 21:56:36 +10:00 committed by GitHub
commit fee9ed6b05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View file

@ -948,7 +948,7 @@ namespace Sapphire::Entity
ItemPtr getItemAt( uint16_t containerId, uint8_t slotId );
bool updateContainer( uint16_t storageId, uint8_t slotId, ItemPtr pItem );
bool updateContainer( uint16_t storageId, uint8_t slotId, ItemPtr pItem, bool writeToDb = true );
/*! calculate and return player ilvl based off equipped gear */
uint16_t calculateEquippedGearItemLevel();

View file

@ -739,7 +739,7 @@ Sapphire::Entity::Player::moveItem( uint16_t fromInventoryId, uint8_t fromSlotId
sendStatusEffectUpdate(); // send if any equip is changed
}
bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint8_t slotId, ItemPtr pItem )
bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint8_t slotId, ItemPtr pItem, bool writeToDb )
{
auto containerType = World::Manager::ItemMgr::getContainerType( storageId );
@ -752,7 +752,8 @@ bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint8_t slot
case Bag:
case CurrencyCrystal:
{
writeInventory( static_cast< InventoryType >( storageId ) );
if( writeToDb )
writeInventory( static_cast< InventoryType >( storageId ) );
break;
}
@ -767,7 +768,8 @@ bool Sapphire::Entity::Player::updateContainer( uint16_t storageId, uint8_t slot
else
unequipItem( static_cast< GearSetSlot >( slotId ), pItem, true );
writeInventory( static_cast< InventoryType >( storageId ) );
if( writeToDb )
writeInventory( static_cast< InventoryType >( storageId ) );
break;
}
default:
@ -804,7 +806,7 @@ void Sapphire::Entity::Player::splitItem( uint16_t fromInventoryId, uint8_t from
fromItem->setStackSize( fromItem->getStackSize() - itemCount );
updateContainer( fromInventoryId, fromSlotId, fromItem );
updateContainer( fromInventoryId, fromSlotId, fromItem, fromInventoryId != toInventoryId );
updateContainer( toInventoryId, toSlot, newItem );
updateItemDb( fromItem );
@ -835,7 +837,7 @@ void Sapphire::Entity::Player::mergeItem( uint16_t fromInventoryId, uint8_t from
{
fromItem->setStackSize( stackOverflow );
updateItemDb( fromItem );
updateContainer( fromInventoryId, fromSlotId, fromItem );
updateContainer( fromInventoryId, fromSlotId, fromItem, fromInventoryId != toInventoryId );
}
@ -871,7 +873,7 @@ void Sapphire::Entity::Player::swapItem( uint16_t fromInventoryId, uint8_t fromS
auto containerTypeFrom = World::Manager::ItemMgr::getContainerType( fromInventoryId );
auto containerTypeTo = World::Manager::ItemMgr::getContainerType( toInventoryId );
updateContainer( toInventoryId, toSlot, fromItem );
updateContainer( toInventoryId, toSlot, fromItem, fromInventoryId != toInventoryId );
updateContainer( fromInventoryId, fromSlotId, toItem );
if( static_cast< InventoryType >( toInventoryId ) == GearSet0 ||