2.5 update
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using BumpCombat.Constants;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BumpCombat.Progression
|
||||
{
|
||||
public sealed class ExperienceProgress
|
||||
{
|
||||
private float fractionalExperience;
|
||||
|
||||
public event Action<int, int, int> ExperienceChanged;
|
||||
public event Action<int> LevelGained;
|
||||
|
||||
public int Level { get; private set; } = 1;
|
||||
public int CurrentExperience { get; private set; }
|
||||
public int RequiredExperience => RequiredExperienceForLevel(Level);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Level = 1;
|
||||
CurrentExperience = 0;
|
||||
fractionalExperience = 0f;
|
||||
}
|
||||
|
||||
public void AddEvaluated(float evaluatedAmount)
|
||||
{
|
||||
fractionalExperience += Mathf.Max(0f, evaluatedAmount);
|
||||
int wholeExperience = Mathf.FloorToInt(
|
||||
fractionalExperience + 0.0001f);
|
||||
fractionalExperience = Mathf.Max(
|
||||
0f,
|
||||
fractionalExperience - wholeExperience);
|
||||
CurrentExperience += wholeExperience;
|
||||
|
||||
while (CurrentExperience >= RequiredExperience)
|
||||
{
|
||||
CurrentExperience -= RequiredExperience;
|
||||
Level++;
|
||||
LevelGained?.Invoke(Level);
|
||||
}
|
||||
|
||||
ExperienceChanged?.Invoke(
|
||||
CurrentExperience,
|
||||
RequiredExperience,
|
||||
Level);
|
||||
}
|
||||
|
||||
internal static int RequiredExperienceForLevel(int level)
|
||||
{
|
||||
LevelUpConstants tuning = GameplayConstants.Current.LevelUp;
|
||||
return tuning.BaseExperienceToNextLevel
|
||||
+ (Mathf.Max(1, level) - 1)
|
||||
* tuning.AdditionalExperiencePerLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user