XP and level up systems implemented.

This commit is contained in:
2023-12-24 22:50:25 -06:00
parent 2a72238e40
commit 4ac15dd1cc
17 changed files with 235 additions and 113 deletions
+53 -1
View File
@@ -51,7 +51,6 @@ All rights reserved.
#include "config.h"
#include <string_view>
INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_LIST
INCLUDE_ANIMATION_DATA
@@ -958,6 +957,9 @@ void EntityStats::SetBaseStat(ItemAttribute stat,float val){
baseStats.A(stat)=val;
RecalculateEquipStats();
}
void EntityStats::SetBaseStat(std::string_view stat,float val){
SetBaseStat(ItemAttribute::Get(stat),val);
}
void Player::SetBaseStat(std::string_view a,float val){
stats.SetBaseStat(ItemAttribute::Get(a),val);
}
@@ -1089,4 +1091,54 @@ const float Player::GetDamageReductionPct()const{
float modDmgReductionPct=0;
modDmgReductionPct+=GetStat("Damage Reduction")/100;
return modDmgReductionPct;
}
void Player::AddXP(const uint32_t xpGain){
currentLevelXP+=xpGain;
totalXPEarned+=xpGain;
uint32_t nextLevelXP=NextLevelXPRequired();
if(Level()<LevelCap()){
if(currentLevelXP>nextLevelXP){
currentLevelXP-=nextLevelXP;
level++;
OnLevelUp();
}
}
}
void Player::OnLevelUp(){
stats.SetBaseStat("Health",GetBaseStat("Health")+hpGrowthRate);
stats.SetBaseStat("Attack",GetBaseStat("Attack")+atkGrowthRate);
Heal(GetBaseStat("Health"));
}
const uint8_t Player::LevelCap()const{
return levelCap;
}
const uint8_t Player::Level()const{
return level;
}
const uint32_t Player::CurrentXP()const{
return currentLevelXP;
}
const uint32_t Player::TotalXP()const{
return totalXPEarned;
}
const uint32_t Player::NextLevelXPRequired()const{
if(Level()<LevelCap()){
return DATA.GetProperty(std::format("PlayerXP.LEVEL[{}]",Level()+1)).GetInt();
}
return 0;
}
void Player::ResetAccumulatedXP(){
accumulatedXP=0;
}
void Player::AddAccumulatedXP(const uint32_t xpGain){
accumulatedXP+=xpGain;
}
const uint32_t Player::GetAccumulatedXP()const{
return accumulatedXP;
}