From bcb6c2b4045fec075609ee100fc8683964432740 Mon Sep 17 00:00:00 2001 From: Matthe815 Date: Wed, 4 Jan 2023 23:36:03 -0500 Subject: [PATCH] persistant money --- deps/ffxiv-actions | 1 + src/world/Actor/Player.cpp | 4 ++++ src/world/Actor/Player.h | 2 ++ src/world/Actor/PlayerInventory.cpp | 14 ++++++++++++- src/world/Actor/PlayerSql.cpp | 31 ++++++++++++++++++++++++++++- 5 files changed, 50 insertions(+), 2 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..3078b8e6 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 writeMoney(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..96b347d2 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 ); + writeMoney( CurrencyType::Gil ); updateContainer( Currency, slot, currItem ); @@ -557,6 +557,18 @@ void Sapphire::Entity::Player::writeItem( Sapphire::ItemPtr pItem ) const db.directExecute( stmt ); } +void Sapphire::Entity::Player::writeMoney(CurrencyType type) +{ + auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); + std::string query = "UPDATE charaitemcurrency SET "; + auto money = m_storageMap[Currency]->getItem(static_cast(type) - 1)->getStackSize(); + + query += "container_0 = " + std::to_string(money); + query += " WHERE CharacterId = " + 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..83ba2590 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(); @@ -680,6 +680,7 @@ bool Sapphire::Entity::Player::loadInventory() while( bagRes->next() ) { + Logger::info("Loaded items"); uint16_t storageId = bagRes->getUInt16( 1 ); for( uint32_t i = 1; i <= m_storageMap[ storageId ]->getMaxSize(); i++ ) { @@ -696,6 +697,34 @@ bool Sapphire::Entity::Player::loadInventory() } } + Logger::info(std::to_string(m_characterId)); + + auto moneyRes = db.query("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;"); + + while ( moneyRes->next() ) + { + uint16_t storageId = moneyRes->getUInt16( 1 ); + uint32_t money = moneyRes->getUInt64(2); + + auto slot = static_cast(static_cast(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; }