namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; /// /// Shields Down is an ability that changes Minior's form depending on its HP. /// /// Bulbapedia - Shields Down /// [Script(ScriptCategory.Ability, "shields_down")] public class ShieldsDown : Script, IScriptOnEndTurn, IScriptOnSwitchIn { /// public void OnSwitchIn(IBattlePokemon pokemon, byte position) => ChangeFormIfNeeded(pokemon); /// public void OnEndTurn(IScriptSource owner, IBattle battle) => ChangeFormIfNeeded(owner as IBattlePokemon); private static void ChangeFormIfNeeded(IBattlePokemon? pokemon) { if (pokemon is null) return; if (pokemon.Species.Name != SpeciesNames.Minior || pokemon.Battle == null) return; if (pokemon.CurrentHealth < pokemon.MaxHealth / 2 && pokemon.Form.Name.ToString().EndsWith("-meteor")) { var coreForm = pokemon.Form.Name.ToString().Replace("-meteor", ""); if (coreForm == "blue") coreForm = "default"; if (pokemon.Species.TryGetForm(coreForm, out var coreFormData)) { pokemon.ChangeForm(coreFormData); } } else if (pokemon.CurrentHealth >= pokemon.MaxHealth / 2 && pokemon.Form.Name.ToString().EndsWith("-meteor") == false) { var baseFormName = pokemon.Form.Name; if (baseFormName == FormNames.Default) baseFormName = "blue"; var meteorFormName = baseFormName + "-meteor"; if (pokemon.Species.TryGetForm(meteorFormName, out var meteorFormData)) { pokemon.ChangeForm(meteorFormData); } } } }