This commit is contained in:
45
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs
Normal file
45
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/Schooling.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
|
||||
|
||||
/// <summary>
|
||||
/// Schooling is an ability that changes Wishiwashi's form in battle.
|
||||
///
|
||||
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Schooling_(Ability)">Bulbapedia - Schooling</see>
|
||||
/// </summary>
|
||||
[Script(ScriptCategory.Ability, "schooling")]
|
||||
public class Schooling : Script
|
||||
{
|
||||
private IPokemon? _owningPokemon;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAddedToParent(IScriptSource source)
|
||||
{
|
||||
if (source is not IPokemon pokemon)
|
||||
throw new ArgumentException("Schooling script must be added to a Pokemon.", nameof(source));
|
||||
_owningPokemon = pokemon;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnSwitchIn(IPokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle) => ChangeFormIfNeeded(_owningPokemon);
|
||||
|
||||
private static void ChangeFormIfNeeded(IPokemon? pokemon)
|
||||
{
|
||||
if (pokemon is null)
|
||||
return;
|
||||
|
||||
if (pokemon.Species.Name != "wishiwashi" || pokemon.BattleData?.Battle == null)
|
||||
return;
|
||||
// If Wishiwashi has less than 25% health, change to Solo form
|
||||
if (pokemon.CurrentHealth < pokemon.MaxHealth / 4 && pokemon.Form.Name != "default")
|
||||
{
|
||||
pokemon.ChangeForm(pokemon.Species.GetDefaultForm());
|
||||
}
|
||||
else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 4 && pokemon.Form.Name != "school" &&
|
||||
pokemon.Species.TryGetForm("school", out var schoolForm))
|
||||
{
|
||||
pokemon.ChangeForm(schoolForm);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user