59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
|
|
|
|
[Script(ScriptCategory.Weather, "rain")]
|
|
public class Rain : Script, ILimitedTurnsScript, IScriptChangeBasePower, IScriptOnEndTurn, IScriptChangeAccuracy
|
|
{
|
|
private int? _duration;
|
|
|
|
/// <inheritdoc />
|
|
public int TurnsRemaining => _duration ?? 0;
|
|
|
|
/// <inheritdoc />
|
|
public void SetTurns(int turns)
|
|
{
|
|
_duration = turns;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual void OnEndTurn(IScriptSource owner, IBattle battle)
|
|
{
|
|
_duration--;
|
|
if (_duration <= 0)
|
|
{
|
|
battle.SetWeather(null, 0);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ChangeBasePower(IExecutingMove move, IBattlePokemon target, byte hit, ref ushort basePower)
|
|
{
|
|
var hitType = move.GetHitData(target, hit).Type;
|
|
if (hitType?.Name == TypeNames.Water)
|
|
{
|
|
// Increase Water-type move power by 50% in rain
|
|
basePower = (ushort)(basePower * 1.5);
|
|
}
|
|
else if (hitType?.Name == TypeNames.Fire)
|
|
{
|
|
// Decrease Fire-type move power by 50% in rain
|
|
basePower = (ushort)(basePower * 0.5);
|
|
}
|
|
}
|
|
|
|
// These moves are not part of the gen 7 data files, so no generated constants exist for them.
|
|
private static readonly StringKey BleakwindStormName = "bleakwind_storm";
|
|
private static readonly StringKey WindboltStormName = "windbolt_storm";
|
|
private static readonly StringKey SandsearStormName = "sandsear_storm";
|
|
|
|
/// <inheritdoc />
|
|
public void ChangeAccuracy(IExecutingMove executingMove, IBattlePokemon target, byte hitIndex,
|
|
ref int modifiedAccuracy)
|
|
{
|
|
var moveName = executingMove.UseMove.Name;
|
|
if (moveName == MoveNames.Thunder || moveName == MoveNames.Hurricane || moveName == BleakwindStormName ||
|
|
moveName == WindboltStormName || moveName == SandsearStormName)
|
|
{
|
|
modifiedAccuracy = 1000;
|
|
}
|
|
}
|
|
} |