Files
PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7/Scripts/Weather/StrongWinds.cs

50 lines
1.7 KiB
C#

namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
/// <summary>
/// StrongWinds is a weather condition that represents strong winds in battle.
///
/// <see href="https://bulbapedia.bulbagarden.net/wiki/Strong_winds">Bulbapedia - Strong Winds</see>
/// </summary>
[Script(ScriptCategory.Weather, "strong_winds")]
public class StrongWinds : Script, IScriptOnSwitchOut, IScriptChangeTypesForMove, IScriptPreventWeatherChange
{
private HashSet<IBattlePokemon> _placers = new();
public void MarkAsPlaced(IBattlePokemon pokemon)
{
_placers.Add(pokemon);
}
/// <inheritdoc />
public void OnSwitchOut(IBattlePokemon oldPokemon, byte position)
{
_placers.Remove(oldPokemon);
if (_placers.Count == 0)
oldPokemon.Battle.SetWeather(null, 0);
}
/// <inheritdoc />
public void PreventWeatherChange(StringKey? weatherName, ref bool preventWeatherChange)
{
if (weatherName == ScriptUtils.ResolveName<DesolateLands>() ||
weatherName == ScriptUtils.ResolveName<PrimordialSea>())
return;
preventWeatherChange = true;
}
/// <inheritdoc />
public void ChangeTypesForMove(IExecutingMove executingMove, IBattlePokemon target, byte hitIndex,
IList<TypeIdentifier> types)
{
var flyingType = types.FirstOrDefault(x => x.Name == TypeNames.Flying);
if (flyingType != null)
{
var typeLibrary = executingMove.Battle.Library.StaticLibrary.Types;
var hitData = executingMove.GetHitData(target, hitIndex);
if (hitData.Type != null && typeLibrary.GetSingleEffectiveness(hitData.Type.Value, flyingType) > 1)
{
types.Remove(flyingType);
}
}
}
}