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>
/// Rain Dish is an ability that heals the Pokémon for 1/16 of its maximum HP each turn during rain.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Rain_Dish_(Ability)">Bulbapedia - Rain Dish</see>
/// </summary>
[Script(ScriptCategory.Ability, "rain_dish")]
public class RainDish : Script, IScriptOnEndTurn
{
private IPokemon? _owner;
/// <inheritdoc />
public override void OnAddedToParent(IScriptSource source)
{
if (source is not IPokemon pokemon)
throw new ArgumentException("RainDish script can only be added to a Pokemon.", nameof(source));
_owner = pokemon;
}
/// <inheritdoc />
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
if (_owner is null)
return;
if (battle.WeatherName != ScriptUtils.ResolveName<Weather.Rain>())
return;
var healAmount = _owner.MaxHealth / 16;
if (healAmount <= 0)
return;
EventBatchId batchId = new();
battle.EventHook.Invoke(new AbilityTriggerEvent(_owner)
{
BatchId = batchId,
});
_owner.Heal(healAmount, batchId: batchId);
}
}