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.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
///
/// Tests for the move script and its side effect script
/// .
/// Gen VII Bulbapedia behavior: Light Screen halves the damage the user's side takes from special moves
/// for 5 turns; "When multiple Pokémon are present on the user's side, special damage reduces by one-third
/// instead of one-half." and "If Light Clay is held when Light Screen is used, it will extend the duration
/// of Light Screen from 5 to 8 turns."
///
public class LightScreenTests
{
///
/// Test helper script that extends the Light Screen duration through the custom trigger, the same way
/// the Light Clay item script does.
///
[Script(ScriptCategory.Pokemon, "test_light_screen_duration_extender")]
private class DurationExtender : Script, IScriptCustomTrigger
{
public void CustomTrigger(StringKey eventName, ICustomTriggerArgs args)
{
if (eventName == CustomTriggers.LightScreenNumberOfTurns &&
args is CustomTriggers.LightScreenNumberOfTurnsArgs d)
d.Duration = 8;
}
}
private static (LightScreen script, IExecutingMove move, IScriptSet sideScripts) CreateMoveSetup()
{
var script = new LightScreen();
var move = Substitute.For();
move.GetScripts().Returns(_ => new ScriptIterator(new List>()));
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);
var battleData = Substitute.For();
battleData.BattleSide.Returns(side);
var user = Substitute.For();
user.BattleData.Returns(battleData);
move.User.Returns(user);
return (script, move, sideScripts);
}
///
/// Helper to extract the effect script instance created through StackOrAdd on the side's volatile
/// scripts.
///
private static LightScreenEffect? GetAddedEffect(IScriptSet sideScripts)
{
var call = sideScripts.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "StackOrAdd");
if (call == null)
return null;
var factory = (Func