using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
///
/// Inner Focus is an ability that prevents the Pokémon from flinching.
///
/// Bulbapedia - Inner Focus
///
[Script(ScriptCategory.Ability, "inner_focus")]
public class InnerFocus : Script
{
private IPokemon? _pokemon;
///
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Illusion can only be added to a Pokemon script source.");
_pokemon = pokemon;
}
///
public override void PreventVolatileAdd(Script script, ref bool preventVolatileAdd)
{
if (script is not FlinchEffect)
return;
_pokemon?.BattleData?.Battle.EventHook.Invoke(new AbilityTriggerEvent(_pokemon));
preventVolatileAdd = true;
}
}