namespace PkmnLib.Plugin.Gen7.Scripts.Abilities; /// /// Emergency Exit is an ability that makes the Pokémon switch out when its HP drops below half. /// This ability is similar to Wimp Out and is exclusive to Golisopod. /// /// Bulbapedia - Emergency Exit /// [Script(ScriptCategory.Ability, "emergency_exit")] public class EmergencyExit : Script, IScriptOnDamage { /// public void OnDamage(IBattlePokemon pokemon, DamageSource source, uint oldHealth, uint newHealth) { if (source is DamageSource.Confusion) return; var oldHealthFraction = (float)oldHealth / pokemon.MaxHealth; var newHealthFraction = (float)newHealth / pokemon.MaxHealth; if (!(oldHealthFraction >= 0.5f) || !(newHealthFraction < 0.5f)) return; if (pokemon.Battle.IsWildBattle) { pokemon.Battle.ForceEndBattle(); return; } pokemon.BattleSide.SwapPokemon(pokemon.Position, null); } }