From 495f651bceef045fd5dbfbbc26e19be35de8fb84 Mon Sep 17 00:00:00 2001 From: Mordred Date: Thu, 2 Jan 2025 13:25:18 +0100 Subject: [PATCH] levelup logic moved to playerMgr --- src/world/Actor/Player.cpp | 32 --------------------- src/world/Actor/Player.h | 3 -- src/world/Actor/PlayerInventory.cpp | 6 ++-- src/world/Manager/DebugCommandMgr.cpp | 5 ++-- src/world/Manager/PlayerMgr.cpp | 41 ++++++++++++++++++++++++++- src/world/Manager/PlayerMgr.h | 4 +++ 6 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 9c5a504d..03b65f2e 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -553,14 +553,6 @@ bool Player::hasMount( uint32_t mountId ) const return m_mountGuide[ index ] & value; } -void Player::levelUp() -{ - m_hp = getMaxHp(); - m_mp = getMaxMp(); - - setLevel( getLevel() + 1 ); -} - uint8_t Player::getLevel() const { auto& exdData = Common::Service< Data::ExdData >::ref(); @@ -620,20 +612,6 @@ void Player::setInCombat( bool mode ) void Player::setClassJob( Common::ClassJob classJob ) { m_class = classJob; - - if( getHp() > getMaxHp() ) - m_hp = getMaxHp(); - - if( getMp() > getMaxMp() ) - m_mp = getMaxMp(); - - m_tp = 0; - - Network::Util::Packet::sendChangeClass( *this ); - Network::Util::Packet::sendStatusUpdate( *this ); - Network::Util::Packet::sendActorControl( getInRangePlayerIds( true ), getId(), ClassJobChange, 4 ); - Network::Util::Packet::sendHudParam( *this ); - Service< World::Manager::MapMgr >::ref().updateQuests( *this ); } void Player::setLevel( uint8_t level ) @@ -641,16 +619,6 @@ void Player::setLevel( uint8_t level ) auto& exdData = Common::Service< Data::ExdData >::ref(); uint8_t classJobIndex = exdData.getRow< Excel::ClassJob >( static_cast< uint8_t >( getClass() ) )->data().WorkIndex; m_classArray[ classJobIndex ] = level; - - calculateStats(); - Network::Util::Packet::sendBaseParams( *this ); - Network::Util::Packet::sendHudParam( *this ); - Network::Util::Packet::sendStatusUpdate( *this ); - Network::Util::Packet::sendActorControl( getInRangePlayerIds( true ), getId(), LevelUpEffect, static_cast< uint8_t >( getClass() ), getLevel(), getLevel() - 1 ); - - auto& achvMgr = Common::Service< World::Manager::AchievementMgr >::ref(); - achvMgr.progressAchievementByType< Common::Achievement::Type::Classjob >( *this, static_cast< uint32_t >( getClass() ) ); - Service< World::Manager::MapMgr >::ref().updateQuests( *this ); } void Player::setLevelForClass( uint8_t level, Common::ClassJob classjob ) diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 5be3a0b0..87db7e18 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -220,9 +220,6 @@ namespace Sapphire::Entity /*! sets the exp of the currently active class / job */ void setCurrentExp( uint32_t amount ); - /*! gain a level on the currently active class / job */ - void levelUp(); - /*! set level on the currently active class / job to given level */ void setLevel( uint8_t level ); diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index 597b8e17..4d116629 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -118,7 +118,7 @@ void Player::equipWeapon( const Item& item ) if( ( isClassJobUnlocked( newClassJob ) ) && ( currentParentClass != newClassJob ) ) { - setClassJob( newClassJob ); + playerMgr().onClassJobChanged( *this, newClassJob ); } } @@ -131,7 +131,7 @@ void Player::equipSoulCrystal( const Item& item ) auto newClassJob = static_cast< ClassJob >( itemClassJob ); if( isClassJobUnlocked( newClassJob ) ) - setClassJob( newClassJob ); + playerMgr().onClassJobChanged( *this, newClassJob ); } void Player::updateModels( GearSetSlot equipSlotId, const Sapphire::Item& item ) @@ -263,7 +263,7 @@ void Player::unequipSoulCrystal() auto currentClassJob = exdData.getRow< Excel::ClassJob >( static_cast< uint32_t >( getClass() ) ); auto parentClass = static_cast< ClassJob >( currentClassJob->data().MainClass ); - setClassJob( parentClass ); + playerMgr().onClassJobChanged( *this, parentClass ); } uint32_t Player::currencyTypeToItem( Common::CurrencyType type ) const diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index f5b8eae3..4ed6bd23 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -247,10 +247,9 @@ void DebugCommandMgr::set( char* data, Entity::Player& player, std::shared_ptr< if( player.getLevelForClass( static_cast< Common::ClassJob > ( id ) ) == 0 ) { player.setLevelForClass( 1, static_cast< Common::ClassJob > ( id ) ); - player.setClassJob( static_cast< Common::ClassJob > ( id ) ); } - else - player.setClassJob( static_cast< Common::ClassJob > ( id ) ); + + playerMgr.onClassJobChanged( player, static_cast< Common::ClassJob > ( id ) ); } else if( subCommand == "cfpenalty" ) { diff --git a/src/world/Manager/PlayerMgr.cpp b/src/world/Manager/PlayerMgr.cpp index b8a60bc2..78192773 100644 --- a/src/world/Manager/PlayerMgr.cpp +++ b/src/world/Manager/PlayerMgr.cpp @@ -6,10 +6,12 @@ #include #include +#include #include #include #include #include +#include #include