using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Scripts;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Side;
using PkmnLib.Plugin.Gen7.Scripts.Weather;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
///
/// Tests for the move script.
/// Gen VII Bulbapedia behavior: "Aurora Veil reduces the damage done to the user by physical and special
/// moves for five turns [...]. The move cannot be activated unless hail [...] is present. [...] Holding
/// Light Clay extends the duration from 5 to 8 turns."
///
public class AuroraVeilTests
{
///
/// Test helper script that extends the Aurora Veil duration through the custom trigger, the same way the
/// Light Clay item script does.
///
[Script(ScriptCategory.Pokemon, "test_aurora_veil_duration_extender")]
private class DurationExtender : Script, IScriptCustomTrigger
{
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.AuroraVeilDuration && args is CustomTriggers.AuroraVeilDurationArgs d)
d.Duration = 8;
}
}
private static (AuroraVeil script, IExecutingMove move, IPokemon target, IPokemon user, IScriptSet sideScripts,
IHitData hitData) CreateTestSetup(StringKey? weather)
{
var script = new AuroraVeil();
var move = Substitute.For();
var target = Substitute.For();
var hitData = Substitute.For();
move.GetHitData(target, 0).Returns(hitData);
var battle = Substitute.For();
battle.WeatherName.Returns(weather);
var sideScripts = Substitute.For();
// Mimic the real ScriptSet: invoke the factory and hand back a container holding the new script.
sideScripts.StackOrAdd(Arg.Any(), Arg.Any>())
.Returns(ci => new ScriptContainer(ci.Arg>()()!));
var side = Substitute.For();
side.VolatileScripts.Returns(sideScripts);
battle.Sides.Returns(new[] { side });
var battleData = Substitute.For();
battleData.Battle.Returns(battle);
battleData.SideIndex.Returns((byte)0);
var user = Substitute.For();
user.BattleData.Returns(battleData);
user.GetScripts().Returns(_ => new ScriptIterator(new List>()));
move.User.Returns(user);
return (script, move, target, user, sideScripts, hitData);
}
///
/// Helper to extract the effect script instance created through StackOrAdd on the side's volatile scripts.
///
private static AuroraVeilEffect? GetAddedEffect(IScriptSet sideScripts)
{
var call = sideScripts.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "StackOrAdd");
if (call == null)
return null;
var factory = (Func