1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 22:17:45 +00:00

Merge pull request #644 from collett8192/exp_fix

Should not gain any exp past max level.
This commit is contained in:
Adam 2020-02-29 18:56:28 +11:00 committed by GitHub
commit 34f66fbcd8

View file

@ -693,30 +693,34 @@ bool Sapphire::Entity::Player::isActionLearned( uint8_t actionId ) const
void Sapphire::Entity::Player::gainExp( uint32_t amount )
{
auto pExdData = m_pFw->get< Data::ExdDataGenerated >();
uint32_t currentExp = getExp();
uint16_t level = getLevel();
if( level >= Common::MAX_PLAYER_LEVEL )
{
setExp( 0 );
if( currentExp != 0 )
queuePacket( makeActorControlSelf( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), 0 ) );
return;
}
auto pExdData = m_pFw->get< Data::ExdDataGenerated >();
uint32_t neededExpToLevel = pExdData->get< Sapphire::Data::ParamGrow >( level )->expToNext;
uint32_t neededExpToLevelplus1 = pExdData->get< Sapphire::Data::ParamGrow >( level + 1 )->expToNext;
queuePacket( makeActorControlSelf( getId(), GainExpMsg, static_cast< uint8_t >( getClass() ), amount ) );
if( level >= Common::MAX_PLAYER_LEVEL ) // temporary fix for leveling over levelcap
{
queuePacket( makeActorControlSelf( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) );
return;
}
if( ( currentExp + amount ) >= neededExpToLevel )
{
// levelup
amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ?
neededExpToLevelplus1 - 1 :
( currentExp + amount - neededExpToLevel );
if( level + 1 >= Common::MAX_PLAYER_LEVEL )
amount = 0;
setExp( amount );
gainLevel();
queuePacket( makeActorControlSelf( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) );