Work on item use/evolutions
All checks were successful
Build / Build (push) Successful in 1m7s

This commit is contained in:
2025-08-18 11:57:03 +02:00
parent e5041ec5f0
commit f061ba2455
7 changed files with 157 additions and 12 deletions

View File

@@ -204,7 +204,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// <summary>
/// Marks the Pokemon as caught. This makes it so that the Pokemon is not considered valid in battle anymore.
/// </summary>
public void MarkAsCaught();
void MarkAsCaught();
/// <summary>
/// The script for the held item.
@@ -293,7 +293,7 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// <summary>
/// Suppresses the ability of the Pokémon.
/// </summary>
public void SuppressAbility();
void SuppressAbility();
/// <summary>
/// Returns the currently active ability.
@@ -313,15 +313,21 @@ public interface IPokemon : IScriptSource, IDeepCloneable
/// </summary>
void RecalculateBoostedStats();
/// <summary>
/// Evolves the Pokemon to a specific evolution. This will not check whether the evolution is valid, so
/// you should check that before calling this method.
/// </summary>
bool EvolveTo(IEvolution evolution, EventHook? eventHook = null);
/// <summary>
/// Change the species of the Pokemon.
/// </summary>
void ChangeSpecies(ISpecies species, IForm form);
void ChangeSpecies(ISpecies species, IForm form, EventHook? eventHook = null);
/// <summary>
/// Change the form of the Pokemon.
/// </summary>
void ChangeForm(IForm form, EventBatchId batchId = default);
void ChangeForm(IForm form, EventBatchId batchId = default, EventHook? eventHook = null);
/// <summary>
/// Whether the Pokemon is useable in a battle.
@@ -606,7 +612,7 @@ public class PokemonImpl : ScriptSource, IPokemon
public IDynamicLibrary Library { get; }
/// <inheritdoc />
public ISpecies Species { get; }
public ISpecies Species { get; private set; }
/// <inheritdoc />
public IForm Form { get; private set; }
@@ -985,8 +991,25 @@ public class PokemonImpl : ScriptSource, IPokemon
public void RecalculateBoostedStats() => Library.StatCalculator.CalculateBoostedStats(this, BoostedStats);
/// <inheritdoc />
public void ChangeSpecies(ISpecies species, IForm form)
public bool EvolveTo(IEvolution evolution, EventHook? eventHook = null)
{
if (!Species.EvolutionData.Contains(evolution))
return false;
if (!Library.StaticLibrary.Species.TryGet(evolution.ToSpecies, out var species))
return false;
// TODO: Consider how forms work with evolution items.
var newForm = species.GetDefaultForm();
eventHook?.Invoke(new EvolutionEvent(this, Species, Form, species, newForm, evolution));
ChangeSpecies(species, newForm, eventHook);
return true;
}
/// <inheritdoc />
public void ChangeSpecies(ISpecies species, IForm form, EventHook? eventHook = null)
{
eventHook ??= BattleData?.Battle.EventHook;
if (Species == species)
{
if (form != Form)
@@ -1007,18 +1030,20 @@ public class PokemonImpl : ScriptSource, IPokemon
}
var batchId = new EventBatchId();
BattleData?.Battle.EventHook.Invoke(new SpeciesChangeEvent(this, species, form)
eventHook?.Invoke(new SpeciesChangeEvent(this, species, form)
{
BatchId = batchId,
});
Species = species;
ChangeForm(form, batchId);
}
/// <inheritdoc />
public void ChangeForm(IForm form, EventBatchId batchId = default)
public void ChangeForm(IForm form, EventBatchId batchId = default, EventHook? eventHook = null)
{
if (form == Form)
return;
eventHook ??= BattleData?.Battle.EventHook;
var oldAbility = Form.GetAbility(AbilityIndex);
@@ -1068,7 +1093,7 @@ public class PokemonImpl : ScriptSource, IPokemon
// TODO: form specific moves?
BattleData?.Battle.EventHook.Invoke(new FormChangeEvent(this, form)
eventHook?.Invoke(new FormChangeEvent(this, form)
{
BatchId = batchId,
});