Browse Source

Optimize AddPlrExperience() (#5737)

pull/5740/head
Eric Robinson 3 years ago committed by GitHub
parent
commit
93a145608e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      Source/player.cpp

12
Source/player.cpp

@ -2686,6 +2686,12 @@ void AddPlrExperience(Player &player, int lvl, int exp)
return;
}
// exit function early if player is unable to gain more experience by checking final index of ExpLvlsTbl
int expLvlsTblSize = sizeof(ExpLvlsTbl) / sizeof(ExpLvlsTbl[0]);
if (player._pExperience >= ExpLvlsTbl[expLvlsTblSize - 1]) {
return;
}
if (player._pHitPoints <= 0) {
return;
}
@ -2711,8 +2717,10 @@ void AddPlrExperience(Player &player, int lvl, int exp)
RedrawEverything();
}
if (player._pExperience >= ExpLvlsTbl[49]) {
player._pLevel = 50;
/* set player level to MaxCharacterLevel if the experience value for MaxCharacterLevel is reached, which exits the function early
and does not call NextPlrLevel(), which is responsible for giving Attribute points and Life/Mana on level up */
if (player._pExperience >= ExpLvlsTbl[MaxCharacterLevel - 1]) {
player._pLevel = MaxCharacterLevel;
return;
}

Loading…
Cancel
Save