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

31 lines
1.0 KiB
C#

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