diff --git a/Mage.Sets/src/mage/sets/stronghold/DreamHalls.java b/Mage.Sets/src/mage/sets/stronghold/DreamHalls.java index 317db0e018..e0a0b4c45f 100644 --- a/Mage.Sets/src/mage/sets/stronghold/DreamHalls.java +++ b/Mage.Sets/src/mage/sets/stronghold/DreamHalls.java @@ -58,7 +58,6 @@ public class DreamHalls extends CardImpl { super(ownerId, 28, "Dream Halls", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{U}{U}"); this.expansionSetCode = "STH"; - // Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DreamHallsEffect())); } @@ -102,13 +101,13 @@ class DreamHallsEffect extends ContinuousEffectImpl { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - for (UUID playerId: controller.getInRange()) { + for (UUID playerId : controller.getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { player.getAlternativeSourceCosts().add(alternativeCastingCostAbility); } } - + return true; } return false; diff --git a/Mage.Sets/src/mage/sets/urzassaga/Persecute.java b/Mage.Sets/src/mage/sets/urzassaga/Persecute.java index 5c83ad2eea..82d8dfe6f5 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/Persecute.java +++ b/Mage.Sets/src/mage/sets/urzassaga/Persecute.java @@ -29,6 +29,7 @@ package mage.sets.urzassaga; import java.util.Set; import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; @@ -52,7 +53,6 @@ public class Persecute extends CardImpl { super(ownerId, 146, "Persecute", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{B}{B}"); this.expansionSetCode = "USG"; - // Choose a color. Target player reveals his or her hand and discards all cards of that color. this.getSpellAbility().addEffect(new PersecuteEffect()); this.getSpellAbility().addTarget(new TargetPlayer()); @@ -88,19 +88,20 @@ class PersecuteEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getFirstTarget()); - if (controller != null) { + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller != null && sourceObject != null) { ChoiceColor choice = new ChoiceColor(); while (!choice.isChosen()) { controller.choose(outcome, choice, game); if (!controller.isInGame()) { return false; } - } + } if (choice.getColor() == null) { return false; } Cards hand = controller.getHand(); - controller.revealCards("Persecute", hand, game); + controller.revealCards(sourceObject.getIdName(), hand, game); Set cards = hand.getCards(game); for (Card card : cards) { if (card != null && card.getColor(game).shares(choice.getColor())) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/OmniscienceTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/OmniscienceTest.java index 941a069618..02ab0f8a23 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/OmniscienceTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/OmniscienceTest.java @@ -2,44 +2,43 @@ package org.mage.test.cards.cost.alternate; import mage.constants.PhaseStep; import mage.constants.Zone; - import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; public class OmniscienceTest extends CardTestPlayerBase { - - @Test - public void testSpellNoCost() { + + @Test + public void testSpellNoCost() { + // You may cast nonland cards from your hand without paying their mana costs. addCard(Zone.BATTLEFIELD, playerA, "Omniscience", 1); - + addCard(Zone.HAND, playerA, "Gray Ogre", 1); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gray Ogre"); setStopAt(1, PhaseStep.END_TURN); execute(); - + //Gray Ogre is cast because it is free assertPermanentCount(playerA, "Gray Ogre", 1); - } - - @Test - public void testSpellHasCostIfCastFromGraveyard() { + } + + @Test + public void testSpellHasCostIfCastFromGraveyard() { + // You may cast nonland cards from your hand without paying their mana costs. addCard(Zone.BATTLEFIELD, playerA, "Omniscience", 1); - + addCard(Zone.BATTLEFIELD, playerA, "Haakon, Stromgald Scourge", 1); - + addCard(Zone.GRAVEYARD, playerA, "Knight of the White Orchid", 1); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Knight of the White Orchid"); setStopAt(1, PhaseStep.END_TURN); execute(); - + //Knight of the White Orchid was not cast due to lack of mana assertPermanentCount(playerA, "Knight of the White Orchid", 0); - } - - + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/UseAlternateSourceCostsTets.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/UseAlternateSourceCostsTets.java new file mode 100644 index 0000000000..c33fdc961e --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate/UseAlternateSourceCostsTets.java @@ -0,0 +1,104 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.cards.cost.alternate; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class UseAlternateSourceCostsTets extends CardTestPlayerBase { + + @Test + public void DreamHallsCastColoredSpell() { + // Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. + addCard(Zone.BATTLEFIELD, playerA, "Dream Halls", 1); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); // Add the mountains so the spell is included in teh available spells + + addCard(Zone.HAND, playerA, "Gray Ogre", 1); // Creature 3/1 + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gray Ogre"); // Cast Orgre by discarding the Lightning Bolt + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + //Gray Ogre is cast with the discard + assertPermanentCount(playerA, "Gray Ogre", 1); + assertGraveyardCount(playerA, "Lightning Bolt", 1); + assertTapped("Mountain", false); + } + + @Test + public void DreamHallsCantCastColorlessSpell() { + // Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. + addCard(Zone.BATTLEFIELD, playerA, "Dream Halls", 1); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); // Add the mountains so the spell is included in teh available spells + + addCard(Zone.HAND, playerA, "Juggernaut", 1); // Creature 5/3 - {4} + addCard(Zone.HAND, playerA, "Haunted Plate Mail", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Juggernaut"); // Cast Juggernaut by discarding Haunted Plate Mail may not work + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Haunted Plate Mail", 0); + assertTapped("Mountain", true); + //Juggernaut is not cast by alternate casting costs + assertPermanentCount(playerA, "Juggernaut", 1); + } + + @Test + public void DreamHallsCastWithFutureSight() { + // Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. + addCard(Zone.BATTLEFIELD, playerA, "Dream Halls", 1); + // Play with the top card of your library revealed. + // You may play the top card of your library. + addCard(Zone.BATTLEFIELD, playerA, "Future Sight", 1); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); // Add the mountains so the spell is included in teh available spells + + addCard(Zone.LIBRARY, playerA, "Gray Ogre", 1); // Creature 3/1 + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + skipInitShuffling(); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gray Ogre"); // Cast Orgre by discarding the Lightning Bolt + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertTapped("Mountain", false); + //Gray Ogre is cast with the discard + assertPermanentCount(playerA, "Gray Ogre", 1); + assertGraveyardCount(playerA, "Lightning Bolt", 1); + } +} 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 8b910600cb..331f42e4fe 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 @@ -41,13 +41,14 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement // Defines the constant if for activate ability is not target but a ability on the stack to define public static final String NO_TARGET = "NO_TARGET"; - + protected GameOptions gameOptions; - + protected String deckNameA; protected String deckNameB; - + protected enum ExpectedType { + TURN_NUMBER, RESULT, LIFE, @@ -55,14 +56,15 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement GRAVEYARD, UNKNOWN } - + static { // CardScanner.scanned = true; CardScanner.scan(); } /** - * Default game initialization params for red player (that plays with Mountains) + * Default game initialization params for red player (that plays with + * Mountains) */ @Override public void useRedDefault() { @@ -88,7 +90,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * Default game initialization params for white player (that plays with Plains) + * Default game initialization params for white player (that plays with + * Plains) */ public void useWhiteDefault() { // *** ComputerA *** @@ -103,7 +106,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement removeAllCardsFromLibrary(playerB); addCard(Zone.LIBRARY, playerB, "Plains", 10); } - + @Before public void reset() throws GameException, FileNotFoundException { if (currentGame != null) { @@ -120,7 +123,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement stopAtStep = PhaseStep.UNTAP; for (Player player : currentGame.getPlayers().values()) { - TestPlayer testPlayer = (TestPlayer)player; + TestPlayer testPlayer = (TestPlayer) player; getCommands(testPlayer).clear(); getLibraryCards(testPlayer).clear(); getHandCards(testPlayer).clear(); @@ -132,11 +135,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } abstract protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException; - + protected TestPlayer createPlayer(Game game, TestPlayer player, String name) throws GameException { return createPlayer(game, player, name, "RB Aggro.dck"); } - + protected TestPlayer createPlayer(Game game, TestPlayer player, String name, String deckName) throws GameException { player = createNewPlayer(name); player.setTestMode(true); @@ -147,7 +150,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck.getCards().size()); } game.loadCards(deck.getCards(), player.getId()); - game.loadCards(deck.getSideboard(), player.getId()); + game.loadCards(deck.getSideboard(), player.getId()); game.addPlayer(player, deck); return player; @@ -156,7 +159,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Starts testing card by starting current game. * - * @throws IllegalStateException In case game wasn't created previously. Use {@link #load} method to initialize the game. + * @throws IllegalStateException In case game wasn't created previously. Use + * {@link #load} method to initialize the game. */ public void execute() throws IllegalStateException { if (currentGame == null || activePlayer == null) { @@ -164,7 +168,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } for (Player player : currentGame.getPlayers().values()) { - TestPlayer testPlayer = (TestPlayer)player; + TestPlayer testPlayer = (TestPlayer) player; currentGame.cheat(player.getId(), getCommands(testPlayer)); currentGame.cheat(player.getId(), getLibraryCards(testPlayer), getHandCards(testPlayer), getBattlefieldCards(testPlayer), getGraveCards(testPlayer)); @@ -182,13 +186,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement logger.info("Test has been executed. Execution time: " + (t2 - t1) / 1000000 + " ms"); } - - - + protected TestPlayer createNewPlayer(String playerName) { return createPlayer(playerName); } - + protected Player getPlayerFromName(String playerName, String line) { Player player = null; switch (playerName) { @@ -209,10 +211,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } return player; } - + /** - * Removes all cards from player's library from the game. - * Usually this should be used once before initialization to form the library in certain order. + * Removes all cards from player's library from the game. Usually this + * should be used once before initialization to form the library in certain + * order. * * @param player {@link Player} to remove all library cards from. */ @@ -221,8 +224,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * Removes all cards from player's hand from the game. - * Usually this should be used once before initialization to set the players hand. + * Removes all cards from player's hand from the game. Usually this should + * be used once before initialization to set the players hand. * * @param player {@link Player} to remove all cards from hand. */ @@ -234,7 +237,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Add a card to specified zone of specified player. * * @param gameZone {@link mage.constants.Zone} to add cards to. - * @param player {@link Player} to add cards for. Use either playerA or playerB. + * @param player {@link Player} to add cards for. Use either playerA or + * playerB. * @param cardName Card name in string format. */ public void addCard(Zone gameZone, TestPlayer player, String cardName) { @@ -245,9 +249,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Add any amount of cards to specified zone of specified player. * * @param gameZone {@link mage.constants.Zone} to add cards to. - * @param player {@link Player} to add cards for. Use either playerA or playerB. + * @param player {@link Player} to add cards for. Use either playerA or + * playerB. * @param cardName Card name in string format. - * @param count Amount of cards to be added. + * @param count Amount of cards to be added. */ public void addCard(Zone gameZone, TestPlayer player, String cardName, int count) { addCard(gameZone, player, cardName, count, false); @@ -257,11 +262,13 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Add any amount of cards to specified zone of specified player. * * @param gameZone {@link mage.constants.Zone} to add cards to. - * @param player {@link Player} to add cards for. Use either playerA or playerB. + * @param player {@link Player} to add cards for. Use either playerA or + * playerB. * @param cardName Card name in string format. - * @param count Amount of cards to be added. - * @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped. - * In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown + * @param count Amount of cards to be added. + * @param tapped In case gameZone is Battlefield, determines whether + * permanent should be tapped. In case gameZone is other than Battlefield, + * {@link IllegalArgumentException} is thrown */ public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) { @@ -315,7 +322,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Set player's initial life count. * * @param player {@link Player} to set life count for. - * @param life Life count to set. + * @param life Life count to set. */ public void setLife(TestPlayer player, int life) { getCommands(player).put(Zone.OUTSIDE, "life:" + String.valueOf(life)); @@ -323,6 +330,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Define turn number to stop the game on. + * * @param turn */ @Override @@ -332,8 +340,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * Define turn number and step to stop the game on. - * The game stops after executing the step + * Define turn number and step to stop the game on. The game stops after + * executing the step + * * @param turn * @param step */ @@ -389,7 +398,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Assert player's life count after test execution. * * @param player {@link Player} to get life for comparison. - * @param life Expected player's life to compare with. + * @param life Expected player's life to compare with. */ @Override public void assertLife(Player player, int life) throws AssertionError { @@ -400,19 +409,20 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert creature's power and toughness by card name. *

- * Throws {@link AssertionError} in the following cases: - * 1. no such player - * 2. no such creature under player's control - * 3. depending on comparison scope: - * 3a. any: no creature under player's control with the specified p\t params - * 3b. all: there is at least one creature with the cardName with the different p\t params + * Throws {@link AssertionError} in the following cases: 1. no such player + * 2. no such creature under player's control 3. depending on comparison + * scope: 3a. any: no creature under player's control with the specified p\t + * params 3b. all: there is at least one creature with the cardName with the + * different p\t params * - * @param player {@link Player} to get creatures for comparison. - * @param cardName Card name to compare with. - * @param power Expected power to compare with. + * @param player {@link Player} to get creatures for comparison. + * @param cardName Card name to compare with. + * @param power Expected power to compare with. * @param toughness Expected toughness to compare with. - * @param scope {@link mage.filter.Filter.ComparisonScope} Use ANY, if you want "at least one creature with given name should have specified p\t" - * Use ALL, if you want "all creature with gived name should have specified p\t" + * @param scope {@link mage.filter.Filter.ComparisonScope} Use ANY, if you + * want "at least one creature with given name should have specified p\t" + * Use ALL, if you want "all creature with gived name should have specified + * p\t" */ @Override public void assertPowerToughness(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope) @@ -442,18 +452,19 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } } - Assert.assertTrue("There is no such permanent under player's control, player=" + player.getName() + - ", cardName=" + cardName, count > 0); + Assert.assertTrue("There is no such permanent under player's control, player=" + player.getName() + + ", cardName=" + cardName, count > 0); if (scope.equals(Filter.ComparisonScope.Any)) { - Assert.assertTrue("There is no such creature under player's control with specified power&toughness, player=" + player.getName() + - ", cardName=" + cardName + " (found similar: " + found + ", one of them: power=" + foundPower + " toughness=" + foundToughness + ")", fit > 0); + Assert.assertTrue("There is no such creature under player's control with specified power&toughness, player=" + player.getName() + + ", cardName=" + cardName + " (found similar: " + found + ", one of them: power=" + foundPower + " toughness=" + foundToughness + ")", fit > 0); } } /** - * See {@link #assertPowerToughness(mage.players.Player, String, int, int, mage.filter.Filter.ComparisonScope)} - * + * See + * {@link #assertPowerToughness(mage.players.Player, String, int, int, mage.filter.Filter.ComparisonScope)} + * * @param player * @param cardName * @param power @@ -478,15 +489,15 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } } - Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + - ", cardName=" + cardName, found); + Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + + ", cardName=" + cardName, found); - Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + - ", cardName=" + cardName, count == 1); + Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + + ", cardName=" + cardName, count == 1); for (Ability ability : abilities) { - Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + - ", cardName" + cardName, found.getAbilities().contains(ability)); + Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + + ", cardName" + cardName, found.getAbilities().contains(ability)); } } @@ -495,7 +506,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * @param player * @param cardName * @param ability - * @param flag true if creature should contain ability, false if it should NOT contain it instead + * @param flag true if creature should contain ability, false if it should + * NOT contain it instead * @throws AssertionError */ public void assertAbility(Player player, String cardName, Ability ability, boolean flag) throws AssertionError { @@ -508,18 +520,18 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } } - Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + - ", cardName=" + cardName, found); + Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + + ", cardName=" + cardName, found); - Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + - ", cardName=" + cardName, count == 1); + Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + + ", cardName=" + cardName, count == 1); if (flag) { - Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + - ", cardName" + cardName, found.getAbilities().containsRule(ability)); + Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + + ", cardName" + cardName, found.getAbilities().containsRule(ability)); } else { - Assert.assertFalse("Card shouldn't have such ability=" + ability.toString() + ", player=" + player.getName() + - ", cardName" + cardName, found.getAbilities().containsRule(ability)); + Assert.assertFalse("Card shouldn't have such ability=" + ability.toString() + ", player=" + player.getName() + + ", cardName" + cardName, found.getAbilities().containsRule(ability)); } } @@ -527,7 +539,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Assert permanent count under player's control. * * @param player {@link Player} which permanents should be counted. - * @param count Expected count. + * @param count Expected count. */ @Override public void assertPermanentCount(Player player, int count) throws AssertionError { @@ -543,9 +555,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert permanent count under player's control. * - * @param player {@link Player} which permanents should be counted. + * @param player {@link Player} which permanents should be counted. * @param cardName Name of the cards that should be counted. - * @param count Expected count. + * @param count Expected count. */ @Override public void assertPermanentCount(Player player, String cardName, int count) throws AssertionError { @@ -580,9 +592,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert counter count on a permanent * - * @param cardName Name of the cards that should be counted. - * @param type Type of the counter that should be counted. - * @param count Expected count. + * @param cardName Name of the cards that should be counted. + * @param type Type of the counter that should be counted. + * @param count Expected count. */ public void assertCounterCount(String cardName, CounterType type, int count) throws AssertionError { Permanent found = null; @@ -595,35 +607,36 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement Assert.assertNotNull("There is no such permanent on the battlefield, cardName=" + cardName, found); Assert.assertEquals("(Battlefield) Counter counts are not equal (" + cardName + ":" + type + ")", count, found.getCounters().getCount(type)); } + /** - * Assert counter count on a card in exile + * Assert counter count on a card in exile * - * @param cardName Name of the cards that should be counted. - * @param type Type of the counter that should be counted. - * @param count Expected count. + * @param cardName Name of the cards that should be counted. + * @param type Type of the counter that should be counted. + * @param count Expected count. */ public void assertCounterOnExiledCardCount(String cardName, CounterType type, int count) throws AssertionError { Card found = null; if (found == null) { - for (Card card : currentGame.getExile().getAllCards(currentGame)) { - if (card.getName().equals(cardName)) { - found = card; - break; + for (Card card : currentGame.getExile().getAllCards(currentGame)) { + if (card.getName().equals(cardName)) { + found = card; + break; + } } - } - + } Assert.assertNotNull("There is no such card in the exile, cardName=" + cardName, found); Assert.assertEquals("(Exile) Counter counts are not equal (" + cardName + ":" + type + ")", count, found.getCounters(currentGame).getCount(type)); } - + /** * Assert counter count on a player * - * @param player The player whos counters should be counted. - * @param type Type of the counter that should be counted. - * @param count Expected count. + * @param player The player whos counters should be counted. + * @param type Type of the counter that should be counted. + * @param count Expected count. */ public void assertCounterCount(Player player, CounterType type, int count) throws AssertionError { Assert.assertEquals("(Battlefield) Counter counts are not equal (" + player.getName() + ":" + type + ")", count, player.getCounters().getCount(type)); @@ -632,9 +645,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert whether a permanent is a specified type or not * - * @param cardName Name of the permanent that should be checked. - * @param type A type to test for - * @param flag true if creature should have type, false if it should not + * @param cardName Name of the permanent that should be checked. + * @param type A type to test for + * @param flag true if creature should have type, false if it should not */ public void assertType(String cardName, CardType type, boolean flag) throws AssertionError { Permanent found = null; @@ -654,9 +667,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert whether a permanent is a specified type * - * @param cardName Name of the permanent that should be checked. - * @param type A type to test for - * @param subType a subtype to test for + * @param cardName Name of the permanent that should be checked. + * @param type A type to test for + * @param subType a subtype to test for */ public void assertType(String cardName, CardType type, String subType) throws AssertionError { Permanent found = null; @@ -677,14 +690,19 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert whether a permanent is tapped or not * - * @param cardName Name of the permanent that should be checked. - * @param tapped Whether the permanent is tapped or not + * @param cardName Name of the permanent that should be checked. + * @param tapped Whether the permanent is tapped or not */ public void assertTapped(String cardName, boolean tapped) throws AssertionError { Permanent found = null; for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents()) { if (permanent.getName().equals(cardName)) { - found = permanent; + if (found == null) { + found = permanent; + } else if (tapped != found.isTapped()) { // try to find a not correct permanent + found = permanent; + break; + } } } @@ -696,8 +714,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert whether a permanent is attacking or not * - * @param cardName Name of the permanent that should be checked. - * @param attacking Whether the permanent is attacking or not + * @param cardName Name of the permanent that should be checked. + * @param attacking Whether the permanent is attacking or not */ public void assertAttacking(String cardName, boolean attacking) throws AssertionError { Permanent found = null; @@ -715,8 +733,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in player's hand. * - * @param player {@link Player} who's hand should be counted. - * @param count Expected count. + * @param player {@link Player} who's hand should be counted. + * @param count Expected count. */ public void assertHandCount(Player player, int count) throws AssertionError { int actual = currentGame.getPlayer(player.getId()).getHand().size(); @@ -726,9 +744,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in player's hand. * - * @param player {@link Player} who's hand should be counted. - * @param cardName Name of the cards that should be counted. - * @param count Expected count. + * @param player {@link Player} who's hand should be counted. + * @param cardName Name of the cards that should be counted. + * @param count Expected count. */ public void assertHandCount(Player player, String cardName, int count) throws AssertionError { FilterCard filter = new FilterCard(); @@ -740,8 +758,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in player's graveyard. * - * @param player {@link Player} who's graveyard should be counted. - * @param count Expected count. + * @param player {@link Player} who's graveyard should be counted. + * @param count Expected count. */ public void assertGraveyardCount(Player player, int count) throws AssertionError { int actual = currentGame.getPlayer(player.getId()).getGraveyard().size(); @@ -751,12 +769,12 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in exile. * - * @param cardName Name of the cards that should be counted. - * @param count Expected count. + * @param cardName Name of the cards that should be counted. + * @param count Expected count. */ public void assertExileCount(String cardName, int count) throws AssertionError { int actualCount = 0; - for (ExileZone exile: currentGame.getExile().getExileZones()) { + for (ExileZone exile : currentGame.getExile().getExileZones()) { for (Card card : exile.getCards(currentGame)) { if (card.getName().equals(cardName)) { actualCount++; @@ -770,12 +788,12 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in exile by owner. * - * @param owner player that owns the cards. - * @param count Expected count. + * @param owner player that owns the cards. + * @param count Expected count. */ public void assertExileCount(Player owner, int count) throws AssertionError { int actualCount = 0; - for (ExileZone exile: currentGame.getExile().getExileZones()) { + for (ExileZone exile : currentGame.getExile().getExileZones()) { for (Card card : exile.getCards(currentGame)) { if (card.getOwnerId().equals(owner.getId())) { actualCount++; @@ -789,9 +807,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Assert card count in player's graveyard. * - * @param player {@link Player} who's graveyard should be counted. + * @param player {@link Player} who's graveyard should be counted. * @param cardName Name of the cards that should be counted. - * @param count Expected count. + * @param count Expected count. */ public void assertGraveyardCount(Player player, String cardName, int count) throws AssertionError { int actualCount = 0; @@ -805,7 +823,9 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * Asserts added actions count. Usefull to make sure that all actions were executed. + * Asserts added actions count. Usefull to make sure that all actions were + * executed. + * * @param player * @param count */ @@ -850,38 +870,42 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * + * * @param turnNum * @param step * @param player * @param cardName - * @param targetName for modes you can add "mode=3" before target name, multiple targets can be seperated by ^ + * @param targetName for modes you can add "mode=3" before target name, + * multiple targets can be seperated by ^ */ public void castSpell(int turnNum, PhaseStep step, TestPlayer player, String cardName, String targetName) { player.addAction(turnNum, step, "activate:Cast " + cardName + "$target=" + targetName); } public enum StackClause { + WHILE_ON_STACK, WHILE_NOT_ON_STACK; } /** - * Spell will only be cast, if a spell / ability with the given name is on the stack - * + * Spell will only be cast, if a spell / ability with the given name is on + * the stack + * * @param turnNum * @param step * @param player * @param cardName * @param targetName - * @param spellOnStack + * @param spellOnStack */ public void castSpell(int turnNum, PhaseStep step, TestPlayer player, String cardName, String targetName, String spellOnStack) { castSpell(turnNum, step, player, cardName, targetName, spellOnStack, StackClause.WHILE_ON_STACK); } /** - * Spell will only be cast, if a spell / ability with the given name IS or IS NOT on the stack + * Spell will only be cast, if a spell / ability with the given name IS or + * IS NOT on the stack * * @param turnNum * @param step @@ -927,18 +951,19 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } /** - * + * * @param turnNum * @param step * @param player * @param ability - * @param targetName if not target has to be defined use the constant NO_TARGET - * @param spellOnStack + * @param targetName if not target has to be defined use the constant + * NO_TARGET + * @param spellOnStack */ public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability, String targetName, String spellOnStack) { StringBuilder sb = new StringBuilder("activate:").append(ability); if (targetName != null && !targetName.isEmpty()) { - sb.append("$target=" ).append(targetName); + sb.append("$target=").append(targetName); } if (spellOnStack != null && !spellOnStack.isEmpty()) { sb.append("$spellOnStack=").append(spellOnStack); @@ -951,11 +976,11 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } public void attack(int turnNum, TestPlayer player, String attacker) { - player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:"+attacker); + player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:" + attacker); } - + public void attack(int turnNum, TestPlayer player, String attacker, TestPlayer defendingPlayer) { - player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:"+attacker+"$defendingPlayer="+defendingPlayer.getName()); + player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:" + attacker + "$defendingPlayer=" + defendingPlayer.getName()); } public void attack(int turnNum, TestPlayer player, String attacker, String planeswalker) { @@ -963,13 +988,13 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } public void block(int turnNum, TestPlayer player, String blocker, String attacker) { - player.addAction(turnNum, PhaseStep.DECLARE_BLOCKERS, "block:"+blocker+"$"+attacker); + player.addAction(turnNum, PhaseStep.DECLARE_BLOCKERS, "block:" + blocker + "$" + attacker); } /** - * For use choices set "Yes" or "No" the the choice string. - * For X values set "X=[xValue]" example: for X=3 set choice string to "X=3". - * + * For use choices set "Yes" or "No" the the choice string. For X values set + * "X=[xValue]" example: for X=3 set choice string to "X=3". + * * @param player * @param choice */ @@ -979,9 +1004,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement /** * Set the modes for modal spells - * + * * @param player - * @param choice starting with "1" for mode 1, "2" for mode 2 and so on (to set multiple modes call the command multiple times) + * @param choice starting with "1" for mode 1, "2" for mode 2 and so on (to + * set multiple modes call the command multiple times) */ public void setModeChoice(TestPlayer player, String choice) { player.addModeChoice(choice); @@ -991,39 +1017,39 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement * Set target permanents * * @param player - * @param target you can add multiple targets by seperating them by the "^" character - * e.g. "creatureName1^creatureName2" - * you can qualify the target additional by setcode - * e.g. "creatureName-M15" - * you can add [no copy] to the end of the target name to prohibite targets that are copied - * you can add [only copy] to the end of the target name to allow only targets that are copies + * @param target you can add multiple targets by seperating them by the "^" + * character e.g. "creatureName1^creatureName2" you can qualify the target + * additional by setcode e.g. "creatureName-M15" you can add [no copy] to + * the end of the target name to prohibite targets that are copied you can + * add [only copy] to the end of the target name to allow only targets that + * are copies */ public void addTarget(TestPlayer player, String target) { player.addTarget(target); } - + /** * Sets a player as target - * + * * @param player - * @param targetPlayer + * @param targetPlayer */ public void addTarget(TestPlayer player, TestPlayer targetPlayer) { - player.addTarget("targetPlayer="+targetPlayer.getName()); + player.addTarget("targetPlayer=" + targetPlayer.getName()); } - + public void setDecknamePlayerA(String deckname) { deckNameA = deckname; } - + public void setDecknamePlayerB(String deckname) { deckNameB = deckname; } - + protected void skipInitShuffling() { gameOptions.skipInitShuffling = true; } - + protected ExpectedType getExpectedType(String line) { if (line.startsWith("turn:")) { return ExpectedType.TURN_NUMBER; @@ -1042,7 +1068,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } return ExpectedType.UNKNOWN; } - + protected String getStringParam(String line, int index) { String[] params = line.split(":"); if (index > params.length - 1) { @@ -1050,7 +1076,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement } return params[index]; } - + protected void checkPermanentPT(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope) { if (currentGame == null) { throw new IllegalStateException("Current game is null"); @@ -1066,7 +1092,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement break; } } - } + } protected int getIntParam(String line, int index) { String[] params = line.split(":"); @@ -1074,6 +1100,6 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement throw new IllegalArgumentException("Not correct line: " + line); } return Integer.parseInt(params[index]); - } - + } + } diff --git a/Mage/src/mage/ObjectColor.java b/Mage/src/mage/ObjectColor.java index 812e45f187..c34ea4269d 100644 --- a/Mage/src/mage/ObjectColor.java +++ b/Mage/src/mage/ObjectColor.java @@ -1,31 +1,30 @@ /* -* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are -* permitted provided that the following conditions are met: -* -* 1. Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* -* 2. Redistributions in binary form must reproduce the above copyright notice, this list -* of conditions and the following disclaimer in the documentation and/or other materials -* provided with the distribution. -* -* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR -* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* The views and conclusions contained in the software and documentation are those of the -* authors and should not be interpreted as representing official policies, either expressed -* or implied, of BetaSteward_at_googlemail.com. -*/ - + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ package mage; import java.io.Serializable; @@ -50,26 +49,27 @@ public class ObjectColor implements Serializable, Copyable, Compara private boolean red; private boolean green; - public ObjectColor() {} + public ObjectColor() { + } public ObjectColor(String color) { for (int i = 0; i < color.length(); i++) { switch (color.charAt(i)) { - case 'W': - white = true; - break; - case 'U': - blue = true; - break; - case 'B': - black = true; - break; - case 'R': - red = true; - break; - case 'G': - green = true; - break; + case 'W': + white = true; + break; + case 'U': + blue = true; + break; + case 'B': + black = true; + break; + case 'R': + red = true; + break; + case 'G': + green = true; + break; } } } @@ -157,30 +157,39 @@ public class ObjectColor implements Serializable, Copyable, Compara public boolean isWhite() { return white; } + public void setWhite(boolean white) { this.white = white; } + public boolean isBlue() { return blue; } + public void setBlue(boolean blue) { this.blue = blue; } + public boolean isBlack() { return black; } + public void setBlack(boolean black) { this.black = black; } + public boolean isRed() { return red; } + public void setRed(boolean red) { this.red = red; } + public boolean isGreen() { return green; } + public void setGreen(boolean green) { this.green = green; } @@ -287,14 +296,10 @@ public class ObjectColor implements Serializable, Copyable, Compara } public boolean shares(ObjectColor color) { - if (this == color) { - return true; - } - if (!hasColor() && !color.hasColor()) { - return true; - } - return color.white && white || color.blue && blue || color.black && black || - color.red && red || color.green && green; + // 105.4. [...] “Multicolored” is not a color. Neither is “colorless.” + return !color.isColorless() + && (color.white && white || color.blue && blue || color.black && black + || color.red && red || color.green && green); } @Override @@ -309,32 +314,32 @@ public class ObjectColor implements Serializable, Copyable, Compara if (this.isMulticolored()) { o1 = 6; - } else if(this.isColorless()) { + } else if (this.isColorless()) { o1 = 0; - } else if(this.isBlack()) { + } else if (this.isBlack()) { o1 = 1; - } else if(this.isBlue()) { + } else if (this.isBlue()) { o1 = 2; - } else if(this.isGreen()) { + } else if (this.isGreen()) { o1 = 3; - } else if(this.isRed()) { + } else if (this.isRed()) { o1 = 4; - } else if(this.isWhite()) { + } else if (this.isWhite()) { o1 = 5; } if (o.isMulticolored()) { o2 = 6; - } else if(o.isColorless()) { + } else if (o.isColorless()) { o2 = 0; - } else if(o.isBlack()) { + } else if (o.isBlack()) { o2 = 1; - } else if(o.isBlue()) { + } else if (o.isBlue()) { o2 = 2; - } else if(o.isGreen()) { + } else if (o.isGreen()) { o2 = 3; - } else if(o.isRed()) { + } else if (o.isRed()) { o2 = 4; - } else if(o.isWhite()) { + } else if (o.isWhite()) { o2 = 5; } return o1 - o2; diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 4fcd9df58f..6b8185d257 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -2459,6 +2459,22 @@ public abstract class PlayerImpl implements Player, Serializable { } } } + // check if it's possible to play the top card of a library + for (UUID playerInRangeId : game.getState().getPlayersInRange(getId(), game)) { + Player player = game.getPlayer(playerInRangeId); + if (player != null) { + if (player.isTopCardRevealed() && player.getLibrary().size() > 0) { + Card card = player.getLibrary().getFromTop(game); + if (game.getContinuousEffects().asThough(card.getId(), AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, getId(), game)) { + for (ActivatedAbility ability : card.getAbilities().getActivatedAbilities(Zone.HAND)) { + if (ability instanceof SpellAbility || ability instanceof PlayLandAbility) { + playable.add(ability); + } + } + } + } + } + } // eliminate duplicate activated abilities Map playableActivated = new HashMap<>(); for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {