1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-04 17:57:47 +00:00

levelup logic moved to playerMgr

This commit is contained in:
Mordred 2025-01-02 13:25:18 +01:00
parent 8a3d8775fe
commit 495f651bce
6 changed files with 49 additions and 42 deletions

View file

@ -553,14 +553,6 @@ bool Player::hasMount( uint32_t mountId ) const
return m_mountGuide[ index ] & value; return m_mountGuide[ index ] & value;
} }
void Player::levelUp()
{
m_hp = getMaxHp();
m_mp = getMaxMp();
setLevel( getLevel() + 1 );
}
uint8_t Player::getLevel() const uint8_t Player::getLevel() const
{ {
auto& exdData = Common::Service< Data::ExdData >::ref(); auto& exdData = Common::Service< Data::ExdData >::ref();
@ -620,20 +612,6 @@ void Player::setInCombat( bool mode )
void Player::setClassJob( Common::ClassJob classJob ) void Player::setClassJob( Common::ClassJob classJob )
{ {
m_class = 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 ) void Player::setLevel( uint8_t level )
@ -641,16 +619,6 @@ void Player::setLevel( uint8_t level )
auto& exdData = Common::Service< Data::ExdData >::ref(); auto& exdData = Common::Service< Data::ExdData >::ref();
uint8_t classJobIndex = exdData.getRow< Excel::ClassJob >( static_cast< uint8_t >( getClass() ) )->data().WorkIndex; uint8_t classJobIndex = exdData.getRow< Excel::ClassJob >( static_cast< uint8_t >( getClass() ) )->data().WorkIndex;
m_classArray[ classJobIndex ] = level; 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 ) void Player::setLevelForClass( uint8_t level, Common::ClassJob classjob )

View file

@ -220,9 +220,6 @@ namespace Sapphire::Entity
/*! sets the exp of the currently active class / job */ /*! sets the exp of the currently active class / job */
void setCurrentExp( uint32_t amount ); 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 */ /*! set level on the currently active class / job to given level */
void setLevel( uint8_t level ); void setLevel( uint8_t level );

View file

@ -118,7 +118,7 @@ void Player::equipWeapon( const Item& item )
if( ( isClassJobUnlocked( newClassJob ) ) && ( currentParentClass != newClassJob ) ) 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 ); auto newClassJob = static_cast< ClassJob >( itemClassJob );
if( isClassJobUnlocked( newClassJob ) ) if( isClassJobUnlocked( newClassJob ) )
setClassJob( newClassJob ); playerMgr().onClassJobChanged( *this, newClassJob );
} }
void Player::updateModels( GearSetSlot equipSlotId, const Sapphire::Item& item ) 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 currentClassJob = exdData.getRow< Excel::ClassJob >( static_cast< uint32_t >( getClass() ) );
auto parentClass = static_cast< ClassJob >( currentClassJob->data().MainClass ); auto parentClass = static_cast< ClassJob >( currentClassJob->data().MainClass );
setClassJob( parentClass ); playerMgr().onClassJobChanged( *this, parentClass );
} }
uint32_t Player::currencyTypeToItem( Common::CurrencyType type ) const uint32_t Player::currencyTypeToItem( Common::CurrencyType type ) const

View file

@ -247,10 +247,9 @@ void DebugCommandMgr::set( char* data, Entity::Player& player, std::shared_ptr<
if( player.getLevelForClass( static_cast< Common::ClassJob > ( id ) ) == 0 ) if( player.getLevelForClass( static_cast< Common::ClassJob > ( id ) ) == 0 )
{ {
player.setLevelForClass( 1, static_cast< Common::ClassJob > ( id ) ); 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" ) else if( subCommand == "cfpenalty" )
{ {

View file

@ -6,10 +6,12 @@
#include <Util/Util.h> #include <Util/Util.h>
#include <Territory/Land.h> #include <Territory/Land.h>
#include <Manager/AchievementMgr.h>
#include <Manager/TerritoryMgr.h> #include <Manager/TerritoryMgr.h>
#include <Manager/HousingMgr.h> #include <Manager/HousingMgr.h>
#include <Manager/QuestMgr.h> #include <Manager/QuestMgr.h>
#include <Manager/WarpMgr.h> #include <Manager/WarpMgr.h>
#include <Manager/MapMgr.h>
#include <Script/ScriptMgr.h> #include <Script/ScriptMgr.h>
#include <Common.h> #include <Common.h>
@ -368,9 +370,11 @@ void PlayerMgr::onGainExp( Entity::Player& player, uint32_t exp )
if( level + 1 >= Common::MAX_PLAYER_LEVEL ) if( level + 1 >= Common::MAX_PLAYER_LEVEL )
exp = 0; exp = 0;
else
onLevelChanged( player, level + 1 );
player.setCurrentExp( exp ); player.setCurrentExp( exp );
player.levelUp();
} }
else else
player.setCurrentExp( currentExp + exp ); player.setCurrentExp( currentExp + exp );
@ -540,5 +544,40 @@ void PlayerMgr::onExitInstance( Entity::Player& player )
} }
void PlayerMgr::onClassJobChanged( Entity::Player& player, Common::ClassJob classJob )
{
player.setClassJob( classJob );
if( player.getHp() > player.getMaxHp() )
player.setHp( player.getMaxHp() );
if( player.getMp() > player.getMaxMp() )
player.setMp( player.getMaxMp() );
player.setTp( 0 );
Network::Util::Packet::sendChangeClass( player );
Network::Util::Packet::sendStatusUpdate( player );
Network::Util::Packet::sendActorControl( player.getInRangePlayerIds( true ), player.getId(), ClassJobChange, 4 );
Network::Util::Packet::sendHudParam( player );
Common::Service< World::Manager::MapMgr >::ref().updateQuests( player );
}
void PlayerMgr::onLevelChanged( Entity::Player& player, uint8_t level )
{
player.setLevel( level );
player.calculateStats();
player.setHp( player.getMaxHp() );
player.setMp( player.getMaxMp() );
Network::Util::Packet::sendBaseParams( player );
Network::Util::Packet::sendHudParam( player );
Network::Util::Packet::sendStatusUpdate( player );
Network::Util::Packet::sendActorControl( player.getInRangePlayerIds( true ), player.getId(), LevelUpEffect, static_cast< uint8_t >( player.getClass() ), player.getLevel(), player.getLevel() - 1 );
auto& achvMgr = Common::Service< World::Manager::AchievementMgr >::ref();
achvMgr.progressAchievementByType< Common::Achievement::Type::Classjob >( player, static_cast< uint32_t >( player.getClass() ) );
Common::Service< World::Manager::MapMgr >::ref().updateQuests( player );
}

View file

@ -42,6 +42,10 @@ namespace Sapphire::World::Manager
void onExitInstance( Sapphire::Entity::Player& player ); void onExitInstance( Sapphire::Entity::Player& player );
void onClassJobChanged( Sapphire::Entity::Player& player, Common::ClassJob classJob );
void onLevelChanged( Sapphire::Entity::Player& player, uint8_t level );
//////////// Helpers //////////// Helpers
static void sendServerNotice( Sapphire::Entity::Player& player, const std::string& message ); static void sendServerNotice( Sapphire::Entity::Player& player, const std::string& message );