Additional functionality

This commit is contained in:
2024-09-30 19:23:56 +02:00
parent 4c34910a43
commit b01a8fb704
9 changed files with 171 additions and 5 deletions

View File

@@ -71,6 +71,11 @@ public interface IPokemon : IScriptSource
/// currently not used, and can be used for other implementations.
/// </summary>
byte Coloring { get; }
/// <summary>
/// Whether the Pokemon is shiny.
/// </summary>
bool IsShiny { get; }
/// <summary>
/// The held item of the Pokemon.
@@ -163,7 +168,12 @@ public interface IPokemon : IScriptSource
/// <summary>
/// Checks whether the Pokemon has a specific move in its current moveset.
/// </summary>
public bool HasMove(StringKey moveName);
bool HasMove(StringKey moveName);
/// <summary>
/// Swaps two moves of the Pokemon.
/// </summary>
void SwapMoves(byte index1, byte index2);
/// <summary>
/// Whether or not the Pokemon is allowed to gain experience.
@@ -487,12 +497,21 @@ public class PokemonImpl : ScriptSource, IPokemon
var oldLevel = Level;
var oldExperience = Experience;
Experience += experience;
var batchId = new EventBatchId();
BattleData?.Battle.EventHook.Invoke(new ExperienceGainEvent(this, oldExperience, Experience)
{
BatchId = batchId,
});
var newLevel = Library.StaticLibrary.GrowthRates.CalculateLevel(Species.GrowthRate, Experience);
if (newLevel > Level)
{
Level = newLevel;
RecalculateFlatStats();
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level));
BattleData?.Battle.EventHook.Invoke(new LevelUpEvent(this, oldLevel, Level)
{
BatchId = batchId,
});
if (newLevel >= maxLevel)
{
@@ -511,6 +530,9 @@ public class PokemonImpl : ScriptSource, IPokemon
/// <inheritdoc />
public byte Coloring { get; }
/// <inheritdoc />
public bool IsShiny => Coloring == 1;
/// <inheritdoc />
public IItem? HeldItem { get; private set; }
@@ -568,6 +590,17 @@ public class PokemonImpl : ScriptSource, IPokemon
/// <inheritdoc />
public bool HasMove(StringKey moveName) => Moves.Any(move => move?.MoveData.Name == moveName);
/// <inheritdoc />
public void SwapMoves(byte index1, byte index2)
{
if (index1 >= Const.MovesCount || index2 >= Const.MovesCount)
return;
var move1 = _learnedMoves[index1];
var move2 = _learnedMoves[index2];
_learnedMoves[index1] = move2;
_learnedMoves[index2] = move1;
}
/// <inheritdoc />
public bool AllowedExperience { get; set; }