namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
///
/// Shed Skin is an ability that gives the Pokémon a chance to heal from a status condition at the end of each turn.
///
/// Bulbapedia - Shed Skin
///
[Script(ScriptCategory.Ability, "shed_skin")]
public class ShedSkin : Script, IScriptOnEndTurn
{
private IPokemon? _owningPokemon;
///
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new ArgumentException("ShedSkin script must be added to a Pokemon.", nameof(source));
_owningPokemon = pokemon;
}
///
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
if (_owningPokemon is null || _owningPokemon.StatusScript.IsEmpty)
return;
if (battle.Random.GetInt(3) == 0)
{
EventBatchId batchId = new();
battle.EventHook.Invoke(new AbilityTriggerEvent(_owningPokemon)
{
BatchId = batchId,
});
_owningPokemon.ClearStatus(batchId);
}
}
}