diff --git a/Mage.Sets/src/mage/sets/tempest/VerdantForce.java b/Mage.Sets/src/mage/sets/tempest/VerdantForce.java index 4377abe9c5..b383f7df44 100644 --- a/Mage.Sets/src/mage/sets/tempest/VerdantForce.java +++ b/Mage.Sets/src/mage/sets/tempest/VerdantForce.java @@ -28,13 +28,12 @@ package mage.sets.tempest; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; import mage.MageInt; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.effects.common.CreateTokenEffect; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; import mage.constants.TargetController; import mage.game.permanent.token.SaprolingToken; @@ -51,6 +50,8 @@ public class VerdantForce extends CardImpl { this.power = new MageInt(7); this.toughness = new MageInt(7); + + // At the beginning of each upkeep, put a 1/1 green Saproling creature token onto the battlefield. this.addAbility(new BeginningOfUpkeepTriggeredAbility(new CreateTokenEffect(new SaprolingToken()), TargetController.ANY, false)); } diff --git a/Mage.Sets/src/mage/sets/timespiral/ParadoxHaze.java b/Mage.Sets/src/mage/sets/timespiral/ParadoxHaze.java index 40c612225b..76b84e06c3 100644 --- a/Mage.Sets/src/mage/sets/timespiral/ParadoxHaze.java +++ b/Mage.Sets/src/mage/sets/timespiral/ParadoxHaze.java @@ -47,6 +47,7 @@ import mage.game.turn.UpkeepStep; import mage.players.Player; import mage.target.TargetPlayer; import mage.target.targetpointer.FixedTarget; +import mage.watchers.common.FirstTimeStepWatcher; /** * @@ -59,15 +60,14 @@ public class ParadoxHaze extends CardImpl { this.expansionSetCode = "TSP"; this.subtype.add("Aura"); - // Enchant player TargetPlayer auraTarget = new TargetPlayer(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Neutral)); this.addAbility(new EnchantAbility(auraTarget.getTargetName())); - + // At the beginning of enchanted player's first upkeep each turn, that player gets an additional upkeep step after this step. - this.addAbility(new ParadoxHazeTriggeredAbility()); + this.addAbility(new ParadoxHazeTriggeredAbility(), new FirstTimeStepWatcher(EventType.UPKEEP_STEP_POST)); } public ParadoxHaze(final ParadoxHaze card) { @@ -81,18 +81,15 @@ public class ParadoxHaze extends CardImpl { } class ParadoxHazeTriggeredAbility extends TriggeredAbilityImpl { - - protected int lastTriggerTurnNumber; - + ParadoxHazeTriggeredAbility() { super(Zone.BATTLEFIELD, new ParadoxHazeEffect(), false); } - + ParadoxHazeTriggeredAbility(final ParadoxHazeTriggeredAbility ability) { super(ability); - lastTriggerTurnNumber = ability.lastTriggerTurnNumber; } - + @Override public ParadoxHazeTriggeredAbility copy() { return new ParadoxHazeTriggeredAbility(this); @@ -102,21 +99,23 @@ class ParadoxHazeTriggeredAbility extends TriggeredAbilityImpl { public boolean checkEventType(GameEvent event, Game game) { return event.getType() == EventType.UPKEEP_STEP_PRE; } - + @Override public boolean checkTrigger(GameEvent event, Game game) { - Permanent permanent = game.getPermanent(this.sourceId); + Permanent permanent = game.getPermanent(getSourceId()); if (permanent != null) { Player player = game.getPlayer(permanent.getAttachedTo()); - if (player != null && game.getActivePlayerId().equals(player.getId()) && lastTriggerTurnNumber != game.getTurnNum()) { - lastTriggerTurnNumber = game.getTurnNum(); - this.getEffects().get(0).setTargetPointer(new FixedTarget(player.getId())); - return true; + if (player != null && game.getActivePlayerId().equals(player.getId())) { + FirstTimeStepWatcher watcher = (FirstTimeStepWatcher) game.getState().getWatchers().get(EventType.UPKEEP_STEP_POST.toString() + FirstTimeStepWatcher.class.getName()); + if (watcher != null && !watcher.conditionMet()) { + this.getEffects().get(0).setTargetPointer(new FixedTarget(player.getId())); + return true; + } } } return false; } - + @Override public String getRule() { return "At the beginning of enchanted player's first upkeep each turn, that player gets an additional upkeep step after this step."; @@ -124,21 +123,21 @@ class ParadoxHazeTriggeredAbility extends TriggeredAbilityImpl { } class ParadoxHazeEffect extends OneShotEffect { - + ParadoxHazeEffect() { super(Outcome.Benefit); this.staticText = "that player gets an additional upkeep step after this step"; } - + ParadoxHazeEffect(final ParadoxHazeEffect effect) { super(effect); } - + @Override public ParadoxHazeEffect copy() { return new ParadoxHazeEffect(this); } - + @Override public boolean apply(Game game, Ability source) { game.getState().getTurnMods().add(new TurnMod(this.getTargetPointer().getFirst(game, source), new UpkeepStep(), null)); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/enchantments/ParadoxHazeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/enchantments/ParadoxHazeTest.java new file mode 100644 index 0000000000..917e25519d --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/enchantments/ParadoxHazeTest.java @@ -0,0 +1,88 @@ +/* + * 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.enchantments; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class ParadoxHazeTest extends CardTestPlayerBase { + + @Test + public void testNormal() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 3); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 8); + // Enchant player + // At the beginning of enchanted player's first upkeep each turn, that player gets an additional upkeep step after this step. + addCard(Zone.HAND, playerA, "Paradox Haze", 1); // {2}{U} + // At the beginning of each upkeep, put a 1/1 green Saproling creature token onto the battlefield. + addCard(Zone.HAND, playerA, "Verdant Force", 1); // {5}{G}{G}{G} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Paradox Haze", playerA); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Verdant Force"); + + setStopAt(3, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertPermanentCount(playerA, "Paradox Haze", 1); + assertPermanentCount(playerA, "Verdant Force", 1); + assertPermanentCount(playerA, "Saproling", 3);// 1 from turn 2 and 2 from turn 3 + } + + @Test + public void testCopied() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 6); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 8); + // Enchant player + // At the beginning of enchanted player's first upkeep each turn, that player gets an additional upkeep step after this step. + addCard(Zone.HAND, playerA, "Paradox Haze", 1); // {2}{U} + + // You may have Copy Enchantment enter the battlefield as a copy of any enchantment on the battlefield. + addCard(Zone.HAND, playerA, "Copy Enchantment", 1); // {2}{U} + + // At the beginning of each upkeep, put a 1/1 green Saproling creature token onto the battlefield. + addCard(Zone.HAND, playerA, "Verdant Force", 1); // {5}{G}{G}{G} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Paradox Haze", playerA); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Copy Enchantment"); + setChoice(playerA, "Paradox Haze"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Verdant Force"); + + setStopAt(3, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertPermanentCount(playerA, "Paradox Haze", 2); + assertPermanentCount(playerA, "Verdant Force", 1); + assertPermanentCount(playerA, "Saproling", 4); // 1 from turn 2 and 3 from turn 3 + } +} diff --git a/Mage/src/mage/watchers/common/FirstTimeStepWatcher.java b/Mage/src/mage/watchers/common/FirstTimeStepWatcher.java new file mode 100644 index 0000000000..911a3ecf93 --- /dev/null +++ b/Mage/src/mage/watchers/common/FirstTimeStepWatcher.java @@ -0,0 +1,72 @@ +/* + * 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.watchers.common; + +import mage.constants.WatcherScope; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.watchers.Watcher; + +/** + * The wachter checks if a specific phase event has already happened during the + * current turn. If not it returns false, otheriwsed true. + * + * @author LevelX2 + */ +public class FirstTimeStepWatcher extends Watcher { + + private final EventType eventType; + + public FirstTimeStepWatcher(EventType eventType) { + super(eventType.toString() + FirstTimeStepWatcher.class.getName(), WatcherScope.GAME); + this.eventType = eventType; + } + + public FirstTimeStepWatcher(final FirstTimeStepWatcher watcher) { + super(watcher); + this.eventType = watcher.eventType; + } + + @Override + public FirstTimeStepWatcher copy() { + return new FirstTimeStepWatcher(this); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == eventType) { + condition = true; + } + } + + @Override + public void reset() { + super.reset(); + } +}