52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
|
|
|
|
[Script(ScriptCategory.Weather, "sandstorm")]
|
|
public class Sandstorm : Script, IScriptChangeBasePower, IScriptChangeDefensiveStatValue, IScriptOnEndTurn,
|
|
IAIInfoScriptExpectedEndOfTurnDamage
|
|
{
|
|
/// <inheritdoc />
|
|
public 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 == TypeNames.Rock || x.Name == TypeNames.Ground || x.Name == TypeNames.Steel))
|
|
{
|
|
// Rock, Ground, and Steel types are immune to Sandstorm damage.
|
|
continue;
|
|
}
|
|
var bypassSandstormArgs = new CustomTriggers.BypassSandstormDamageArgs(pokemon);
|
|
pokemon.RunScriptHook<IScriptCustomTrigger>(x =>
|
|
x.CustomTrigger(CustomTriggers.BypassSandstormDamage, bypassSandstormArgs));
|
|
if (bypassSandstormArgs.Bypass)
|
|
continue;
|
|
|
|
pokemon.Damage(pokemon.MaxHealth / 16, DamageSource.Weather);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public 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 == TypeNames.Rock))
|
|
value = value.MultiplyOrMax(1.5f);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ChangeBasePower(IExecutingMove move, IPokemon target, byte hit, ref ushort basePower)
|
|
{
|
|
if (move.UseMove.Name == MoveNames.SolarBeam)
|
|
basePower /= 2;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ExpectedEndOfTurnDamage(IPokemon pokemon, ref int damage)
|
|
{
|
|
if (pokemon.Types.Any(x => x.Name == TypeNames.Rock || x.Name == TypeNames.Ground || x.Name == TypeNames.Steel))
|
|
return; // Rock, Ground, and Steel types are immune to Sandstorm damage.
|
|
damage += (int)(pokemon.MaxHealth / 16f);
|
|
}
|
|
} |