From 741275d647f7f0e577238796d0e9a64b27c7f0e8 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Fri, 6 Jan 2023 21:21:19 -0500 Subject: [PATCH] refactor: Code updated to fmt::format --- src/world/Actor/PlayerInventory.cpp | 10 ++++------ src/world/Actor/PlayerSql.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index 66f4bb68..99e481c3 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -339,7 +339,7 @@ void Sapphire::Entity::Player::removeCurrency( Common::CurrencyType type, uint32 currItem->setStackSize( 0 ); else currItem->setStackSize( currentAmount - amount ); - writeCurrencyItem(type); + writeCurrencyItem( type ); 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(); - std::string query = "UPDATE charaitemcurrency SET "; - - query += "container_" + std::to_string( static_cast< int16_t >( type ) - 1 ) + " = " + std::to_string( money ); - - query += " WHERE CharacterId = " + std::to_string( getCharacterId() ) + ";"; + std::string query = fmt::format( + "UPDATE charaitemcurrency SET container_{0} = {1} WHERE CharacterId = {2};", + std::to_string( static_cast< int16_t >( type ) - 1 ), std::to_string( money ), std::to_string( getCharacterId() ) ); db.execute( query ); } diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index 4841573b..17e837bf 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #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_5, container_6, container_7, container_8, container_9, " "container_10, container_11 " "FROM charaitemcurrency " \ - "WHERE CharacterId = " + std::to_string(m_characterId) + " " \ - "ORDER BY storageId ASC;"); + "WHERE CharacterId = {0} " \ + "ORDER BY storageId ASC;", std::to_string(m_characterId))); while ( currencyRes->next() ) { uint16_t storageId = currencyRes->getUInt16( 1 ); uint32_t money = currencyRes->getUInt64( 2 ); - auto slot = static_cast< uint8_t >( static_cast( CurrencyType::Gil ) - 1 ); + auto slot = static_cast< uint8_t >( static_cast< uint8_t >( CurrencyType::Gil ) - 1 ); auto currItem = m_storageMap[ Currency ]->getItem( slot ); if ( !currItem )