Implements sandstorm
All checks were successful
Build / Build (push) Successful in 50s

This commit is contained in:
Deukhoofd 2025-06-22 10:53:56 +02:00
parent 2533512eda
commit 02510fd1d0
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
6 changed files with 74 additions and 5 deletions

View File

@ -15,7 +15,11 @@ public class Overcoat : Script
{ {
hailArgs.Ignore = true; hailArgs.Ignore = true;
} }
// TODO: Ignore sandstorm damage else if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
{
bypassArgs.Bypass = true;
}
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -22,5 +22,13 @@ public class SandForce : Script
} }
} }
// TODO: Prevent sandstorm damage. /// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
{
bypassArgs.Bypass = true;
}
}
} }

View File

@ -17,5 +17,13 @@ public class SandRush : Script
} }
} }
// TODO: Prevent sandstorm damage. /// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
{
bypassArgs.Bypass = true;
}
}
} }

View File

@ -18,5 +18,13 @@ public class SandVeil : Script
modifiedAccuracy = (int)(modifiedAccuracy * (3277f / 4096f)); modifiedAccuracy = (int)(modifiedAccuracy * (3277f / 4096f));
} }
// TODO: Prevent sandstorm damage. /// <inheritdoc />
public override void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.BypassSandstormDamage &&
args is CustomTriggers.BypassSandstormDamageArgs bypassArgs)
{
bypassArgs.Bypass = true;
}
}
} }

View File

@ -139,4 +139,11 @@ public static class CustomTriggers
{ {
public bool Prevent { get; set; } = false; public bool Prevent { get; set; } = false;
} }
public static readonly StringKey BypassSandstormDamage = "bypass_sandstorm_damage";
public record BypassSandstormDamageArgs(IPokemon Pokemon) : ICustomTriggerArgs
{
public bool Bypass { get; set; } = false;
}
} }

View File

@ -3,5 +3,39 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "sandstorm")] [Script(ScriptCategory.Weather, "sandstorm")]
public class Sandstorm : Script public class Sandstorm : Script
{ {
// TODO: Implement Sandstorm /// <inheritdoc />
public override void OnEndTurn(IScriptSource owner, IBattle battle)
{
foreach (var pokemon in battle.Sides.SelectMany(x => x.Pokemon).WhereNotNull())
{
if (!pokemon.IsUsable)
continue;
if (pokemon.Types.Any(x => x.Name == "rock" || x.Name == "ground" || x.Name == "steel"))
{
// Rock, Ground, and Steel types are immune to Sandstorm damage.
continue;
}
var bypassSandstormArgs = new CustomTriggers.BypassSandstormDamageArgs(pokemon);
pokemon.RunScriptHook(x => x.CustomTrigger(CustomTriggers.BypassSandstormDamage, bypassSandstormArgs));
if (bypassSandstormArgs.Bypass)
continue;
pokemon.Damage(pokemon.MaxHealth / 16, DamageSource.Weather);
}
}
/// <inheritdoc />
public override void ChangeDefensiveStatValue(IExecutingMove move, IPokemon target, byte hit, uint offensiveStat,
ImmutableStatisticSet<uint> targetStats, Statistic stat, ref uint value)
{
if (stat == Statistic.SpecialDefense && target.Types.Any(x => x.Name == "rock"))
value = value.MultiplyOrMax(1.5f);
}
/// <inheritdoc />
public override void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
{
if (move.UseMove.Name == "solar_beam")
basePower /= 2;
}
} }