Fixes several moves

This commit is contained in:
Deukhoofd 2025-02-01 15:26:57 +01:00
parent 00fe08dcd4
commit 0669f15a98
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
10 changed files with 49 additions and 12 deletions

View File

@ -58,7 +58,7 @@ public class ScriptRegistry
var constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, var constructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
null, Type.EmptyTypes, null); null, Type.EmptyTypes, null);
if (constructor == null) if (constructor == null)
throw new ArgumentException($"Type {type} does not have a parameterless constructor."); return;
// We create a lambda that creates a new instance of the script type. // We create a lambda that creates a new instance of the script type.
// This is more performant than using Activator.CreateInstance. // This is more performant than using Activator.CreateInstance.

View File

@ -307,7 +307,7 @@
"category": "status", "category": "status",
"flags": [], "flags": [],
"effect": { "effect": {
"name": "SwapWithTarget" "name": "ally_switch"
} }
}, },
{ {
@ -644,7 +644,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "double_power_user_damaged_by_target_in_turn" "name": "double_power_if_target_damaged_in_turn"
} }
}, },
{ {
@ -2371,7 +2371,7 @@
"mirror" "mirror"
], ],
"effect": { "effect": {
"name": "raise_user_defense", "name": "change_user_defense",
"chance": 50, "chance": 50,
"parameters": { "parameters": {
"amount": 2 "amount": 2

View File

@ -0,0 +1,30 @@
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Tests.Integration;
namespace PkmnLib.Tests.DataTests;
public class MoveDataTests
{
[Test]
public async Task AllMoveEffectsHaveValidScripts()
{
var library = LibraryHelpers.LoadLibrary();
var moveLibrary = library.StaticLibrary.Moves;
foreach (var move in moveLibrary)
{
if (move.SecondaryEffect == null)
continue;
var scriptName = move.SecondaryEffect.Name;
try
{
await Assert.That(library.ScriptResolver.TryResolve(ScriptCategory.Move, scriptName,
move.SecondaryEffect.Parameters, out var script)).IsTrue();
}
catch (Exception e)
{
throw new AggregateException($"Failed to resolve script for move {move.Name} with effect {scriptName}", e);
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "ally_switch")]
public class AllySwitch : Script
{
// TODO: Implement the AllySwitch script.
}

View File

@ -3,6 +3,7 @@ using PkmnLib.Static;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves; namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "belch")]
public class Belch : Script public class Belch : Script
{ {
/// <inheritdoc /> /// <inheritdoc />

View File

@ -21,7 +21,7 @@ public class ChangeAllTargetStats : Script
{ {
throw new ArgumentException("Parameter 'amount' is required."); throw new ArgumentException("Parameter 'amount' is required.");
} }
_amount = (sbyte)amount; _amount = (sbyte)(int)amount;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -28,7 +28,7 @@ public abstract class ChangeTargetStats : Script
throw new ArgumentException("Parameter 'amount' is required."); throw new ArgumentException("Parameter 'amount' is required.");
} }
_amount = (sbyte)amount; _amount = (sbyte)(int)amount;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -28,7 +28,7 @@ public abstract class ChangeUserStats : Script
throw new ArgumentException("Parameter 'amount' is required."); throw new ArgumentException("Parameter 'amount' is required.");
} }
_amount = (sbyte)amount; _amount = (sbyte)(int)amount;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -7,10 +7,6 @@ public class BindEffect : Script
private int _turns; private int _turns;
private readonly float _percentOfMaxHealth; private readonly float _percentOfMaxHealth;
private BindEffect(float percentOfMaxHealth)
{
_percentOfMaxHealth = percentOfMaxHealth;
}
public BindEffect(IPokemon owner, int turns, float percentOfMaxHealth) public BindEffect(IPokemon owner, int turns, float percentOfMaxHealth)
{ {

View File

@ -19,7 +19,7 @@ public class DoomDesireEffect : Script
} }
} }
private readonly IBattleSide _side; private readonly IBattleSide? _side;
private List<Target> _targets = new(); private List<Target> _targets = new();
public DoomDesireEffect(IBattleSide side) public DoomDesireEffect(IBattleSide side)
@ -40,6 +40,9 @@ public class DoomDesireEffect : Script
/// <inheritdoc /> /// <inheritdoc />
public override void OnEndTurn(IBattle battle) public override void OnEndTurn(IBattle battle)
{ {
if (_side == null)
return;
var toRemove = new List<Target>(); var toRemove = new List<Target>();
foreach (var v in _targets) foreach (var v in _targets)
{ {