Deukhoofd 6d71de375e
All checks were successful
Build / Build (push) Successful in 48s
More abilities, refactor custom triggers to be typed.
2025-06-13 11:15:48 +02:00

49 lines
1.4 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "hail")]
public class Hail : Script, ILimitedTurnsScript
{
private int? _duration;
/// <inheritdoc />
public int TurnsRemaining => _duration ?? 0;
/// <inheritdoc />
public void SetTurns(int turns)
{
_duration = turns;
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType))
{
iceType = new TypeIdentifier(255, "non_existent");
}
foreach (var side in battle.Sides)
{
foreach (var pokemon in side.Pokemon.WhereNotNull())
{
if (!pokemon.IsUsable)
continue;
if (pokemon.Types.Contains(iceType))
continue;
var args = new CustomTriggers.IgnoreHailArgs(pokemon);
pokemon.RunScriptHook(x => x.CustomTrigger(CustomTriggers.IgnoreHail, args));
if (args.Ignore)
continue;
var maxHealth = pokemon.BoostedStats.Hp;
var damage = maxHealth / 16;
pokemon.Damage(damage, DamageSource.Weather, new EventBatchId());
}
}
_duration--;
if (_duration <= 0)
{
battle.SetWeather(null, 0);
}
}
}