From fdcc365926e8fd4eea7dcf44df8ae36be7fd291e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 11 May 2015 12:18:07 +0200 Subject: [PATCH] * Fixed that cyle triggered abilities did not work. --- .../mage/sets/urzassaga/DiscipleOfGrace.java | 8 +- .../cards/abilities/keywords/CycleTest.java | 117 ++++++++++++++++++ .../common/CycleTriggeredAbility.java | 7 -- Mage/src/mage/players/PlayerImpl.java | 45 ++++--- 4 files changed, 150 insertions(+), 27 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CycleTest.java diff --git a/Mage.Sets/src/mage/sets/urzassaga/DiscipleOfGrace.java b/Mage.Sets/src/mage/sets/urzassaga/DiscipleOfGrace.java index d4a5894d252..b271ba24413 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/DiscipleOfGrace.java +++ b/Mage.Sets/src/mage/sets/urzassaga/DiscipleOfGrace.java @@ -46,7 +46,7 @@ import java.util.UUID; */ public class DiscipleOfGrace extends CardImpl { - private static final FilterCard filter = new FilterCard("Black"); + private static final FilterCard filter = new FilterCard("black"); static { filter.add(new ColorPredicate(ObjectColor.BLACK)); @@ -57,10 +57,14 @@ public class DiscipleOfGrace extends CardImpl { this.expansionSetCode = "USG"; this.subtype.add("Human"); this.subtype.add("Cleric"); - this.color.setWhite(true); + this.power = new MageInt(1); this.toughness = new MageInt(2); + + // Protection from black this.addAbility(new ProtectionAbility(filter)); + + // Cycling {2} ({2}, Discard this card: Draw a card.) this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CycleTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CycleTest.java new file mode 100644 index 00000000000..a0f1f8e8dd5 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CycleTest.java @@ -0,0 +1,117 @@ +/* + * 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.abilities.keywords; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class CycleTest extends CardTestPlayerBase { + + /** + * 702.28. Cycling + * 702.28a Cycling is an activated ability that functions only while the card with cycling is in a player’s hand. + * “Cycling [cost]” means “[Cost], Discard this card: Draw a card.” + * 702.28b Although the cycling ability is playable only if the card is in a player’s hand, it continues to exist + * while the object is in play and in all other zones. Therefore objects with cycling will be affected by + * effects that depend on objects having one or more activated abilities. + * 702.28c Some cards with cycling have abilities that trigger when they’re cycled. “When you cycle [this card]” means + * “When you discard [this card] to pay a cycling cost.” These abilities trigger from whatever zone the card + * winds up in after it’s cycled. + * 702.28d Typecycling is a variant of the cycling ability. “[Type]cycling [cost]” means “[Cost], Discard this card: + * Search your library for a [type] card, reveal it, and put it into your hand. Then shuffle your library.” + * This type is usually a subtype (as in “mountaincycling”) but can be any card type, subtype, supertype, or + * combination thereof (as in “basic landcycling”). + * 702.28e Typecycling abilities are cycling abilities, and typecycling costs are cycling costs. Any cards that trigger + * when a player cycles a card will trigger when a card is discarded to pay a typecycling cost. Any effect that + * stops players from cycling cards will stop players from activating cards’ typecycling abilities. Any effect + * that increases or reduces a cycling cost will increase or reduce a typecycling cost. + */ + + @Test + public void CycleAndTriggerTest() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5); + // Destroy all creatures. They can't be regenerated. Draw a card for each creature destroyed this way. + // Cycling {3}{B}{B} + // When you cycle Decree of Pain, all creatures get -2/-2 until end of turn. + addCard(Zone.HAND, playerA, "Decree of Pain"); + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); + addCard(Zone.BATTLEFIELD, playerB, "Pillarfield Ox", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cycling {3}{B}{B}"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, 1); + + assertGraveyardCount(playerA, "Decree of Pain", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 0); + + assertPermanentCount(playerB, "Pillarfield Ox", 1); + assertPowerToughness(playerB, "Pillarfield Ox", 0, 2); + + + } + + /** + * Cycle from graveyard or battlefield may not work + */ + @Test + public void CycleFromGraveyard() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5); + // Destroy all creatures. They can't be regenerated. Draw a card for each creature destroyed this way. + // Cycling {3}{B}{B} + // When you cycle Decree of Pain, all creatures get -2/-2 until end of turn. + addCard(Zone.GRAVEYARD, playerA, "Decree of Pain"); + // Protection from black + // Cycling {2} ({2}, Discard this card: Draw a card.) + addCard(Zone.BATTLEFIELD, playerB, "Disciple Of Grace"); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cycling {3}{B}{B}"); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cycling {2}"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertHandCount(playerA, 0); + assertHandCount(playerB, 0); + + assertGraveyardCount(playerA, "Decree of Pain", 1); + assertPermanentCount(playerB, "Disciple Of Grace", 1); + + } + +} diff --git a/Mage/src/mage/abilities/common/CycleTriggeredAbility.java b/Mage/src/mage/abilities/common/CycleTriggeredAbility.java index ea8351356eb..537b75691d2 100644 --- a/Mage/src/mage/abilities/common/CycleTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/CycleTriggeredAbility.java @@ -28,13 +28,11 @@ package mage.abilities.common; -import mage.MageObject; import mage.abilities.effects.Effect; import mage.abilities.keyword.CyclingAbility; import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.stack.StackObject; /** @@ -55,11 +53,6 @@ public class CycleTriggeredAbility extends ZoneChangeTriggeredAbility { super(ability); } - @Override - public boolean isInUseableZone(Game game, MageObject source, GameEvent event) { - return game.getState().getZone(getSourceId()).equals(Zone.HAND) && hasSourceObjectAbility(game, source, event); - } - @Override public boolean checkEventType(GameEvent event, Game game) { return event.getType() == GameEvent.EventType.ACTIVATED_ABILITY; diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 6c3b0d77d5c..6a35a5da6d6 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -639,8 +639,9 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void discardToMax(Game game) { if (hand.size() > this.maxHandSize) { - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(getLogName() + " discards down to " + this.maxHandSize + (this.maxHandSize == 1 ? " hand card" : " hand cards")); + } discard(hand.size() - this.maxHandSize, null, game); } } @@ -733,8 +734,9 @@ public abstract class PlayerImpl implements Player, Serializable { */ if (card != null) { // write info to game log first so game log infos from triggered or replacement effects follow in the game log - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(getLogName() + " discards " + card.getLogName()); + } /* If a card is discarded while Rest in Peace is on the battlefield, abilities that function * when a card is discarded (such as madness) still work, even though that card never reaches * a graveyard. In addition, spells or abilities that check the characteristics of a discarded @@ -1034,8 +1036,9 @@ public abstract class PlayerImpl implements Player, Serializable { game.getStack().push(new StackAbility(ability, playerId)); if (ability.activate(game, false)) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, ability.getId(), ability.getSourceId(), playerId)); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(getLogName() + ability.getGameLogMessage(game)); + } game.removeBookmark(bookmark); resetStoredBookmark(game); return true; @@ -1061,8 +1064,9 @@ public abstract class PlayerImpl implements Player, Serializable { int bookmark = game.bookmarkState(); if (action.activate(game, false)) { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, action.getSourceId(), action.getId(), playerId)); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(getLogName() + action.getGameLogMessage(game)); + } if (action.resolve(game)) { game.removeBookmark(bookmark); resetStoredBookmark(game); @@ -1287,8 +1291,9 @@ public abstract class PlayerImpl implements Player, Serializable { public void shuffleLibrary(Game game) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.SHUFFLE_LIBRARY, playerId, playerId))) { this.library.shuffle(); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(getLogName() + " shuffles his or her library."); + } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SHUFFLED, playerId, playerId)); } } @@ -1585,8 +1590,9 @@ public abstract class PlayerImpl implements Player, Serializable { GameEvent event = new GameEvent(GameEvent.EventType.LOSE_LIFE, playerId, playerId, playerId, amount, false); if (!game.replaceEvent(event)) { this.life -= event.getAmount(); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(this.getLogName() + " loses " + event.getAmount() + " life"); + } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST_LIFE, playerId, playerId, playerId, amount)); return amount; } @@ -2055,8 +2061,9 @@ public abstract class PlayerImpl implements Player, Serializable { } GameEvent event = GameEvent.getEvent(GameEvent.EventType.SEARCH_LIBRARY, targetPlayerId, playerId, playerId, Integer.MAX_VALUE); if (!game.replaceEvent(event)) { - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(searchInfo); + } TargetCardInLibrary newTarget = target.copy(); int count; int librarySearchLimit = event.getAmount(); @@ -2096,8 +2103,9 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean flipCoin(Game game, ArrayList appliedEffects) { boolean result = rnd.nextBoolean(); - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers("[Flip a coin] " + getLogName() + (result ? " won (head)." : " lost (tail).")); + } GameEvent event = new GameEvent(GameEvent.EventType.FLIP_COIN, playerId, null, playerId, 0, result); event.setAppliedEffects(appliedEffects); game.replaceEvent(event); @@ -2287,12 +2295,12 @@ public abstract class PlayerImpl implements Player, Serializable { } // controller specific alternate spell costs - for (AlternativeSourceCosts alternativeSourceCosts: getAlternativeSourceCosts()) { - if (alternativeSourceCosts instanceof Ability) { - if (((AlternativeSourceCosts) alternativeSourceCosts).isAvailable(ability, game)) { - if (((Ability) alternativeSourceCosts).getCosts().canPay(ability, playerId, playerId, game)) { + for (AlternativeSourceCosts alternateSourceCosts: getAlternativeSourceCosts()) { + if (alternateSourceCosts instanceof Ability) { + if (alternateSourceCosts.isAvailable(ability, game)) { + if (((Ability) alternateSourceCosts).getCosts().canPay(ability, playerId, playerId, game)) { ManaCostsImpl manaCosts = new ManaCostsImpl(); - for (Cost cost : ((Ability) alternativeSourceCosts).getCosts()) { + for (Cost cost : ((Ability) alternateSourceCosts).getCosts()) { if (cost instanceof ManaCost) { manaCosts.add((ManaCost) cost); } @@ -2884,7 +2892,7 @@ public abstract class PlayerImpl implements Player, Serializable { } boolean chooseOrder = true; if (cards.size() > 2) { - chooseOrder = choosingPlayer.chooseUse(Outcome.Neutral, "Do you like to choose the order the cards go to graveyard?", game); + chooseOrder = choosingPlayer.chooseUse(Outcome.Neutral, "Would you like to choose the order the cards go to graveyard?", game); } if (chooseOrder) { while (choosingPlayer.isInGame() && cards.size() > 1) { @@ -2997,11 +3005,12 @@ public abstract class PlayerImpl implements Player, Serializable { public boolean putOntoBattlefieldWithInfo(Card card, Game game, Zone fromZone, UUID sourceId, boolean tapped, boolean facedown) { boolean result = false; if (card.putOntoBattlefield(game, fromZone, sourceId, this.getId(), tapped, facedown)) { - if (!game.isSimulation()) + if (!game.isSimulation()) { game.informPlayers(new StringBuilder(this.getLogName()) - .append(" puts ").append(facedown ? "a card face down ":card.getLogName()) - .append(" from ").append(fromZone.toString().toLowerCase(Locale.ENGLISH)).append(" ") - .append("onto the Battlefield").toString()); + .append(" puts ").append(facedown ? "a card face down ":card.getLogName()) + .append(" from ").append(fromZone.toString().toLowerCase(Locale.ENGLISH)).append(" ") + .append("onto the Battlefield").toString()); + } result = true; } return result;