Last couple abilities
This commit is contained in:
34
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs
Normal file
34
Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/ZenMode.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
|
||||
|
||||
/// <summary>
|
||||
/// Zen Mode is an ability that changes the Pokémon's form when its HP falls below half.
|
||||
///
|
||||
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Zen_Mode_(Ability)">Bulbapedia - Zen Mode</see>
|
||||
/// </summary>
|
||||
[Script(ScriptCategory.Ability, "zen_mode")]
|
||||
public class ZenMode : Script
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void OnSwitchIn(IPokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IScriptSource owner, IBattle battle) => ChangeFormIfNeeded(owner as IPokemon);
|
||||
|
||||
private static void ChangeFormIfNeeded(IPokemon? pokemon)
|
||||
{
|
||||
if (pokemon is null)
|
||||
return;
|
||||
|
||||
if (pokemon.Species.Name != "darmanitan" || pokemon.BattleData?.Battle == null)
|
||||
return;
|
||||
if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name != "zen" &&
|
||||
pokemon.Species.TryGetForm("zen", out var zenForm))
|
||||
{
|
||||
pokemon.ChangeForm(zenForm);
|
||||
}
|
||||
else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 2 && pokemon.Form.Name == "zen")
|
||||
{
|
||||
pokemon.ChangeForm(pokemon.Species.GetDefaultForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user