Files
PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Abilities/PowerConstruct.cs

37 lines
1.3 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Power Construct is an ability that allows Zygarde to change form when its HP drops below half.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Power_Construct_(Ability)">Bulbapedia - Power Construct</see>
/// </summary>
[Script(ScriptCategory.Ability, "power_construct")]
public class PowerConstruct : Script, IScriptOnEndTurn
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("PowerConstruct script must be attached to a Pokemon.");
_pokemon = pokemon;
}
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
if (_pokemon?.BattleData?.Battle == null)
return;
if (_pokemon.Species.Name != SpeciesNames.Zygarde)
return;
if (_pokemon.CurrentHealth > _pokemon.BoostedStats.Hp / 2)
return;
if (_pokemon.Form.Name != FormNames._10 || _pokemon.Form.Name != FormNames._50)
return;
if (!_pokemon.Species.TryGetForm(FormNames.Complete, out var completeForm))
return;
_pokemon.ChangeForm(completeForm);
}
}