Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -8,28 +8,28 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
|
||||
[Script(ScriptCategory.Ability, "schooling")]
|
||||
public class Schooling : Script, IScriptOnEndTurn, IScriptOnSwitchIn
|
||||
{
|
||||
private IPokemon? _owningPokemon;
|
||||
private IBattlePokemon? _owningPokemon;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
if (source is not IPokemon pokemon)
|
||||
if (source is not IBattlePokemon pokemon)
|
||||
throw new ArgumentException("Schooling script must be added to a Pokemon.", nameof(source));
|
||||
_owningPokemon = pokemon;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnSwitchIn(IPokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon);
|
||||
public void OnSwitchIn(IBattlePokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void OnEndTurn(IScriptSource owner, IBattle battle) => ChangeFormIfNeeded(_owningPokemon);
|
||||
|
||||
private static void ChangeFormIfNeeded(IPokemon? pokemon)
|
||||
private static void ChangeFormIfNeeded(IBattlePokemon? pokemon)
|
||||
{
|
||||
if (pokemon is null)
|
||||
return;
|
||||
|
||||
if (pokemon.Species.Name != SpeciesNames.Wishiwashi || pokemon.BattleData?.Battle == null)
|
||||
if (pokemon.Species.Name != SpeciesNames.Wishiwashi || pokemon.Battle == null)
|
||||
return;
|
||||
// If Wishiwashi has less than 25% health, change to Solo form
|
||||
if (pokemon.CurrentHealth < pokemon.MaxHealth / 4 && pokemon.Form.Name != FormNames.Default)
|
||||
|
||||
Reference in New Issue
Block a user