namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
///
/// Ice Body is an ability that heals the Pokémon for 1/16 of its maximum HP each turn during hail.
///
/// Bulbapedia - Ice Body
///
[Script(ScriptCategory.Ability, "ice_body")]
public class IceBody : Script
{
private IPokemon? _pokemon;
///
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Ice Body can only be added to a Pokemon script source.");
_pokemon = pokemon;
}
///
public override void OnEndTurn(IBattle battle)
{
if (_pokemon is null)
return;
// Check if the weather is hail
if (battle.WeatherName != ScriptUtils.ResolveName())
return;
// Heal the Pokémon for 1/16 of its maximum HP
EventBatchId batchId = new();
var healAmount = _pokemon.MaxHealth / 16;
_pokemon.Heal(healAmount, true, batchId);
// Trigger the ability event
battle.EventHook.Invoke(new AbilityTriggerEvent(_pokemon)
{
BatchId = batchId,
});
}
///
public override void CustomTrigger(StringKey eventName, IDictionary? parameters)
{
if (eventName != CustomTriggers.IgnoreHail || parameters is null)
return;
parameters["ignoresHail"] = true;
}
}