using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "mirror_coat")]
public class MirrorCoat : Script, IScriptOnBeforeTurnStart, IScriptChangeTargets, IScriptChangeMoveDamage
{
///
public void OnBeforeTurnStart(ITurnChoice choice)
{
choice.User.Volatile.Add(new MirrorCoatHelper());
}
///
public void ChangeTargets(IMoveChoice moveChoice, ref IReadOnlyList targets)
{
var helper = moveChoice.User.Volatile.Get();
var lastAttacker = helper?.LastAttacker;
if (lastAttacker == null)
{
moveChoice.Fail();
return;
}
targets = [lastAttacker];
}
///
public void ChangeMoveDamage(IExecutingMove move, IPokemon target, byte hit, ref uint damage)
{
var helper = move.User.Volatile.Get();
if (helper?.LastAttacker == null || helper.LastAttacker != target)
{
move.GetHitData(target, hit).Fail();
return;
}
damage = Math.Max(helper.LastDamage.MultiplyOrMax(2f), 1);
}
[Script(ScriptCategory.Pokemon, "mirror_coat_helper")]
private class MirrorCoatHelper : Script, IScriptOnIncomingHit, IScriptOnEndTurn
{
public IPokemon? LastAttacker { get; set; }
public uint LastDamage { get; set; }
///
public void OnIncomingHit(IExecutingMove move, IPokemon target, byte hit)
{
if (move.UseMove.Category != MoveCategory.Special)
return;
LastAttacker = move.User;
LastDamage = move.GetHitData(target, hit).Damage;
}
///
public void OnEndTurn(IScriptSource owner, IBattle battle)
{
RemoveSelf();
}
}
}