Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -16,8 +16,8 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
||||
/// </summary>
|
||||
public class CurseTests
|
||||
{
|
||||
private static (Curse script, IExecutingMove move, IPokemon user, IPokemon target, IScriptSet targetVolatile)
|
||||
CreateTestSetup(bool userIsGhost, uint userMaxHealth = 100, uint userCurrentHealth = 100)
|
||||
private static (Curse script, IExecutingMove move, IBattlePokemon user, IBattlePokemon target, IScriptSet
|
||||
targetVolatile) CreateTestSetup(bool userIsGhost, uint userMaxHealth = 100, uint userCurrentHealth = 100)
|
||||
{
|
||||
var script = new Curse();
|
||||
var library = LibraryHelpers.LoadLibrary();
|
||||
@@ -26,18 +26,16 @@ public class CurseTests
|
||||
|
||||
var battle = Substitute.For<IBattle>();
|
||||
battle.Library.Returns(library);
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
|
||||
var user = Substitute.For<IPokemon>();
|
||||
user.BattleData.Returns(battleData);
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
user.Types.Returns(new[] { userIsGhost ? ghostType : normalType });
|
||||
user.Battle.Returns(battle);
|
||||
user.MaxHealth.Returns(userMaxHealth);
|
||||
user.CurrentHealth.Returns(userCurrentHealth);
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
move.User.Returns(user);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
// Use a real script set so the curse applied to the target can be inspected afterwards.
|
||||
var targetVolatile = new ScriptSet(target);
|
||||
target.Volatile.Returns(targetVolatile);
|
||||
@@ -49,7 +47,7 @@ public class CurseTests
|
||||
/// <summary>
|
||||
/// Helper that checks whether a stat boost change was applied to the given Pokémon.
|
||||
/// </summary>
|
||||
private static bool ReceivedStatBoost(IPokemon pokemon, Statistic stat, sbyte amount) =>
|
||||
private static bool ReceivedStatBoost(IBattlePokemon pokemon, Statistic stat, sbyte amount) =>
|
||||
pokemon.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "ChangeStatBoost" &&
|
||||
(Statistic)c.GetArguments()[0]! == stat &&
|
||||
(sbyte)c.GetArguments()[1]! == amount);
|
||||
@@ -57,7 +55,7 @@ public class CurseTests
|
||||
/// <summary>
|
||||
/// Helper to extract the damage amount from a substitute's received Damage calls.
|
||||
/// </summary>
|
||||
private static uint? GetDamageAmount(IPokemon pokemon)
|
||||
private static uint? GetDamageAmount(IBattlePokemon pokemon)
|
||||
{
|
||||
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Damage");
|
||||
return call != null ? (uint)call.GetArguments()[0]! : null;
|
||||
@@ -178,7 +176,7 @@ public class CurseTests
|
||||
public async Task GhostCurseEffect_OnEndTurnAtFullHp_CursedPokemonLosesQuarterOfMaximumHp()
|
||||
{
|
||||
// Arrange
|
||||
var cursed = Substitute.For<IPokemon>();
|
||||
var cursed = Substitute.For<IBattlePokemon>();
|
||||
cursed.MaxHealth.Returns(100u);
|
||||
cursed.CurrentHealth.Returns(100u);
|
||||
var effect = new GhostCurseEffect(cursed);
|
||||
@@ -198,7 +196,7 @@ public class CurseTests
|
||||
public async Task GhostCurseEffect_OnEndTurnAtLowHp_CursedPokemonStillLosesQuarterOfMaximumHp()
|
||||
{
|
||||
// Arrange
|
||||
var cursed = Substitute.For<IPokemon>();
|
||||
var cursed = Substitute.For<IBattlePokemon>();
|
||||
cursed.MaxHealth.Returns(100u);
|
||||
cursed.CurrentHealth.Returns(40u);
|
||||
var effect = new GhostCurseEffect(cursed);
|
||||
|
||||
Reference in New Issue
Block a user