From 47a8686958e6ece7463b17dfcf299d287c0f3179 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 9 Jan 2020 23:17:39 +0100 Subject: [PATCH] * Some more move actions replaced and added missing methods for move to command zone. --- .../java/org/mage/test/player/TestPlayer.java | 94 +++++++++---------- .../java/org/mage/test/stub/PlayerStub.java | 10 +- .../ReturnToHandFromGraveyardAllEffect.java | 8 +- .../effects/keyword/ExploreSourceEffect.java | 9 +- .../abilities/keyword/NinjutsuAbility.java | 8 +- 5 files changed, 64 insertions(+), 65 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 529f1c7460..329c16b95d 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 @@ -1,5 +1,10 @@ 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.MageObject; import mage.MageObjectReference; @@ -55,13 +60,6 @@ import mage.util.CardUtil; import org.apache.log4j.Logger; import org.junit.Assert; 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 static org.mage.test.serverside.base.impl.CardTestPlayerAPIImpl.*; /** @@ -177,7 +175,7 @@ public class TestPlayer implements Player { /** * @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) { this.maxCallsWithoutAction = maxCallsWithoutAction; @@ -449,7 +447,6 @@ public class TestPlayer implements Player { } // found, can use as target - if (currentTarget.getNumberOfTargets() == 1) { currentTarget.clearChosen(); } @@ -898,15 +895,13 @@ public class TestPlayer implements Player { System.out.println("Total permanents: " + cards.size()); List data = cards.stream() - .map(c -> ( - ((c instanceof PermanentToken) ? "[T] " : "[C] ") - + c.getIdName() - + (c.isCopy() ? " [copy of " + c.getCopyFrom().getId().toString().substring(0, 3) + "]" : "") - + " - " + c.getPower().getValue() + "/" + c.getToughness().getValue() - + (c.isPlaneswalker() ? " - L" + c.getCounters(game).getCount(CounterType.LOYALTY) : "") - + ", " + (c.isTapped() ? "Tapped" : "Untapped") - + (c.getAttachedTo() == null ? "" : ", attached to " + game.getPermanent(c.getAttachedTo()).getIdName()) - )) + .map(c -> (((c instanceof PermanentToken) ? "[T] " : "[C] ") + + c.getIdName() + + (c.isCopy() ? " [copy of " + c.getCopyFrom().getId().toString().substring(0, 3) + "]" : "") + + " - " + c.getPower().getValue() + "/" + c.getToughness().getValue() + + (c.isPlaneswalker() ? " - L" + c.getCounters(game).getCount(CounterType.LOYALTY) : "") + + ", " + (c.isTapped() ? "Tapped" : "Untapped") + + (c.getAttachedTo() == null ? "" : ", attached to " + game.getPermanent(c.getAttachedTo()).getIdName()))) .sorted() .collect(Collectors.toList()); @@ -929,14 +924,12 @@ public class TestPlayer implements Player { } List data = abilities.stream() - .map(a -> ( - a.getZone() + " -> " - + a.getSourceObject(game).getIdName() + " -> " - + (a.toString().length() > 0 - ? a.toString().substring(0, Math.min(20, a.toString().length()) - 1) - : a.getClass().getSimpleName()) - + "..." - )) + .map(a -> (a.getZone() + " -> " + + a.getSourceObject(game).getIdName() + " -> " + + (a.toString().length() > 0 + ? a.toString().substring(0, Math.min(20, a.toString().length()) - 1) + : a.getClass().getSimpleName()) + + "...")) .sorted() .collect(Collectors.toList()); @@ -945,7 +938,6 @@ public class TestPlayer implements Player { } } - private String getAliasInfo(Game game, TestPlayer player, String aliasName) { MageItem item = findAliasObject(game, player, aliasName); if (item == null) { @@ -1291,7 +1283,7 @@ public class TestPlayer implements Player { UUID defenderId = null; boolean mustAttackByAction = false; boolean madeAttackByAction = false; - for (Iterator it = actions.iterator(); it.hasNext(); ) { + for (Iterator it = actions.iterator(); it.hasNext();) { PlayerAction action = it.next(); if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) { mustAttackByAction = true; @@ -1727,7 +1719,7 @@ public class TestPlayer implements Player { if (!target.getTargetName().equals("starting player")) { Assert.fail("Wrong choice"); } - */ + */ } // ignore player select @@ -1927,7 +1919,6 @@ public class TestPlayer implements Player { } } - // card in graveyard if (target.getOriginalTarget() instanceof TargetCardInOpponentsGraveyard || target.getOriginalTarget() instanceof TargetCardInYourGraveyard @@ -3136,6 +3127,11 @@ public class TestPlayer implements Player { return computerPlayer.moveCardToExileWithInfo(card, exileId, exileName, sourceId, game, fromZone, withName); } + @Override + public boolean moveCardToCommandWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) { + return computerPlayer.moveCardToCommandWithInfo(card, sourceId, game, fromZone); + } + @Override public boolean hasOpponent(UUID playerToCheckId, Game game) { return computerPlayer.hasOpponent(playerToCheckId, game); @@ -3239,7 +3235,7 @@ public class TestPlayer implements Player { @Override 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 return choose(outcome, target, sourceId, game, null); @@ -3247,7 +3243,7 @@ public class TestPlayer implements Player { @Override public boolean choose(Outcome outcome, Cards cards, - TargetCard target, Game game + TargetCard target, Game game ) { if (!choices.isEmpty()) { for (String choose2 : choices) { @@ -3283,7 +3279,7 @@ public class TestPlayer implements Player { @Override public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, - Ability source, Game game + Ability source, Game game ) { // command format: targetName^X=3 @@ -3342,15 +3338,15 @@ public class TestPlayer implements Player { @Override public boolean choosePile(Outcome outcome, String message, - List pile1, List pile2, - Game game + List pile1, List pile2, + Game game ) { return computerPlayer.choosePile(outcome, message, pile1, pile2, game); } @Override public boolean playMana(Ability ability, ManaCost unpaid, - String promptText, Game game + String promptText, Game game ) { groupsForTargetHandling = null; return computerPlayer.playMana(ability, unpaid, promptText, game); @@ -3364,15 +3360,15 @@ public class TestPlayer implements Player { @Override public UUID chooseBlockerOrder(List blockers, CombatGroup combatGroup, - List blockerOrder, Game game + List blockerOrder, Game game ) { return computerPlayer.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game); } @Override public void assignDamage(int damage, List targets, - String singleTargetName, UUID sourceId, - Game game + String singleTargetName, UUID sourceId, + Game game ) { computerPlayer.assignDamage(damage, targets, singleTargetName, sourceId, game); } @@ -3391,14 +3387,14 @@ public class TestPlayer implements Player { @Override public void pickCard(List cards, Deck deck, - Draft draft + Draft draft ) { computerPlayer.pickCard(cards, deck, draft); } @Override public boolean scry(int value, Ability source, - Game game + Game game ) { // Don't scry at the start of the game. if (game.getTurnNum() == 1 && game.getStep() == null) { @@ -3409,44 +3405,44 @@ public class TestPlayer implements Player { @Override public boolean surveil(int value, Ability source, - Game game + Game game ) { return computerPlayer.surveil(value, source, game); } @Override public boolean moveCards(Card card, Zone toZone, - Ability source, Game game + Ability source, Game game ) { return computerPlayer.moveCards(card, toZone, source, game); } @Override public boolean moveCards(Card card, Zone toZone, - Ability source, Game game, - boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects + Ability source, Game game, + boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects ) { return computerPlayer.moveCards(card, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); } @Override public boolean moveCards(Cards cards, Zone toZone, - Ability source, Game game + Ability source, Game game ) { return computerPlayer.moveCards(cards, toZone, source, game); } @Override public boolean moveCards(Set cards, Zone toZone, - Ability source, Game game + Ability source, Game game ) { return computerPlayer.moveCards(cards, toZone, source, game); } @Override public boolean moveCards(Set cards, Zone toZone, - Ability source, Game game, - boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects + Ability source, Game game, + boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects ) { return computerPlayer.moveCards(cards, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); } 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 f1e750f2ac..e3996289d9 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 @@ -1,5 +1,7 @@ package org.mage.test.stub; +import java.io.Serializable; +import java.util.*; import mage.MageObject; import mage.MageObjectReference; import mage.abilities.*; @@ -39,9 +41,6 @@ import mage.target.TargetAmount; import mage.target.TargetCard; import mage.target.common.TargetCardInLibrary; -import java.io.Serializable; -import java.util.*; - /** * @author Quercitron */ @@ -1187,6 +1186,11 @@ public class PlayerStub implements Player { return false; } + @Override + public boolean moveCardToCommandWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) { + return false; + } + @Override public boolean hasOpponent(UUID playerToCheckId, Game game) { return false; diff --git a/Mage/src/main/java/mage/abilities/effects/common/ReturnToHandFromGraveyardAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ReturnToHandFromGraveyardAllEffect.java index bfa9e45287..9d89562071 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ReturnToHandFromGraveyardAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ReturnToHandFromGraveyardAllEffect.java @@ -1,10 +1,8 @@ - package mage.abilities.effects.common; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterCard; @@ -37,9 +35,9 @@ public class ReturnToHandFromGraveyardAllEffect extends OneShotEffect { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { - for (Card card : player.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game)) { - card.moveToZone(Zone.HAND, playerId, game, false); - } + player.moveCards(player.getGraveyard() + .getCards(filter, source.getSourceId(), player.getId(), game), + Zone.HAND, source, game); } } diff --git a/Mage/src/main/java/mage/abilities/effects/keyword/ExploreSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/keyword/ExploreSourceEffect.java index 6ff8e1ea2f..05e8f1e9b9 100644 --- a/Mage/src/main/java/mage/abilities/effects/keyword/ExploreSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/keyword/ExploreSourceEffect.java @@ -20,8 +20,8 @@ import mage.players.Player; */ public class ExploreSourceEffect extends OneShotEffect { - // "it explores. (Reveal the top card of your library. Put that card into - // your hand if it's a land. Otherwise, put a +1/+1 counter on this creature, + // "it explores. (Reveal the top card of your library. Put that card into + // your hand if it's a land. Otherwise, put a +1/+1 counter on this creature, // then put the card back or put it into your graveyard.)"; private static final String RULE_TEXT_START = "explores."; private static final String RULE_TEXT_HINT = "(Reveal the top card of your library. " @@ -98,7 +98,7 @@ public class ExploreSourceEffect extends OneShotEffect { if (permanentController == null) { return false; } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLORED, permanentId, + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLORED, permanentId, source.getSourceId(), permanent.getControllerId())); if (permanentController.getLibrary().hasCards()) { Card card = permanentController.getLibrary().getFromTop(game); @@ -108,6 +108,7 @@ public class ExploreSourceEffect extends OneShotEffect { cardWasRevealed = true; if (card != null) { if (card.isLand()) { + permanentController.moveCardToHandWithInfo(card, source.getSourceId(), game); card.moveToZone(Zone.HAND, source.getSourceId(), game, true); } else { if (game.getState().getZone(permanentId) == Zone.BATTLEFIELD) { // needed in case LKI object is used @@ -124,7 +125,7 @@ public class ExploreSourceEffect extends OneShotEffect { } if (!cardWasRevealed && game.getState().getZone(permanentId) == Zone.BATTLEFIELD) { - // If no card is revealed, most likely because that player's library is empty, + // If no card is revealed, most likely because that player's library is empty, // the exploring creature receives a +1/+1 counter. permanent.addCounters(CounterType.P1P1.createInstance(), source, game); } diff --git a/Mage/src/main/java/mage/abilities/keyword/NinjutsuAbility.java b/Mage/src/main/java/mage/abilities/keyword/NinjutsuAbility.java index 157a173354..7c92b2f447 100644 --- a/Mage/src/main/java/mage/abilities/keyword/NinjutsuAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/NinjutsuAbility.java @@ -1,5 +1,6 @@ package mage.abilities.keyword; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.ActivatedAbilityImpl; import mage.abilities.costs.Cost; @@ -20,8 +21,6 @@ import mage.players.Player; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledPermanent; -import java.util.UUID; - /** * 702.47. Ninjutsu *

@@ -149,11 +148,12 @@ class ReturnAttackerToHandTargetCost extends CostImpl { if (targets.choose(Outcome.ReturnToHand, controllerId, sourceId, game)) { for (UUID targetId : targets.get(0).getTargets()) { Permanent permanent = game.getPermanent(targetId); - if (permanent == null) { + Player controller = game.getPlayer(controllerId); + if (permanent == null || controller == null) { return false; } defendingPlayerId = game.getCombat().getDefenderId(permanent.getId()); - paid |= permanent.moveToZone(Zone.HAND, sourceId, game, false); + paid |= controller.moveCardToHandWithInfo(permanent, sourceId, game); } } return paid;