1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 16:57:47 +00:00

correctly store items in armory/inventory based on client flag

This commit is contained in:
NotAdam 2018-08-25 22:38:07 +10:00
parent a86fc2794b
commit 4cab50f77c
5 changed files with 92 additions and 22 deletions

View file

@ -62,6 +62,46 @@ namespace Common {
SoulCrystal = 13, SoulCrystal = 13,
}; };
enum EquipSlotCategory : uint8_t
{
Unequippbale = 0,
// main slots
CharaMainHand = 1,
CharaOffHand = 2,
CharaHead = 3,
CharaBody = 4,
CharaHands = 5,
CharaWaist = 6,
CharaLegs = 7,
CharaFeet = 8,
CharaEars = 9,
CharaNeck = 10,
CharaWrist = 11,
CharaRing = 12,
CharaSoulCrystal = 17,
// specials
/*! Cannot equip gear to offhand slot */
MainTwoHandedWeapon = 13,
/*! Can be equipped in either main or offhand slot */
MainOrOffHand = 14, // unused
/*! Cannot equip gear to head */
BodyAndHead = 15,
/*! Cannot equip gear to hands, legs and feet slots */
BodyDisallowHandsLegsFeet = 16,
/*! Cannot equip gear to feet slot */
LegsDisallowFeet = 18,
/*! Cannot equp gear to head, hands, legs, feet slots */
BodyDisallowAll = 19,
/*! Cannot equip gear to hands slot */
BodyDisallowHands = 20,
/*! Cannot equip gear to legs & feet slots */
BodyDisallowLegsFeet = 21,
};
enum InventoryType : uint16_t enum InventoryType : uint16_t
{ {
Bag0 = 0, Bag0 = 0,
@ -87,7 +127,7 @@ namespace Common {
ArmoryWaist = 3204, ArmoryWaist = 3204,
ArmoryLegs = 3205, ArmoryLegs = 3205,
ArmoryFeet = 3206, ArmoryFeet = 3206,
ArmotyNeck = 3207, ArmoryNeck = 3207,
ArmoryEar = 3208, ArmoryEar = 3208,
ArmoryWrist = 3209, ArmoryWrist = 3209,
ArmoryRing = 3300, ArmoryRing = 3300,
@ -600,8 +640,8 @@ namespace Common {
HideWeapon = 0x2, HideWeapon = 0x2,
HideLegacyMark = 0x4, HideLegacyMark = 0x4,
StoreNewItemsInArmouryChest = 0x5, StoreNewItemsInArmouryChest = 0x10,
StoreCraftedItemsInInventory = 0x6, StoreCraftedItemsInInventory = 0x20,
Visor = 0x40, Visor = 0x40,
}; };

View file

@ -289,7 +289,7 @@ namespace Core {
createInvDbContainer( InventoryType::ArmoryLegs ); createInvDbContainer( InventoryType::ArmoryLegs );
createInvDbContainer( InventoryType::ArmoryFeet ); createInvDbContainer( InventoryType::ArmoryFeet );
createInvDbContainer( InventoryType::ArmotyNeck ); createInvDbContainer( InventoryType::ArmoryNeck );
createInvDbContainer( InventoryType::ArmoryEar ); createInvDbContainer( InventoryType::ArmoryEar );
createInvDbContainer( InventoryType::ArmoryWrist ); createInvDbContainer( InventoryType::ArmoryWrist );
createInvDbContainer( InventoryType::ArmoryRing ); createInvDbContainer( InventoryType::ArmoryRing );

View file

@ -88,7 +88,7 @@ void Core::Entity::Player::initInventory()
setupContainer( ArmoryFeet, 34, "charaiteminventory", true ); setupContainer( ArmoryFeet, 34, "charaiteminventory", true );
//neck //neck
setupContainer( ArmotyNeck, 34, "charaiteminventory", true ); setupContainer( ArmoryNeck, 34, "charaiteminventory", true );
//earring //earring
setupContainer( ArmoryEar, 34, "charaiteminventory", true ); setupContainer( ArmoryEar, 34, "charaiteminventory", true );
@ -503,10 +503,22 @@ Core::ItemPtr Core::Entity::Player::addItem( uint32_t catalogId, uint32_t quanti
// todo: for now we're just going to add any items to main inv // todo: for now we're just going to add any items to main inv
std::pair< uint8_t, uint8_t > freeBagSlot; std::pair< uint16_t, uint8_t > freeBagSlot;
bool foundFreeSlot = false; bool foundFreeSlot = false;
for( auto bag : { Bag0, Bag1, Bag2, Bag3 } ) std::vector< uint16_t > bags = { Bag0, Bag1, Bag2, Bag3 };
// add the related armoury bag to the applicable bags and try and fill a free slot there before falling back to regular inventory
if( itemInfo->isEquippable && getEquipDisplayFlags() & StoreNewItemsInArmouryChest )
{
auto bag = Items::Util::getCharaEquipSlotCategoryToArmoryId( itemInfo->equipSlotCategory );
sendDebug( "Got bag: " + std::to_string( bag ) + " for cat: " + std::to_string( itemInfo->equipSlotCategory ) );
bags.insert( bags.begin(), bag );
}
for( auto bag : bags )
{ {
auto storage = m_storageMap[bag]; auto storage = m_storageMap[bag];
@ -727,7 +739,7 @@ void Core::Entity::Player::swapItem( uint16_t fromInventoryId, uint8_t fromSlotI
&& !Items::Util::isArmory( fromInventoryId ) ) && !Items::Util::isArmory( fromInventoryId ) )
{ {
updateContainer( fromInventoryId, fromSlotId, nullptr ); updateContainer( fromInventoryId, fromSlotId, nullptr );
fromInventoryId = Items::Util::getArmoryToEquipSlot( toSlot ); fromInventoryId = Items::Util::getCharaEquipSlotCategoryToArmoryId( toSlot );
fromSlotId = static_cast < uint8_t >( m_storageMap[fromInventoryId]->getFreeSlot() ); fromSlotId = static_cast < uint8_t >( m_storageMap[fromInventoryId]->getFreeSlot() );
} }

View file

@ -25,44 +25,62 @@ bool Core::Items::Util::isArmory( uint16_t containerId )
containerId == Common::ArmoryOff || containerId == Common::ArmoryOff ||
containerId == Common::ArmoryRing || containerId == Common::ArmoryRing ||
containerId == Common::ArmoryWaist || containerId == Common::ArmoryWaist ||
containerId == Common::ArmoryWrist; containerId == Common::ArmoryWrist ||
containerId == Common::ArmorySoulCrystal;
} }
uint16_t Core::Items::Util::getArmoryToEquipSlot( uint8_t slotId ) uint16_t Core::Items::Util::getCharaEquipSlotCategoryToArmoryId( uint8_t slotId )
{ {
switch( slotId ) switch( slotId )
{ {
case Common::Body: case Common::CharaHead:
return Common::ArmoryHead;
case Common::CharaBody:
case Common::BodyAndHead:
case Common::BodyDisallowHandsLegsFeet:
case Common::BodyDisallowAll:
case Common::BodyDisallowHands:
case Common::BodyDisallowLegsFeet:
return Common::ArmoryBody; return Common::ArmoryBody;
case Common::Ear: case Common::CharaEars:
return Common::ArmoryEar; return Common::ArmoryEar;
case Common::Feet: case Common::CharaFeet:
return Common::ArmoryFeet; return Common::ArmoryFeet;
case Common::Hands: case Common::CharaHands:
return Common::ArmoryHand; return Common::ArmoryHand;
case Common::Legs: case Common::CharaLegs:
case Common::LegsDisallowFeet:
return Common::ArmoryLegs; return Common::ArmoryLegs;
case Common::MainHand: case Common::CharaMainHand:
case Common::MainTwoHandedWeapon:
case Common::MainOrOffHand:
return Common::ArmoryMain; return Common::ArmoryMain;
case Common::OffHand: case Common::CharaOffHand:
return Common::ArmoryOff; return Common::ArmoryOff;
case Common::Ring2: case Common::CharaRing:
case Common::Ring1:
return Common::ArmoryRing; return Common::ArmoryRing;
case Common::Waist: case Common::CharaWaist:
return Common::ArmoryWaist; return Common::ArmoryWaist;
case Common::Wrist: case Common::CharaWrist:
return Common::ArmoryWrist; return Common::ArmoryWrist;
case Common::CharaNeck:
return Common::ArmoryNeck;
case Common::CharaSoulCrystal:
return Common::ArmorySoulCrystal;
default: default:
return 0; return 0;
} }

View file

@ -15,7 +15,7 @@ namespace Util {
bool isArmory( uint16_t containerId ); bool isArmory( uint16_t containerId );
bool isEquipment( uint16_t containerId ); bool isEquipment( uint16_t containerId );
uint16_t getArmoryToEquipSlot( uint8_t slotId ); uint16_t getCharaEquipSlotCategoryToArmoryId( uint8_t slotId );
Common::ContainerType getContainerType( uint32_t containerId ); Common::ContainerType getContainerType( uint32_t containerId );