Tweaks for setting weather
This commit is contained in:
32
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SetWeather.cs
Normal file
32
Plugins/PkmnLib.Plugin.Gen7/Scripts/Moves/SetWeather.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
|
||||
|
||||
[Script(ScriptCategory.Move, "set_weather")]
|
||||
public class SetWeather : Script
|
||||
{
|
||||
private string _weather = null!;
|
||||
private int _defaultTurns = 5;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
|
||||
{
|
||||
if (!parameters!.TryGetValue("weather", out var weather) || weather is null)
|
||||
{
|
||||
throw new Exception("Weather not provided.");
|
||||
}
|
||||
_weather = weather!.ToString();
|
||||
if (parameters.TryGetValue("turns", out var turns) && turns is int turn)
|
||||
{
|
||||
_defaultTurns = turn;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
|
||||
{
|
||||
target.BattleData?.Battle.SetWeather(_weather, _defaultTurns);
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,15 @@ using PkmnLib.Static.Utils;
|
||||
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
|
||||
|
||||
[Script(ScriptCategory.Weather, "hail")]
|
||||
public class Hail : Script
|
||||
public class Hail : Script, IWeatherScript
|
||||
{
|
||||
public static void RegisterHailIgnoreAbility(StringKey abilityName)
|
||||
{
|
||||
_hailIgnoreAbilities.Add(abilityName);
|
||||
}
|
||||
private int? _duration;
|
||||
|
||||
private static readonly HashSet<StringKey> _hailIgnoreAbilities =
|
||||
[
|
||||
"ice_body",
|
||||
"magic_guard",
|
||||
"overcoat",
|
||||
"snow_cloak",
|
||||
];
|
||||
/// <inheritdoc />
|
||||
public void SetTurns(int turns)
|
||||
{
|
||||
_duration = turns;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnEndTurn(IBattle battle)
|
||||
@@ -36,14 +31,22 @@ public class Hail : Script
|
||||
continue;
|
||||
if (pokemon.Types.Contains(iceType))
|
||||
continue;
|
||||
if (pokemon.ActiveAbility != null && _hailIgnoreAbilities.Contains(pokemon.ActiveAbility.Name))
|
||||
var ignoresHail = false;
|
||||
pokemon.RunScriptHook(x => x.CustomTrigger("ignores_hail", new Dictionary<StringKey, object?>()
|
||||
{
|
||||
{ "ignoresHail", ignoresHail },
|
||||
}));
|
||||
if (ignoresHail)
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
_duration--;
|
||||
if (_duration <= 0)
|
||||
RemoveSelf();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user