63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class Level
|
|
{
|
|
public int currentLevel;
|
|
|
|
public UnityEvent OnLevelUpEvent = new UnityEvent();
|
|
public UnityEvent OnExperienceChanged = new UnityEvent();
|
|
|
|
float currentExperience;
|
|
public float GetCurrentExperience()
|
|
{
|
|
return currentExperience;
|
|
}
|
|
|
|
public float FinalExperienceThreshold;
|
|
|
|
public Level()
|
|
{
|
|
currentLevel = 1;
|
|
currentExperience = 0f;
|
|
//baseExperienceThreshold = 500f;
|
|
OnLevelUpEvent.AddListener(UpdateExperienceThreshold);
|
|
UpdateExperienceThreshold();
|
|
}
|
|
public Level(int currentLevel, float currentExperience)
|
|
{
|
|
this.currentLevel = currentLevel;
|
|
this.currentExperience = currentExperience;
|
|
|
|
OnLevelUpEvent.AddListener(UpdateExperienceThreshold);
|
|
UpdateExperienceThreshold();
|
|
}
|
|
|
|
public void GainExperience(float xpIncome)
|
|
{
|
|
currentExperience += xpIncome;
|
|
if (currentExperience >= FinalExperienceThreshold)
|
|
{
|
|
currentExperience -= FinalExperienceThreshold;
|
|
currentLevel++;
|
|
OnLevelUpEvent.Invoke();
|
|
//Debug.Log("LevelUp Event Trigger");
|
|
}
|
|
//Debug.Log(xpIncome + " exp received");
|
|
//Debug.Log(currentExperience + " / " + FinalExperienceThreshold);
|
|
if (currentExperience >= FinalExperienceThreshold)
|
|
{
|
|
GainExperience(0);
|
|
}
|
|
OnExperienceChanged.Invoke();
|
|
}
|
|
|
|
public void UpdateExperienceThreshold()
|
|
{
|
|
FinalExperienceThreshold = Mathf.RoundToInt(GameConstants.CharacterBalancing.BaseExperienceThreshold + GameConstants.CharacterBalancing.ExperienceThresholdGrowth * Mathf.Pow((float)currentLevel, GameConstants.CharacterBalancing.ExperienceThresholdGrowthPerLevelExponent));
|
|
}
|
|
|
|
}
|