Support adding experience
This commit is contained in:
parent
e7cda474f1
commit
b77f0122d7
22
PkmnLib.Dynamic/Events/LevelUpEvent.cs
Normal file
22
PkmnLib.Dynamic/Events/LevelUpEvent.cs
Normal file
@ -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; }
|
||||||
|
}
|
@ -51,6 +51,11 @@ public interface IPokemon : IScriptSource
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
uint Experience { get; }
|
uint Experience { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increases the experience of the Pokemon. Returns whether any experience was gained.
|
||||||
|
/// </summary>
|
||||||
|
bool AddExperience(uint experience);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The personality value of the Pokemon.
|
/// The personality value of the Pokemon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -469,7 +474,34 @@ public class PokemonImpl : ScriptSource, IPokemon
|
|||||||
public LevelInt Level { get; private set; }
|
public LevelInt Level { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <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 />
|
/// <inheritdoc />
|
||||||
public uint PersonalityValue { get; }
|
public uint PersonalityValue { get; }
|
||||||
|
@ -71,6 +71,9 @@ public interface ISpecies : INamedValue
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IReadOnlyList<IEvolution> EvolutionData { get; }
|
IReadOnlyList<IEvolution> EvolutionData { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The egg groups the Pokémon belongs to.
|
||||||
|
/// </summary>
|
||||||
ICollection<StringKey> EggGroups { get; }
|
ICollection<StringKey> EggGroups { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user