Support adding experience
This commit is contained in:
@@ -50,6 +50,11 @@ public interface IPokemon : IScriptSource
|
||||
/// The amount of experience of the Pokemon.
|
||||
/// </summary>
|
||||
uint Experience { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Increases the experience of the Pokemon. Returns whether any experience was gained.
|
||||
/// </summary>
|
||||
bool AddExperience(uint experience);
|
||||
|
||||
/// <summary>
|
||||
/// The personality value of the Pokemon.
|
||||
@@ -469,7 +474,34 @@ public class PokemonImpl : ScriptSource, IPokemon
|
||||
public LevelInt Level { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public uint Experience { get; }
|
||||
public uint Experience { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool AddExperience(uint experience)
|
||||
{
|
||||
if (!AllowedExperience)
|
||||
return false;
|
||||
var maxLevel = Library.StaticLibrary.Settings.MaxLevel;
|
||||
if (Level >= maxLevel)
|
||||
return false;
|
||||
var oldLevel = Level;
|
||||
var oldExperience = Experience;
|
||||
Experience += experience;
|
||||
var newLevel = Library.StaticLibrary.GrowthRates.CalculateLevel(Species.GrowthRate, Experience);
|
||||
if (newLevel > Level)
|
||||
{
|
||||
Level = newLevel;
|
||||
RecalculateFlatStats();
|
||||
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level));
|
||||
|
||||
if (newLevel >= maxLevel)
|
||||
{
|
||||
Experience = Library.StaticLibrary.GrowthRates.CalculateExperience(Species.GrowthRate, maxLevel);
|
||||
}
|
||||
}
|
||||
|
||||
return oldExperience != Experience;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public uint PersonalityValue { get; }
|
||||
|
||||
Reference in New Issue
Block a user