Deukhoofd 1feb27e826
All checks were successful
Build / Build (push) Successful in 50s
More work on refactor to interfaces
2025-06-29 12:03:51 +02:00

40 lines
1.2 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>
/// Hydration is an ability that heals status conditions if it is raining at the end of the turn.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Hydration_(Ability)">Bulbapedia - Hydration</see>
/// </summary>
[Script(ScriptCategory.Ability, "hydration")]
public class Hydration : Script, IScriptOnEndTurn
{
private IPokemon? _pokemon;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new InvalidOperationException("Hydration can only be added to a Pokemon script source.");
_pokemon = pokemon;
}
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
if (_pokemon is null)
return;
if (battle.WeatherName != ScriptUtils.ResolveName<Weather.Rain>())
return;
if (_pokemon.StatusScript.IsEmpty)
return;
EventBatchId batchId = new();
battle.EventHook.Invoke(new AbilityTriggerEvent(_pokemon)
{
BatchId = batchId,
});
_pokemon.ClearStatus(batchId);
}
}