From 4e79c83784ec4ab370d58af7aee0ba6c051d2162 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 5 Mar 2021 15:12:47 +0400 Subject: [PATCH] Test framework: fixed missing range info for added cards (some ETB effects were broken on "put to battlefield" command usage); --- .../test/java/org/mage/test/player/TestPlayer.java | 5 +++++ .../serverside/base/impl/CardTestPlayerAPIImpl.java | 5 +++++ .../src/test/java/org/mage/test/stub/PlayerStub.java | 5 +++++ Mage/src/main/java/mage/players/Player.java | 2 ++ Mage/src/main/java/mage/players/PlayerImpl.java | 12 ++++++++++-- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index ef3f411c73..1b97fb3b71 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -3023,6 +3023,11 @@ public class TestPlayer implements Player { computerPlayer.untap(game); } + @Override + public void updateRange(Game game) { + computerPlayer.updateRange(game); + } + @Override public UUID getId() { return computerPlayer.getId(); diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java index c8cd5cb4c5..0ff795c71f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestPlayerAPIImpl.java @@ -298,6 +298,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement (maxTurn > this.stopOnTurn) || (maxTurn == this.stopOnTurn && maxPhase > this.stopAtStep.getIndex())); if (!currentGame.isPaused()) { + // workaround to fill range info (cause real range fills after game start, but some cheated cards needs range on ETB) + for (Player player : currentGame.getPlayers().values()) { + player.updateRange(currentGame); + } + // add cards to game for (Player player : currentGame.getPlayers().values()) { TestPlayer testPlayer = (TestPlayer) player; currentGame.cheat(testPlayer.getId(), getCommands(testPlayer)); diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index fd808bb715..d28fa3c596 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -1030,6 +1030,11 @@ public class PlayerStub implements Player { } + @Override + public void updateRange(Game game) { + + } + @Override public ManaOptions getManaAvailable(Game game) { return null; diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index 39c5a0c678..4e24915afe 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -707,6 +707,8 @@ public interface Player extends MageItem, Copyable { void untap(Game game); + void updateRange(Game game); + ManaOptions getManaAvailable(Game game); void addAvailableTriggeredMana(List netManaAvailable); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 6594ad0897..35e8797956 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -483,7 +483,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void beginTurn(Game game) { this.landsPlayed = 0; - updateRangeOfInfluence(game); + updateRange(game); } @Override @@ -491,7 +491,8 @@ public abstract class PlayerImpl implements Player, Serializable { return range; } - protected void updateRangeOfInfluence(Game game) { + @Override + public void updateRange(Game game) { // 20100423 - 801.2c // 801.2c The particular players within each player’s range of influence are determined as each turn begins. inRange.clear(); @@ -523,6 +524,13 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public Set getInRange() { + if (inRange.isEmpty()) { + // runtime check: inRange filled on beginTurn, but unit tests adds cards by cheat engine before game starting, + // so inRange will be empty and some ETB effects can be broken (example: Spark Double puts direct to battlefield). + // Cheat engine already have a workaround, so that error must not be visible in normal situation. + throw new IllegalStateException("Wrong code usage (game is not started, but you call getInRange in some effects)."); + } + return inRange; }