diff --git a/src/common/Common.h b/src/common/Common.h index e34e4606..52f19554 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -556,8 +556,8 @@ namespace Sapphire::Common WolfMark = 0x07, TomestoneSold = 0x08, AlliedSeal = 0x09, - TomestonePoet = 0x0A, - Mgp = 0x0B, + Mgp = 0x0A, + TomestonePoet = 0x0B, TomestoneLaw = 0x0C, TomestoneEso = 0x0D, TomestoneLore = 0x0E diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 652ea0d7..e551ba98 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -182,6 +182,8 @@ namespace Sapphire::Entity /*! return the current amount of crystals of type */ uint32_t getCrystal( uint8_t type ) const; + uint32_t currencyTypeToItem( Common::CurrencyType type ) const; + void updateModels( Common::GearSetSlot equipSlotId, const Item& item ); Common::GearModelSlot equipSlotToModelSlot( Common::GearSetSlot slot ); diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index b424882e..817390d6 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -264,6 +264,43 @@ void Sapphire::Entity::Player::unequipSoulCrystal() setClassJob( parentClass ); } +uint32_t Sapphire::Entity::Player::currencyTypeToItem( Common::CurrencyType type ) const +{ + switch( type ) + { + case Common::CurrencyType::Gil: + return 1; + case Common::CurrencyType::StormSeal: + return 20; + case Common::CurrencyType::SerpentSeal: + return 21; + case Common::CurrencyType::FlameSeal: + return 22; + case Common::CurrencyType::TomestonePhilo: + return 23; + case Common::CurrencyType::TomestoneMytho: + return 24; + case Common::CurrencyType::WolfMark: + return 25; + case Common::CurrencyType::TomestoneSold: + return 26; + case Common::CurrencyType::AlliedSeal: + return 27; + case Common::CurrencyType::Mgp: + return 29; + case Common::CurrencyType::TomestonePoet: + return 28; + case Common::CurrencyType::TomestoneLaw: + return 30; + case Common::CurrencyType::TomestoneEso: + return 31; + case Common::CurrencyType::TomestoneLore: + return 32; + default: + return 0; + } +} + // TODO: these next functions are so similar that they could likely be simplified void Sapphire::Entity::Player::addCurrency( CurrencyType type, uint32_t amount ) { @@ -272,8 +309,7 @@ void Sapphire::Entity::Player::addCurrency( CurrencyType type, uint32_t amount ) if( !currItem ) { - // TODO: map currency type to itemid - currItem = createItem( 1 ); + currItem = createItem( currencyTypeToItem( type ) ); m_storageMap[ Currency ]->setItem( slot, currItem ); } diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index ab60ba5a..cc800cff 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -710,19 +710,23 @@ bool Sapphire::Entity::Player::loadInventory() while ( currencyRes->next() ) { uint16_t storageId = currencyRes->getUInt16( 1 ); - uint32_t money = currencyRes->getUInt( 2 ); - - auto slot = static_cast< uint8_t >( static_cast< uint8_t >( CurrencyType::Gil ) - 1 ); - auto currItem = m_storageMap[ Currency ]->getItem( slot ); - - if ( !currItem ) + for( uint32_t i = 1; i <= m_storageMap[ storageId ]->getMaxSize(); i++ ) { - // TODO: map currency type to itemid - currItem = createItem( 1 ); - m_storageMap[ Currency ]->setItem( slot, currItem ); - } + uint32_t money = currencyRes->getUInt( i + 1 ); + auto slot = i - 1; + auto currItem = m_storageMap[ Currency ]->getItem( slot ); - m_storageMap[ Currency ]->getItem( slot )->setStackSize( money ); + if( money == 0 ) + continue; + + if( !currItem ) + { + currItem = createItem( currencyTypeToItem( static_cast< Common::CurrencyType >( i ) ) ); + m_storageMap[ Currency ]->setItem( slot, currItem ); + } + + m_storageMap[ Currency ]->getItem( slot )->setStackSize( money ); + } } return true; diff --git a/src/world/Manager/InventoryMgr.cpp b/src/world/Manager/InventoryMgr.cpp index e597ab36..9734fc5a 100644 --- a/src/world/Manager/InventoryMgr.cpp +++ b/src/world/Manager/InventoryMgr.cpp @@ -46,7 +46,7 @@ void InventoryMgr::sendInventoryContainer( Entity::Player& player, ItemContainer currencyInfoPacket->data().item.subquarity = 1; currencyInfoPacket->data().item.stack = itM.second->getStackSize(); currencyInfoPacket->data().item.storageId = container->getId(); - currencyInfoPacket->data().item.containerIndex = 0; + currencyInfoPacket->data().item.containerIndex = itM.first; server.queueForPlayer( player.getCharacterId(), currencyInfoPacket ); }