From f71230809b0cda13221e67ea9ee7b914159b69ed Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 6 Jan 2023 22:18:29 -0500 Subject: [PATCH] Improved Persistence (#822) * persistant money * removed hardcoding and fixed debug console spam * refactor: fix coding system inconsistencies * refactor: fix coding style inconsistencies in loading * refactor: Missed some inconsistents * refactor: Missed some more inconsistents * quest: Introduced marauder quest (can get class, but no cutscenes yet) * refactor: Code updated to fmt::format * Delete ClsMar999.cpp * Delete ClsMar998.cpp * script-loader fix * script-loader formatting * build-error: removed broken dep --- deps/ffxiv-actions | 1 + src/world/Actor/Player.cpp | 4 ++++ src/world/Actor/Player.h | 2 ++ src/world/Actor/PlayerInventory.cpp | 19 +++++++++++++++--- src/world/Actor/PlayerSql.cpp | 31 +++++++++++++++++++++++++++-- 5 files changed, 52 insertions(+), 5 deletions(-) create mode 160000 deps/ffxiv-actions diff --git a/deps/ffxiv-actions b/deps/ffxiv-actions new file mode 160000 index 00000000..dde9b5bb --- /dev/null +++ b/deps/ffxiv-actions @@ -0,0 +1 @@ +Subproject commit dde9b5bbfc7c0197de0b0b49b982a0ee9fe761ab diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 33bd50a2..8ac60b07 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -322,11 +322,13 @@ void Player::calculateStats() uint8_t tribe = getLookAt( Common::CharaLook::Tribe ); uint8_t level = getLevel(); auto job = static_cast< uint8_t >( getClass() ); + auto deity = getGuardianDeity(); auto& exdData = Common::Service< Data::ExdData >::ref(); auto classInfo = exdData.getRow< Excel::ClassJob >( job ); auto tribeInfo = exdData.getRow< Excel::Tribe >( tribe ); + auto deityInfo = exdData.getRow< Excel::GuardianDeity >( deity ); auto paramGrowthInfo = exdData.getRow< Excel::ParamGrow >( level ); float base = Math::CalcStats::calculateBaseStat( *this ); @@ -374,6 +376,8 @@ void Player::calculateStats() setStatValue( BaseParam::AttackMagicPotency, inte ); setStatValue( BaseParam::HealingMagicPotency, mnd ); + setStatValue( BaseParam::PiercingResistance, 0 ); + max_mp = Math::CalcStats::calculateMaxMp( *this ); max_hp = Math::CalcStats::calculateMaxHp( *this ); diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 5595d194..27173b82 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -736,6 +736,8 @@ namespace Sapphire::Entity void writeItem( ItemPtr pItem ) const; + void writeCurrencyItem( Common::CurrencyType type ); + void deleteItemDb( ItemPtr pItem ) const; /*! return the crystal amount of currency of type */ diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index b48a63ea..99e481c3 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -301,7 +301,7 @@ void Sapphire::Entity::Player::addCurrency( CurrencyType type, uint32_t amount ) uint32_t currentAmount = currItem->getStackSize(); currItem->setStackSize( currentAmount + amount ); - writeItem( currItem ); + writeCurrencyItem( type ); updateContainer( Currency, slot, currItem ); @@ -339,7 +339,7 @@ void Sapphire::Entity::Player::removeCurrency( Common::CurrencyType type, uint32 currItem->setStackSize( 0 ); else currItem->setStackSize( currentAmount - amount ); - writeItem( currItem ); + writeCurrencyItem( type ); auto seq = getNextInventorySequence(); @@ -531,7 +531,7 @@ void Sapphire::Entity::Player::writeInventory( InventoryType type ) if( i > 0 ) query += ", "; - query += "container_" + std::to_string( i ) + " = " + std::to_string( currItem ? currItem->getUId() : 0 ); + query += "container_" + std::to_string( i ) + " = " + std::to_string( currItem ? currItem->getUId() : 0 ); } query += " WHERE CharacterId = " + std::to_string( getCharacterId() ); @@ -557,6 +557,19 @@ void Sapphire::Entity::Player::writeItem( Sapphire::ItemPtr pItem ) const db.directExecute( stmt ); } +void Sapphire::Entity::Player::writeCurrencyItem( CurrencyType type ) +{ + auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); + + auto money = m_storageMap[ Currency ]->getItem( static_cast< uint16_t >( type ) - 1 )->getStackSize(); + + 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 ); +} + void Sapphire::Entity::Player::deleteItemDb( Sapphire::ItemPtr item ) const { auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index eb93924b..3ae159b0 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -152,7 +152,7 @@ bool Sapphire::Entity::Player::loadFromDb( uint64_t characterId ) // Stats m_hp = res->getUInt( "Hp" ); m_mp = res->getUInt( "Mp" ); - m_tp = 0; + m_tp = res->getUInt( "Tp" ); m_maxHp = getMaxHp(); m_maxMp = getMaxMp(); @@ -168,6 +168,7 @@ bool Sapphire::Entity::Player::loadFromDb( uint64_t characterId ) m_bNewGame = false; m_hp = getMaxHp(); m_mp = getMaxMp(); + m_tp = 1000; } if( m_hp == 0 ) @@ -323,7 +324,7 @@ void Sapphire::Entity::Player::updateDbChara() const stmt->setInt( 1, getHp() ); stmt->setInt( 2, getMp() ); - stmt->setInt( 3, 0 ); // TP + stmt->setInt( 3, getTp() ); // TP stmt->setInt( 4, 0 ); // GP stmt->setInt( 5, 0 ); // Mode stmt->setUInt( 6, m_mount ); // Mount @@ -696,6 +697,32 @@ bool Sapphire::Entity::Player::loadInventory() } } + 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 = {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< uint8_t >( CurrencyType::Gil ) - 1 ); + auto currItem = m_storageMap[ Currency ]->getItem( slot ); + + if ( !currItem ) + { + // TODO: map currency type to itemid + currItem = createItem( 1 ); + m_storageMap[ Currency ]->setItem( slot, currItem ); + } + + m_storageMap[ Currency ]->getItem( slot )->setStackSize( money ); + } + return true; }