Reverted some changes, related to #6187, see comments from d20a20fb6a

This commit is contained in:
Oleg Agafonov 2020-01-16 08:22:23 +04:00
parent 180c7dfff6
commit ec2ea7f070
6 changed files with 74 additions and 59 deletions

View file

@ -70,7 +70,7 @@ class AvengerEnDalEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (permanent != null) { if (permanent != null) {
Player player = game.getPlayer(permanent.getControllerId()); Player player = game.getPlayer(permanent.getControllerId());
if (player != null) { if (player != null) {

View file

@ -59,7 +59,7 @@ class BeastWithinEffect extends OneShotEffect {
// If the permanent is an illegal target when Beast Within tries to resolve, the spell wont resolve and none // If the permanent is an illegal target when Beast Within tries to resolve, the spell wont resolve and none
// of its effects will happen. The permanents controller wont get a Beast token. // of its effects will happen. The permanents controller wont get a Beast token.
// (2011-06-01) // (2011-06-01)
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); // must use LKI
if (permanent != null) { if (permanent != null) {
new BeastToken().putOntoBattlefield(1, game, source.getSourceId(), permanent.getControllerId()); new BeastToken().putOntoBattlefield(1, game, source.getSourceId(), permanent.getControllerId());
} }

View file

@ -58,8 +58,9 @@ class CrumbleEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
// If the target artifact becomes illegal before resolution, the player does not gain any life. (2004-10-04) // If the target artifact becomes illegal before resolution, the player does not gain any life.
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); // (2004-10-04)
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); // must use LKI
if (permanent != null) { if (permanent != null) {
int cost = permanent.getConvertedManaCost(); int cost = permanent.getConvertedManaCost();
Player player = game.getPlayer(permanent.getControllerId()); Player player = game.getPlayer(permanent.getControllerId());

View file

@ -44,6 +44,7 @@ public final class FaerieArtisans extends CardImpl {
// Flying // Flying
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Whenever a nontoken creature enters the battlefield under an opponent's control, create a token that's a copy of that creature except it's an artifact in addition to its other types. Then exile all other tokens created with Faerie Artisans. // Whenever a nontoken creature enters the battlefield under an opponent's control, create a token that's a copy of that creature except it's an artifact in addition to its other types. Then exile all other tokens created with Faerie Artisans.
Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new FaerieArtisansEffect(), filterNontoken, false, SetTargetPointer.PERMANENT, Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new FaerieArtisansEffect(), filterNontoken, false, SetTargetPointer.PERMANENT,
"Whenever a nontoken creature enters the battlefield under an opponent's control, create a token that's a copy of that creature except it's an artifact in addition to its other types. Then exile all other tokens created with {this}."); "Whenever a nontoken creature enters the battlefield under an opponent's control, create a token that's a copy of that creature except it's an artifact in addition to its other types. Then exile all other tokens created with {this}.");

View file

@ -74,7 +74,7 @@ class IncongruityEffect extends OneShotEffect {
// If the target creature is an illegal target by the time Incongruity tries to resolve, the spell doesnt resolve. // If the target creature is an illegal target by the time Incongruity tries to resolve, the spell doesnt resolve.
// No player creates a Frog Lizard token. // No player creates a Frog Lizard token.
// (2019-01-25) // (2019-01-25)
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); Permanent permanent = game.getPermanentOrLKIBattlefield(targetPointer.getFirst(game, source)); // must use LKI
if (permanent != null) { if (permanent != null) {
FrogLizardToken token = new FrogLizardToken(); FrogLizardToken token = new FrogLizardToken();
token.putOntoBattlefield(1, game, source.getSourceId(), permanent.getControllerId()); token.putOntoBattlefield(1, game, source.getSourceId(), permanent.getControllerId());

View file

@ -1,10 +1,5 @@
package org.mage.test.player; package org.mage.test.player;
import java.io.Serializable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import mage.MageItem; import mage.MageItem;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectReference; import mage.MageObjectReference;
@ -61,6 +56,14 @@ import mage.util.CardUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import java.io.Serializable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*; import static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*;
/** /**
@ -177,7 +180,7 @@ public class TestPlayer implements Player {
/** /**
* @param maxCallsWithoutAction max number of priority passes a player may * @param maxCallsWithoutAction max number of priority passes a player may
* have for this test (default = 100) * have for this test (default = 100)
*/ */
public void setMaxCallsWithoutAction(int maxCallsWithoutAction) { public void setMaxCallsWithoutAction(int maxCallsWithoutAction) {
this.maxCallsWithoutAction = maxCallsWithoutAction; this.maxCallsWithoutAction = maxCallsWithoutAction;
@ -901,12 +904,12 @@ public class TestPlayer implements Player {
List<String> data = cards.stream() List<String> data = cards.stream()
.map(c -> (((c instanceof PermanentToken) ? "[T] " : "[C] ") .map(c -> (((c instanceof PermanentToken) ? "[T] " : "[C] ")
+ c.getIdName() + c.getIdName()
+ (c.isCopy() ? " [copy of " + c.getCopyFrom().getId().toString().substring(0, 3) + "]" : "") + (c.isCopy() ? " [copy of " + c.getCopyFrom().getId().toString().substring(0, 3) + "]" : "")
+ " - " + c.getPower().getValue() + "/" + c.getToughness().getValue() + " - " + c.getPower().getValue() + "/" + c.getToughness().getValue()
+ (c.isPlaneswalker() ? " - L" + c.getCounters(game).getCount(CounterType.LOYALTY) : "") + (c.isPlaneswalker() ? " - L" + c.getCounters(game).getCount(CounterType.LOYALTY) : "")
+ ", " + (c.isTapped() ? "Tapped" : "Untapped") + ", " + (c.isTapped() ? "Tapped" : "Untapped")
+ (c.getAttachedTo() == null ? "" : ", attached to " + game.getPermanent(c.getAttachedTo()).getIdName()))) + (c.getAttachedTo() == null ? "" : ", attached to " + game.getPermanent(c.getAttachedTo()).getIdName())))
.sorted() .sorted()
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -930,11 +933,11 @@ public class TestPlayer implements Player {
List<String> data = abilities.stream() List<String> data = abilities.stream()
.map(a -> (a.getZone() + " -> " .map(a -> (a.getZone() + " -> "
+ a.getSourceObject(game).getIdName() + " -> " + a.getSourceObject(game).getIdName() + " -> "
+ (a.toString().length() > 0 + (a.toString().length() > 0
? a.toString().substring(0, Math.min(20, a.toString().length()) - 1) ? a.toString().substring(0, Math.min(20, a.toString().length()) - 1)
: a.getClass().getSimpleName()) : a.getClass().getSimpleName())
+ "...")) + "..."))
.sorted() .sorted()
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -1288,7 +1291,7 @@ public class TestPlayer implements Player {
UUID defenderId = null; UUID defenderId = null;
boolean mustAttackByAction = false; boolean mustAttackByAction = false;
boolean madeAttackByAction = false; boolean madeAttackByAction = false;
for (Iterator<org.mage.test.player.PlayerAction> it = actions.iterator(); it.hasNext();) { for (Iterator<org.mage.test.player.PlayerAction> it = actions.iterator(); it.hasNext(); ) {
PlayerAction action = it.next(); PlayerAction action = it.next();
if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) { if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) {
mustAttackByAction = true; mustAttackByAction = true;
@ -1453,21 +1456,28 @@ public class TestPlayer implements Player {
} }
private String getInfo(MageObject o) { private String getInfo(MageObject o) {
return o != null ? o.getClass().getSimpleName() + ": " + o.getName() : "null"; return "Object: " + (o != null ? o.getClass().getSimpleName() + ": " + o.getName() : "null");
} }
private String getInfo(Ability o) { private String getInfo(Ability o, Game game) {
return o != null ? o.getClass().getSimpleName() + ": " + o.getRule() : "null"; if (o != null) {
MageObject object = o.getSourceObject(game);
return "Ability: " + (object == null ? "" : object.getName() + " - " + o.getClass().getSimpleName() + ": " + o.getRule());
}
return "Ability: null";
} }
private String getInfo(Target o) { private String getInfo(Target o) {
return o != null ? o.getClass().getSimpleName() + ": " + o.getMessage() : "null"; return "Target: " + (o != null ? o.getClass().getSimpleName() + ": " + o.getMessage() : "null");
} }
private void chooseStrictModeFailed(String choiceType, Game game, String reason) { private void chooseStrictModeFailed(String choiceType, Game game, String reason) {
if (strictChooseMode) { if (strictChooseMode) {
Assert.fail("Missing " + choiceType + " def for turn " + game.getTurnNum() + ", " + this.getName() + ", " Assert.fail("Missing " + choiceType + " def for"
+ game.getStep().getType().name() + ": " + reason); + " turn " + game.getTurnNum()
+ ", step " + game.getStep().getType().name()
+ ", " + this.getName()
+ "\n" + reason);
} }
} }
@ -1493,7 +1503,7 @@ public class TestPlayer implements Player {
return null; return null;
} }
this.chooseStrictModeFailed("mode", game, getInfo(source)); this.chooseStrictModeFailed("mode", game, getInfo(source, game));
return computerPlayer.chooseMode(modes, source, game); return computerPlayer.chooseMode(modes, source, game);
} }
@ -1770,7 +1780,7 @@ public class TestPlayer implements Player {
// skip targets // skip targets
if (targets.get(0).equals(TARGET_SKIP)) { if (targets.get(0).equals(TARGET_SKIP)) {
Assert.assertTrue("found skip target, but it require more targets, needs " Assert.assertTrue("found skip target, but it require more targets, needs "
+ (target.getMinNumberOfTargets() - target.getTargets().size()) + " more", + (target.getMinNumberOfTargets() - target.getTargets().size()) + " more",
target.getTargets().size() >= target.getMinNumberOfTargets()); target.getTargets().size() >= target.getMinNumberOfTargets());
targets.remove(0); targets.remove(0);
return true; return true;
@ -2025,7 +2035,7 @@ public class TestPlayer implements Player {
Assert.fail(message); Assert.fail(message);
} }
this.chooseStrictModeFailed("target", game, getInfo(source) + "; " + getInfo(target)); this.chooseStrictModeFailed("target", game,getInfo(source, game) + "\n" + getInfo(target));
return computerPlayer.chooseTarget(outcome, target, source, game); return computerPlayer.chooseTarget(outcome, target, source, game);
} }
@ -2054,7 +2064,7 @@ public class TestPlayer implements Player {
//Assert.fail("Wrong target"); //Assert.fail("Wrong target");
} }
this.chooseStrictModeFailed("target", game, getInfo(source) + "; " + getInfo(target)); this.chooseStrictModeFailed("target", game, getInfo(source, game) + "; " + getInfo(target));
return computerPlayer.chooseTarget(outcome, cards, target, source, game); return computerPlayer.chooseTarget(outcome, cards, target, source, game);
} }
@ -2071,7 +2081,9 @@ public class TestPlayer implements Player {
//Assert.fail("Wrong choice"); //Assert.fail("Wrong choice");
} }
this.chooseStrictModeFailed("choice", game, abilities.stream().map(this::getInfo).collect(Collectors.joining("; "))); this.chooseStrictModeFailed("choice", game,
"Triggered list (total " + abilities.size() + "):\n"
+ abilities.stream().map(a -> getInfo(a, game)).collect(Collectors.joining("\n")));
return computerPlayer.chooseTriggeredAbility(abilities, game); return computerPlayer.chooseTriggeredAbility(abilities, game);
} }
@ -2098,8 +2110,9 @@ public class TestPlayer implements Player {
//Assert.fail("Wrong choice"); //Assert.fail("Wrong choice");
} }
this.chooseStrictModeFailed("choice", game, getInfo(source) + "; " + message + ": " this.chooseStrictModeFailed("choice", game, getInfo(source, game)
+ (trueText != null ? trueText : "Yes") + " - " + (falseText != null ? falseText : "No")); + "\nMessage: " + message
+ "\nChoices: " + (trueText != null ? trueText : "Yes") + " - " + (falseText != null ? falseText : "No"));
return computerPlayer.chooseUse(outcome, message, secondMessage, trueText, falseText, source, game); return computerPlayer.chooseUse(outcome, message, secondMessage, trueText, falseText, source, game);
} }
@ -2115,7 +2128,7 @@ public class TestPlayer implements Player {
} }
} }
this.chooseStrictModeFailed("choice", game, getInfo(ability) + "; " + message); this.chooseStrictModeFailed("choice", game, getInfo(ability, game) + "; " + message);
return computerPlayer.announceXMana(min, max, multiplier, message, game, ability); return computerPlayer.announceXMana(min, max, multiplier, message, game, ability);
} }
@ -2129,7 +2142,7 @@ public class TestPlayer implements Player {
} }
} }
this.chooseStrictModeFailed("choice", game, getInfo(ability) + "; " + message); this.chooseStrictModeFailed("choice", game, getInfo(ability, game) + "; " + message);
return computerPlayer.announceXCost(min, max, message, game, ability, null); return computerPlayer.announceXCost(min, max, message, game, ability, null);
} }
@ -3244,7 +3257,7 @@ public class TestPlayer implements Player {
@Override @Override
public boolean choose(Outcome outcome, Target target, public boolean choose(Outcome outcome, Target target,
UUID sourceId, Game game UUID sourceId, Game game
) { ) {
// needed to call here the TestPlayer because it's overwitten // needed to call here the TestPlayer because it's overwitten
return choose(outcome, target, sourceId, game, null); return choose(outcome, target, sourceId, game, null);
@ -3252,7 +3265,7 @@ public class TestPlayer implements Player {
@Override @Override
public boolean choose(Outcome outcome, Cards cards, public boolean choose(Outcome outcome, Cards cards,
TargetCard target, Game game TargetCard target, Game game
) { ) {
if (!choices.isEmpty()) { if (!choices.isEmpty()) {
for (String choose2 : choices) { for (String choose2 : choices) {
@ -3288,7 +3301,7 @@ public class TestPlayer implements Player {
@Override @Override
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, public boolean chooseTargetAmount(Outcome outcome, TargetAmount target,
Ability source, Game game Ability source, Game game
) { ) {
// chooseTargetAmount calls for EACH target cycle (e.g. one target per click, see TargetAmount) // chooseTargetAmount calls for EACH target cycle (e.g. one target per click, see TargetAmount)
// if use want to stop choosing then chooseTargetAmount must return false (example: up to xxx) // if use want to stop choosing then chooseTargetAmount must return false (example: up to xxx)
@ -3300,7 +3313,7 @@ public class TestPlayer implements Player {
// skip targets // skip targets
if (targets.get(0).equals(TARGET_SKIP)) { if (targets.get(0).equals(TARGET_SKIP)) {
Assert.assertTrue("found skip target, but it require more targets, needs " Assert.assertTrue("found skip target, but it require more targets, needs "
+ (target.getMinNumberOfTargets() - target.getTargets().size()) + " more", + (target.getMinNumberOfTargets() - target.getTargets().size()) + " more",
target.getTargets().size() >= target.getMinNumberOfTargets()); target.getTargets().size() >= target.getMinNumberOfTargets());
targets.remove(0); targets.remove(0);
return false; // false in chooseTargetAmount = stop to choose return false; // false in chooseTargetAmount = stop to choose
@ -3341,7 +3354,7 @@ public class TestPlayer implements Player {
} }
} }
this.chooseStrictModeFailed("target", game, getInfo(source) + "; " + getInfo(target)); this.chooseStrictModeFailed("target", game, getInfo(source, game) + "; " + getInfo(target));
return computerPlayer.chooseTargetAmount(outcome, target, source, game); return computerPlayer.chooseTargetAmount(outcome, target, source, game);
} }
@ -3353,15 +3366,15 @@ public class TestPlayer implements Player {
@Override @Override
public boolean choosePile(Outcome outcome, String message, public boolean choosePile(Outcome outcome, String message,
List<? extends Card> pile1, List<? extends Card> pile2, List<? extends Card> pile1, List<? extends Card> pile2,
Game game Game game
) { ) {
return computerPlayer.choosePile(outcome, message, pile1, pile2, game); return computerPlayer.choosePile(outcome, message, pile1, pile2, game);
} }
@Override @Override
public boolean playMana(Ability ability, ManaCost unpaid, public boolean playMana(Ability ability, ManaCost unpaid,
String promptText, Game game String promptText, Game game
) { ) {
groupsForTargetHandling = null; groupsForTargetHandling = null;
return computerPlayer.playMana(ability, unpaid, promptText, game); return computerPlayer.playMana(ability, unpaid, promptText, game);
@ -3375,15 +3388,15 @@ public class TestPlayer implements Player {
@Override @Override
public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup,
List<UUID> blockerOrder, Game game List<UUID> blockerOrder, Game game
) { ) {
return computerPlayer.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game); return computerPlayer.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game);
} }
@Override @Override
public void assignDamage(int damage, List<UUID> targets, public void assignDamage(int damage, List<UUID> targets,
String singleTargetName, UUID sourceId, String singleTargetName, UUID sourceId,
Game game Game game
) { ) {
computerPlayer.assignDamage(damage, targets, singleTargetName, sourceId, game); computerPlayer.assignDamage(damage, targets, singleTargetName, sourceId, game);
} }
@ -3402,14 +3415,14 @@ public class TestPlayer implements Player {
@Override @Override
public void pickCard(List<Card> cards, Deck deck, public void pickCard(List<Card> cards, Deck deck,
Draft draft Draft draft
) { ) {
computerPlayer.pickCard(cards, deck, draft); computerPlayer.pickCard(cards, deck, draft);
} }
@Override @Override
public boolean scry(int value, Ability source, public boolean scry(int value, Ability source,
Game game Game game
) { ) {
// Don't scry at the start of the game. // Don't scry at the start of the game.
if (game.getTurnNum() == 1 && game.getStep() == null) { if (game.getTurnNum() == 1 && game.getStep() == null) {
@ -3420,44 +3433,44 @@ public class TestPlayer implements Player {
@Override @Override
public boolean surveil(int value, Ability source, public boolean surveil(int value, Ability source,
Game game Game game
) { ) {
return computerPlayer.surveil(value, source, game); return computerPlayer.surveil(value, source, game);
} }
@Override @Override
public boolean moveCards(Card card, Zone toZone, public boolean moveCards(Card card, Zone toZone,
Ability source, Game game Ability source, Game game
) { ) {
return computerPlayer.moveCards(card, toZone, source, game); return computerPlayer.moveCards(card, toZone, source, game);
} }
@Override @Override
public boolean moveCards(Card card, Zone toZone, public boolean moveCards(Card card, Zone toZone,
Ability source, Game game, Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
) { ) {
return computerPlayer.moveCards(card, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); return computerPlayer.moveCards(card, toZone, source, game, tapped, faceDown, byOwner, appliedEffects);
} }
@Override @Override
public boolean moveCards(Cards cards, Zone toZone, public boolean moveCards(Cards cards, Zone toZone,
Ability source, Game game Ability source, Game game
) { ) {
return computerPlayer.moveCards(cards, toZone, source, game); return computerPlayer.moveCards(cards, toZone, source, game);
} }
@Override @Override
public boolean moveCards(Set<Card> cards, Zone toZone, public boolean moveCards(Set<Card> cards, Zone toZone,
Ability source, Game game Ability source, Game game
) { ) {
return computerPlayer.moveCards(cards, toZone, source, game); return computerPlayer.moveCards(cards, toZone, source, game);
} }
@Override @Override
public boolean moveCards(Set<Card> cards, Zone toZone, public boolean moveCards(Set<Card> cards, Zone toZone,
Ability source, Game game, Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
) { ) {
return computerPlayer.moveCards(cards, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); return computerPlayer.moveCards(cards, toZone, source, game, tapped, faceDown, byOwner, appliedEffects);
} }