51 lines
1.5 KiB
C#

using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "mirror_coat")]
public class MirrorCoat : Script
{
/// <inheritdoc />
public override void OnBeforeTurnStart(ITurnChoice choice)
{
choice.User.Volatile.Add(new MirrorCoatHelper());
}
/// <inheritdoc />
public override void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var helper = target.Volatile.Get<MirrorCoatHelper>();
if (helper?.LastAttacker == null || helper.LastAttacker != move.User)
{
move.GetHitData(target, hit).Fail();
return;
}
damage = helper.LastDamage.MultiplyOrMax(2f);
target.Volatile.Remove<MirrorCoatHelper>();
}
[Script(ScriptCategory.Pokemon, "mirror_coat_helper")]
private class MirrorCoatHelper : Script
{
public IPokemon? LastAttacker { get; set; }
public uint LastDamage { get; set; }
/// <inheritdoc />
public override void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
{
if (move.UseMove.Category != MoveCategory.Special)
return;
LastAttacker = move.User;
LastDamage = move.GetHitData(target, hit).Damage;
}
/// <inheritdoc />
public override void OnEndTurn(IBattle battle)
{
RemoveSelf();
}
}
}