Implements Hail
This commit is contained in:
@@ -1,10 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using PkmnLib.Dynamic.Events;
|
||||
using PkmnLib.Dynamic.Models;
|
||||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
|
||||
|
||||
[Script(ScriptCategory.Weather, "hail")]
|
||||
public class Hail : Script
|
||||
{
|
||||
// TODO: Implement Hail weather effect
|
||||
public static void RegisterHailIgnoreAbility(StringKey abilityName)
|
||||
{
|
||||
_hailIgnoreAbilities.Add(abilityName);
|
||||
}
|
||||
|
||||
private static readonly HashSet<StringKey> _hailIgnoreAbilities =
|
||||
[
|
||||
"ice_body",
|
||||
"magic_guard",
|
||||
"overcoat",
|
||||
"snow_cloak"
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
{
|
||||
if (!battle.Library.StaticLibrary.Types.TryGetTypeIdentifier("ice", out var iceType))
|
||||
{
|
||||
iceType = new TypeIdentifier(255);
|
||||
}
|
||||
foreach (var side in battle.Sides)
|
||||
{
|
||||
foreach (var pokemon in side.Pokemon.WhereNotNull())
|
||||
{
|
||||
if (!pokemon.IsUsable)
|
||||
continue;
|
||||
if (pokemon.Types.Contains(iceType))
|
||||
continue;
|
||||
if (_hailIgnoreAbilities.Contains(pokemon.ActiveAbility.Name))
|
||||
continue;
|
||||
|
||||
var maxHealth = pokemon.BoostedStats.Hp;
|
||||
var damage = maxHealth / 16;
|
||||
// TODO: Consider Safety Goggles. Handle it inside the Damage method?
|
||||
pokemon.Damage(damage, DamageSource.Weather, new EventBatchId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user