Test framework: fixed missing range info for added cards (some ETB effects were broken on "put to battlefield" command usage);

This commit is contained in:
Oleg Agafonov 2021-03-05 15:12:47 +04:00
parent 654c0be1ac
commit 4e79c83784
5 changed files with 27 additions and 2 deletions

View file

@ -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();

View file

@ -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));

View file

@ -1030,6 +1030,11 @@ public class PlayerStub implements Player {
}
@Override
public void updateRange(Game game) {
}
@Override
public ManaOptions getManaAvailable(Game game) {
return null;

View file

@ -707,6 +707,8 @@ public interface Player extends MageItem, Copyable<Player> {
void untap(Game game);
void updateRange(Game game);
ManaOptions getManaAvailable(Game game);
void addAvailableTriggeredMana(List<Mana> netManaAvailable);

View file

@ -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 players 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<UUID> 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;
}