Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -13,16 +13,16 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
||||
/// </summary>
|
||||
public class BideTests
|
||||
{
|
||||
private static (Bide script, IExecutingMove move, IPokemon user, IPokemon target, IScriptSet userVolatile, IHitData
|
||||
hitData) CreateTestSetup()
|
||||
private static (Bide script, IExecutingMove move, IBattlePokemon user, IBattlePokemon target, IScriptSet
|
||||
userVolatile, IHitData hitData) CreateTestSetup()
|
||||
{
|
||||
var script = new Bide();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
var hitData = Substitute.For<IHitData>();
|
||||
move.GetHitData(target, 0).Returns(hitData);
|
||||
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
user.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
// A real script set so the volatile Bide effect can actually be added, retrieved and removed.
|
||||
var userVolatile = new ScriptSet(user);
|
||||
@@ -32,12 +32,10 @@ public class BideTests
|
||||
return (script, move, user, target, userVolatile, hitData);
|
||||
}
|
||||
|
||||
private static IPokemon CreateAttacker(bool onBattlefield = true)
|
||||
private static IBattlePokemon CreateAttacker(bool onBattlefield = true)
|
||||
{
|
||||
var attacker = Substitute.For<IPokemon>();
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.IsOnBattlefield.Returns(onBattlefield);
|
||||
attacker.BattleData.Returns(battleData);
|
||||
var attacker = Substitute.For<IBattlePokemon>();
|
||||
attacker.IsOnBattlefield.Returns(onBattlefield);
|
||||
return attacker;
|
||||
}
|
||||
|
||||
@@ -45,8 +43,8 @@ public class BideTests
|
||||
/// Adds a <see cref="BideEffect"/> to the user's volatile scripts, as if Bide has already been storing
|
||||
/// energy for the given number of executed turns.
|
||||
/// </summary>
|
||||
private static BideEffect AddStoredBideEffect(IScriptSet userVolatile, IPokemon user, byte turns, uint damageTaken,
|
||||
params IPokemon[] hitBy)
|
||||
private static BideEffect AddStoredBideEffect(IScriptSet userVolatile, IBattlePokemon user, byte turns,
|
||||
uint damageTaken, params IBattlePokemon[] hitBy)
|
||||
{
|
||||
var effect = new BideEffect(user)
|
||||
{
|
||||
@@ -61,13 +59,13 @@ public class BideTests
|
||||
/// <summary>
|
||||
/// Helper to check whether a Pokémon received any Damage call.
|
||||
/// </summary>
|
||||
private static bool ReceivedDamage(IPokemon pokemon) =>
|
||||
private static bool ReceivedDamage(IBattlePokemon pokemon) =>
|
||||
pokemon.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Damage");
|
||||
|
||||
/// <summary>
|
||||
/// Helper to extract the damage amount from a Pokémon'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;
|
||||
@@ -76,7 +74,7 @@ public class BideTests
|
||||
/// <summary>
|
||||
/// Helper to extract the damage source from a Pokémon's received Damage calls.
|
||||
/// </summary>
|
||||
private static DamageSource? GetDamageSource(IPokemon pokemon)
|
||||
private static DamageSource? GetDamageSource(IBattlePokemon pokemon)
|
||||
{
|
||||
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Damage");
|
||||
return call != null ? (DamageSource)call.GetArguments()[1]! : null;
|
||||
@@ -245,7 +243,7 @@ public class BideTests
|
||||
public async Task BideEffect_OnDamage_AccumulatesDamageTaken()
|
||||
{
|
||||
// Arrange
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var effect = new BideEffect(user);
|
||||
|
||||
// Act - the user drops from 100 to 60 HP, then from 60 to 50 HP
|
||||
@@ -265,10 +263,10 @@ public class BideTests
|
||||
public async Task BideEffect_OnIncomingHit_RecordsAttacker()
|
||||
{
|
||||
// Arrange
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var effect = new BideEffect(user);
|
||||
var incomingMove = Substitute.For<IExecutingMove>();
|
||||
var attacker = Substitute.For<IPokemon>();
|
||||
var attacker = Substitute.For<IBattlePokemon>();
|
||||
incomingMove.User.Returns(attacker);
|
||||
|
||||
// Act
|
||||
|
||||
Reference in New Issue
Block a user