Support adding experience
This commit is contained in:
parent
e7cda474f1
commit
b77f0122d7
|
@ -0,0 +1,22 @@
|
|||
using PkmnLib.Dynamic.Models;
|
||||
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
public class LevelUpEvent : IEventData
|
||||
{
|
||||
public LevelUpEvent(IPokemon pokemon, int previousLevel, int newLevel)
|
||||
{
|
||||
Pokemon = pokemon;
|
||||
PreviousLevel = previousLevel;
|
||||
NewLevel = newLevel;
|
||||
}
|
||||
|
||||
public int NewLevel { get; set; }
|
||||
|
||||
public int PreviousLevel { get; set; }
|
||||
|
||||
public IPokemon Pokemon { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public EventBatchId BatchId { get; init; }
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -71,6 +71,9 @@ public interface ISpecies : INamedValue
|
|||
/// </summary>
|
||||
IReadOnlyList<IEvolution> EvolutionData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The egg groups the Pokémon belongs to.
|
||||
/// </summary>
|
||||
ICollection<StringKey> EggGroups { get; }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue