1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-24 18:47:45 +00:00

refactor: Code updated to fmt::format

This commit is contained in:
Matthe815 2023-01-06 21:21:19 -05:00
parent 952bb6d7be
commit 741275d647
No known key found for this signature in database
GPG key ID: 6B963FE816B1DC39
2 changed files with 9 additions and 10 deletions

View file

@ -339,7 +339,7 @@ void Sapphire::Entity::Player::removeCurrency( Common::CurrencyType type, uint32
currItem->setStackSize( 0 ); currItem->setStackSize( 0 );
else else
currItem->setStackSize( currentAmount - amount ); currItem->setStackSize( currentAmount - amount );
writeCurrencyItem(type); writeCurrencyItem( type );
auto seq = getNextInventorySequence(); auto seq = getNextInventorySequence();
@ -563,11 +563,9 @@ void Sapphire::Entity::Player::writeCurrencyItem( CurrencyType type )
auto money = m_storageMap[ Currency ]->getItem( static_cast< uint16_t >( type ) - 1 )->getStackSize(); auto money = m_storageMap[ Currency ]->getItem( static_cast< uint16_t >( type ) - 1 )->getStackSize();
std::string query = "UPDATE charaitemcurrency SET "; std::string query = fmt::format(
"UPDATE charaitemcurrency SET container_{0} = {1} WHERE CharacterId = {2};",
query += "container_" + std::to_string( static_cast< int16_t >( type ) - 1 ) + " = " + std::to_string( money ); std::to_string( static_cast< int16_t >( type ) - 1 ), std::to_string( money ), std::to_string( getCharacterId() ) );
query += " WHERE CharacterId = " + std::to_string( getCharacterId() ) + ";";
db.execute( query ); db.execute( query );
} }

View file

@ -6,6 +6,7 @@
#include <Network/PacketContainer.h> #include <Network/PacketContainer.h>
#include <Database/DatabaseDef.h> #include <Database/DatabaseDef.h>
#include <Service.h> #include <Service.h>
#include <format>
#include "Network/PacketWrappers/PlayerSetupPacket.h" #include "Network/PacketWrappers/PlayerSetupPacket.h"
@ -697,20 +698,20 @@ bool Sapphire::Entity::Player::loadInventory()
} }
} }
auto currencyRes = db.query("SELECT storageId, " auto currencyRes = db.query(fmt::format("SELECT storageId, "
"container_0, container_1, container_2, container_3, container_4, " "container_0, container_1, container_2, container_3, container_4, "
"container_5, container_6, container_7, container_8, container_9, " "container_5, container_6, container_7, container_8, container_9, "
"container_10, container_11 " "container_10, container_11 "
"FROM charaitemcurrency " \ "FROM charaitemcurrency " \
"WHERE CharacterId = " + std::to_string(m_characterId) + " " \ "WHERE CharacterId = {0} " \
"ORDER BY storageId ASC;"); "ORDER BY storageId ASC;", std::to_string(m_characterId)));
while ( currencyRes->next() ) while ( currencyRes->next() )
{ {
uint16_t storageId = currencyRes->getUInt16( 1 ); uint16_t storageId = currencyRes->getUInt16( 1 );
uint32_t money = currencyRes->getUInt64( 2 ); uint32_t money = currencyRes->getUInt64( 2 );
auto slot = static_cast< uint8_t >( static_cast<uint8_t>( CurrencyType::Gil ) - 1 ); auto slot = static_cast< uint8_t >( static_cast< uint8_t >( CurrencyType::Gil ) - 1 );
auto currItem = m_storageMap[ Currency ]->getItem( slot ); auto currItem = m_storageMap[ Currency ]->getItem( slot );
if ( !currItem ) if ( !currItem )