From 04717714517851f508a54f98df4d631868dfaca4 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 29 Aug 2012 22:45:35 +0400 Subject: [PATCH] [ROE] 4 cards with tests. ROE is 100% implemented. --- .../riseoftheeldrazi/CastThroughTime.java | 167 ++++++++++++++++ .../riseoftheeldrazi/SpawnsireOfUlamog.java | 85 ++++++++ .../riseoftheeldrazi/WarmongersChariot.java | 112 +++++++++++ .../sets/riseoftheeldrazi/WorldAtWar.java | 186 ++++++++++++++++++ .../cards/single/roe/CastThroughTimeTest.java | 108 ++++++++++ .../test/cards/single/roe/WorldAtWarTest.java | 102 ++++++++++ .../CastCardFromOursideTheGameEffect.java | 99 ++++++++++ .../common/AttackedThisTurnWatcher.java | 77 ++++++++ 8 files changed, 936 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java create mode 100644 Mage.Sets/src/mage/sets/riseoftheeldrazi/SpawnsireOfUlamog.java create mode 100644 Mage.Sets/src/mage/sets/riseoftheeldrazi/WarmongersChariot.java create mode 100644 Mage.Sets/src/mage/sets/riseoftheeldrazi/WorldAtWar.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/roe/CastThroughTimeTest.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/roe/WorldAtWarTest.java create mode 100644 Mage/src/mage/abilities/effects/common/CastCardFromOursideTheGameEffect.java create mode 100644 Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java new file mode 100644 index 00000000000..0b980bd7c10 --- /dev/null +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/CastThroughTime.java @@ -0,0 +1,167 @@ +/* + * 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.sets.riseoftheeldrazi; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.keyword.ReboundAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.filter.FilterCard; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.watchers.WatcherImpl; + +import java.util.Iterator; +import java.util.UUID; + +/** + * @author magenoxx_at_gmail.com + */ +public class CastThroughTime extends CardImpl { + + protected static final FilterCard filter = new FilterCard("Instant and sorcery spells you control"); + + static { + filter.add(Predicates.or(new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY))); + } + + public CastThroughTime(UUID ownerId) { + super(ownerId, 55, "Cast Through Time", Rarity.MYTHIC, new CardType[]{CardType.ENCHANTMENT}, "{4}{U}{U}{U}"); + this.expansionSetCode = "ROE"; + + this.color.setBlue(true); + + // Instant and sorcery spells you control have rebound. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new GainReboundEffect())); + + this.addWatcher(new LeavesBattlefieldWatcher()); + } + + public CastThroughTime(final CastThroughTime card) { + super(card); + } + + @Override + public CastThroughTime copy() { + return new CastThroughTime(this); + } +} + +class GainReboundEffect extends ContinuousEffectImpl { + + public GainReboundEffect() { + super(Constants.Duration.Custom, Constants.Layer.AbilityAddingRemovingEffects_6, Constants.SubLayer.NA, Constants.Outcome.AddAbility); + staticText = "Instant and sorcery spells you control have rebound"; + } + + public GainReboundEffect(final GainReboundEffect effect) { + super(effect); + } + + @Override + public GainReboundEffect copy() { + return new GainReboundEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = game.getPermanent(source.getSourceId()); + if (player != null && permanent != null) { + for (Card card : player.getHand().getCards(CastThroughTime.filter, game)) { + boolean found = false; + for (Ability ability : card.getAbilities()) { + if (ability instanceof ReboundAbility) { + found = true; + break; + } + } + if (!found) { + card.addAbility(new AttachedReboundAbility()); + Ability ability = new AttachedReboundAbility(); + ability.setControllerId(source.getControllerId()); + ability.setSourceId(card.getId()); + game.getState().addAbility(ability, source.getSourceId(), card); + } + } + + return true; + } + return false; + } + + private class AttachedReboundAbility extends ReboundAbility {} +} + +class LeavesBattlefieldWatcher extends WatcherImpl { + + public LeavesBattlefieldWatcher() { + super("LeavesBattlefieldWatcher", Constants.WatcherScope.CARD); + } + + public LeavesBattlefieldWatcher(final LeavesBattlefieldWatcher watcher) { + super(watcher); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId())) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD) { + Player player = game.getPlayer(this.getControllerId()); + if (player != null) { + for (Card card : player.getHand().getCards(CastThroughTime.filter, game)) { + Iterator it = card.getAbilities().iterator(); + while (it.hasNext()) { + if (it.next() instanceof ReboundAbility) { + it.remove(); + } + } + } + } + } + } + } + + @Override + public LeavesBattlefieldWatcher copy() { + return new LeavesBattlefieldWatcher(this); + } + +} + diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/SpawnsireOfUlamog.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/SpawnsireOfUlamog.java new file mode 100644 index 00000000000..6fa9513dd35 --- /dev/null +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/SpawnsireOfUlamog.java @@ -0,0 +1,85 @@ +/* + * 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.sets.riseoftheeldrazi; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.common.CastCardFromOursideTheGameEffect; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.keyword.AnnihilatorAbility; +import mage.cards.CardImpl; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.game.permanent.token.EldraziSpawnToken; + +import java.util.UUID; + +/** + * @author magenoxx_at_gmail.com + */ +public class SpawnsireOfUlamog extends CardImpl { + + private static final String ruleText = "Cast any number of Eldrazi cards you own from outside the game without paying their mana costs"; + + private static final FilterCard filter = new FilterCard("Eldrazi cards"); + + static { + filter.add(new SubtypePredicate("Eldrazi")); + } + + public SpawnsireOfUlamog(UUID ownerId) { + super(ownerId, 11, "Spawnsire of Ulamog", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{10}"); + this.expansionSetCode = "ROE"; + this.subtype.add("Eldrazi"); + + this.power = new MageInt(7); + this.toughness = new MageInt(11); + + // Annihilator 1 + this.addAbility(new AnnihilatorAbility(1)); + + // {4}: Put two 0/1 colorless Eldrazi Spawn creature tokens onto the battlefield. They have "Sacrifice this creature: Add {1} to your mana pool." + this.addAbility(new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new CreateTokenEffect(new EldraziSpawnToken(), 2), new GenericManaCost(4))); + + // {20}: Cast any number of Eldrazi cards you own from outside the game without paying their mana costs. + this.addAbility(new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new CastCardFromOursideTheGameEffect(filter, ruleText), new GenericManaCost(20))); + } + + public SpawnsireOfUlamog(final SpawnsireOfUlamog card) { + super(card); + } + + @Override + public SpawnsireOfUlamog copy() { + return new SpawnsireOfUlamog(this); + } +} diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/WarmongersChariot.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/WarmongersChariot.java new file mode 100644 index 00000000000..37c62f090a0 --- /dev/null +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/WarmongersChariot.java @@ -0,0 +1,112 @@ +/* + * 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.sets.riseoftheeldrazi; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.common.continious.BoostEquippedEffect; +import mage.abilities.keyword.DefenderAbility; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +import java.util.UUID; + +/** + * @author magenoxx_at_gmail.com + */ +public class WarmongersChariot extends CardImpl { + + private static final String staticText = "As long as equipped creature has defender, it can attack as though it didn't have defender"; + + public WarmongersChariot(UUID ownerId) { + super(ownerId, 226, "Warmonger's Chariot", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}"); + this.expansionSetCode = "ROE"; + this.subtype.add("Equipment"); + + // Equipped creature gets +2/+2. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new BoostEquippedEffect(2, 2))); + + // As long as equipped creature has defender, it can attack as though it didn't have defender. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new WarmongersChariotEffect())); + + // Equip {3} + this.addAbility(new EquipAbility(Constants.Outcome.AddAbility, new GenericManaCost(3))); + } + + public WarmongersChariot(final WarmongersChariot card) { + super(card); + } + + @Override + public WarmongersChariot copy() { + return new WarmongersChariot(this); + } +} + +class WarmongersChariotEffect extends AsThoughEffectImpl { + + public WarmongersChariotEffect() { + super(Constants.AsThoughEffectType.ATTACK, Constants.Duration.WhileOnBattlefield, Constants.Outcome.Benefit); + staticText = "As long as equipped creature has defender, it can attack as though it didn't have defender"; + } + + public WarmongersChariotEffect(final WarmongersChariotEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public WarmongersChariotEffect copy() { + return new WarmongersChariotEffect(this); + } + + @Override + public boolean applies(UUID sourceId, Ability source, Game game) { + Permanent equipment = game.getPermanent(source.getSourceId()); + if (equipment != null && equipment.getAttachedTo() != null) { + Permanent creature = game.getPermanent(equipment.getAttachedTo()); + if (creature != null && creature.getId().equals(sourceId) + && creature.getAbilities().containsKey(DefenderAbility.getInstance().getId())) { + return true; + } + } + return false; + } + +} diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/WorldAtWar.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/WorldAtWar.java new file mode 100644 index 00000000000..4d1d5b63dc0 --- /dev/null +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/WorldAtWar.java @@ -0,0 +1,186 @@ +/* + * 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.sets.riseoftheeldrazi; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.keyword.ReboundAbility; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.turn.TurnMod; +import mage.watchers.Watcher; +import mage.watchers.common.AttackedThisTurnWatcher; + +import java.util.Set; +import java.util.UUID; + +/** + * @author magenoxx_at_gmail.com + */ +public class WorldAtWar extends CardImpl { + + public WorldAtWar(UUID ownerId) { + super(ownerId, 172, "World at War", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{R}{R}"); + this.expansionSetCode = "ROE"; + + this.color.setRed(true); + + // After the first postcombat main phase this turn, there's an additional combat phase followed by an additional main phase. At the beginning of that combat, untap all creatures that attacked this turn. + this.getSpellAbility().addEffect(new WorldAtWarEffect()); + + // Rebound + this.addAbility(new ReboundAbility()); + + this.addWatcher(new AttackedThisTurnWatcher()); + } + + public WorldAtWar(final WorldAtWar card) { + super(card); + } + + @Override + public WorldAtWar copy() { + return new WorldAtWar(this); + } +} + +class WorldAtWarEffect extends OneShotEffect { + + public WorldAtWarEffect() { + super(Constants.Outcome.Benefit); + staticText = "After the first postcombat main phase this turn, there's an additional combat phase followed by an additional main phase. At the beginning of that combat, untap all creatures that attacked this turn"; + } + + public WorldAtWarEffect(final WorldAtWarEffect effect) { + super(effect); + } + + @Override + public WorldAtWarEffect copy() { + return new WorldAtWarEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + // we can't add two turn modes at once, will add additional post combat on delayed trigger resolution + TurnMod combat = new TurnMod(source.getControllerId(), Constants.TurnPhase.COMBAT, Constants.TurnPhase.POSTCOMBAT_MAIN, false); + game.getState().getTurnMods().add(combat); + UntapDelayedTriggeredAbility delayedTriggeredAbility = new UntapDelayedTriggeredAbility(); + delayedTriggeredAbility.setSourceId(source.getSourceId()); + delayedTriggeredAbility.setControllerId(source.getControllerId()); + delayedTriggeredAbility.setConnectedTurnMod(combat.getId()); + game.addDelayedTriggeredAbility(delayedTriggeredAbility); + return true; + } + +} + +class UntapDelayedTriggeredAbility extends DelayedTriggeredAbility { + + private UUID connectedTurnMod; + private boolean enabled; + + public UntapDelayedTriggeredAbility() { + super(new UntapAttackingThisTurnEffect()); + } + + public UntapDelayedTriggeredAbility(UntapDelayedTriggeredAbility ability) { + super(ability); + this.connectedTurnMod = ability.connectedTurnMod; + this.enabled = ability.enabled; + } + + @Override + public UntapDelayedTriggeredAbility copy() { + return new UntapDelayedTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.PHASE_CHANGED && this.connectedTurnMod.equals(event.getSourceId())) { + enabled = true; + return false; + } + if (event.getType() == GameEvent.EventType.COMBAT_PHASE_PRE && enabled) { + // add additional post combat phase after that + game.getState().getTurnMods().add(new TurnMod(getControllerId(), Constants.TurnPhase.POSTCOMBAT_MAIN, Constants.TurnPhase.COMBAT, false)); + enabled = false; + return true; + } + return false; + } + + public void setConnectedTurnMod(UUID connectedTurnMod) { + this.connectedTurnMod = connectedTurnMod; + } + + @Override + public String getRule() { + return "At the beginning of that combat, untap all creatures that attacked this turn"; + } +} + +class UntapAttackingThisTurnEffect extends OneShotEffect { + + public UntapAttackingThisTurnEffect() { + super(Constants.Outcome.Benefit); + } + + public UntapAttackingThisTurnEffect(final UntapAttackingThisTurnEffect effect) { + super(effect); + } + + @Override + public UntapAttackingThisTurnEffect copy() { + return new UntapAttackingThisTurnEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Watcher watcher = game.getState().getWatchers().get("AttackedThisTurn"); + if (watcher != null && watcher instanceof AttackedThisTurnWatcher) { + Set attackedThisTurn = ((AttackedThisTurnWatcher)watcher).getAttackedThisTurnCreatures(); + for (UUID uuid : attackedThisTurn) { + Permanent permanent = game.getPermanent(uuid); + if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) { + permanent.untap(game); + } + } + } + return true; + } + +} + + diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/CastThroughTimeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/CastThroughTimeTest.java new file mode 100644 index 00000000000..1dab8eac126 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/CastThroughTimeTest.java @@ -0,0 +1,108 @@ +package org.mage.test.cards.single.roe; + +import mage.Constants; +import mage.cards.Card; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author magenoxx_at_gmail.com + */ +public class CastThroughTimeTest extends CardTestPlayerBase { + + /** + * Tests Rebound works with a card that has no Rebound itself + */ + @Test + public void testCastWithRebound() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Cast Through Time"); + addCard(Constants.Zone.HAND, playerA, "Lightning Bolt"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(3, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerB, 14); + } + + /** + * Tests rebound from two Cast Through Time instances + * Should have no effect for second copy + */ + @Test + public void testCastWithDoubleRebound() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Cast Through Time", 2); + addCard(Constants.Zone.HAND, playerA, "Lightning Bolt"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(3, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerB, 14); + } + + /** + * Tests rebound tooltip + */ + @Test + public void testReboundTooltipExists() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Cast Through Time"); + addCard(Constants.Zone.HAND, playerA, "Lightning Bolt"); + + setStopAt(1, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + boolean found = false; + for (Card card : currentGame.getPlayer(playerA.getId()).getHand().getCards(currentGame)) { + if (card.getName().equals("Lightning Bolt")) { + for (String rule : card.getRules()) { + if (rule.startsWith("Rebound")) { + found = true; + } + } + } + } + + Assert.assertTrue("Couldn't find Rebound rule text displayed for the card", found); + } + + /** + * Tests Rebound disappeared + */ + @Test + public void testCastWithoutRebound() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 2); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 2); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Cast Through Time"); + addCard(Constants.Zone.HAND, playerA, "Lightning Bolt"); + addCard(Constants.Zone.HAND, playerA, "Naturalize"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Naturalize", "Cast Through Time"); + castSpell(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(3, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerB, 17); + } + + /** + * Tests other than Battlefield zone + */ + @Test + public void testInAnotherZone() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Constants.Zone.GRAVEYARD, playerA, "Cast Through Time"); + addCard(Constants.Zone.HAND, playerA, "Lightning Bolt"); + + castSpell(1, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + setStopAt(3, Constants.PhaseStep.BEGIN_COMBAT); + execute(); + + assertLife(playerB, 17); + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/WorldAtWarTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/WorldAtWarTest.java new file mode 100644 index 00000000000..bab97e1d34a --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/roe/WorldAtWarTest.java @@ -0,0 +1,102 @@ +package org.mage.test.cards.single.roe; + +import mage.Constants; +import mage.game.permanent.Permanent; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author magenoxx_at_gmail.com + */ +public class WorldAtWarTest extends CardTestPlayerBase { + + /** + * Tests creatures attack twice + */ + @Test + public void testCard() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 5); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Fervor"); + addCard(Constants.Zone.HAND, playerA, "World at War"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Warclamp Mastiff"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "World at War"); + + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Warclamp Mastiff"); + attack(1, playerA, "Warclamp Mastiff"); + + setStopAt(1, Constants.PhaseStep.END_TURN); + execute(); + + System.out.println("player: " + playerA.getId()); + + assertLife(playerB, 14); + Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA); + Assert.assertTrue(eliteVanguard.isTapped()); + } + + /** + * Tests creatures attack twice on each turn (Rebound) + */ + @Test + public void testCardWithRebound() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 5); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Fervor"); + addCard(Constants.Zone.HAND, playerA, "World at War"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Warclamp Mastiff"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "World at War"); + + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Warclamp Mastiff"); + attack(1, playerA, "Warclamp Mastiff"); + + attack(3, playerA, "Elite Vanguard"); + attack(3, playerA, "Elite Vanguard"); + attack(3, playerA, "Warclamp Mastiff"); + attack(3, playerA, "Warclamp Mastiff"); + + setStopAt(3, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerB, 8); + Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA); + Assert.assertTrue(eliteVanguard.isTapped()); + } + + /** + * Tests creatures attack thrice + */ + @Test + public void testDoubleCast() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 10); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Fervor"); + addCard(Constants.Zone.HAND, playerA, "World at War", 2); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Elite Vanguard"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Warclamp Mastiff"); + + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "World at War"); + castSpell(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "World at War"); + + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Elite Vanguard"); + attack(1, playerA, "Warclamp Mastiff"); + attack(1, playerA, "Warclamp Mastiff"); + attack(1, playerA, "Warclamp Mastiff"); + + setStopAt(1, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerB, 11); + Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA); + Assert.assertTrue(eliteVanguard.isTapped()); + } +} diff --git a/Mage/src/mage/abilities/effects/common/CastCardFromOursideTheGameEffect.java b/Mage/src/mage/abilities/effects/common/CastCardFromOursideTheGameEffect.java new file mode 100644 index 00000000000..69fecf27596 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/CastCardFromOursideTheGameEffect.java @@ -0,0 +1,99 @@ +/* + * 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.abilities.effects.common; + +import mage.Constants; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.Cards; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; + +import java.util.Set; + +/** + * @author magenoxx_at_gmail.com + */ +public class CastCardFromOursideTheGameEffect extends OneShotEffect { + + private static final String choiceText = "Cast a card from outside the game?"; + + private FilterCard filterCard; + + public CastCardFromOursideTheGameEffect(FilterCard filter, String ruleText) { + super(Constants.Outcome.Benefit); + this.staticText = ruleText; + this.filterCard = filter; + } + + public CastCardFromOursideTheGameEffect(final CastCardFromOursideTheGameEffect effect) { + super(effect); + filterCard = effect.filterCard; + } + + @Override + public CastCardFromOursideTheGameEffect copy() { + return new CastCardFromOursideTheGameEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + + while (player.chooseUse(Constants.Outcome.Benefit, choiceText, game)) { + Cards cards = player.getSideboard(); + if (cards.isEmpty()) { + game.informPlayer(player, "You have no cards outside the game."); + return false; + } + + Set filteredCards = cards.getCards(filterCard, game); + if (filteredCards.isEmpty()) { + game.informPlayer(player, "You have no " + filterCard.getMessage() + " outside the game."); + return false; + } + + TargetCard target = new TargetCard(Constants.Zone.PICK, filterCard); + if (player.choose(Constants.Outcome.Benefit, cards, target, game)) { + Card card = player.getSideboard().get(target.getFirstTarget(), game); + if (card != null) { + player.cast(card.getSpellAbility(), game, true); + } + } + } + + return true; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java b/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java new file mode 100644 index 00000000000..04f4ba7d16b --- /dev/null +++ b/Mage/src/mage/watchers/common/AttackedThisTurnWatcher.java @@ -0,0 +1,77 @@ +/* + * 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; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.watchers.WatcherImpl; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author magenoxx_at_gmail.com + */ +public class AttackedThisTurnWatcher extends WatcherImpl { + + public Set attackedThisTurnCreatures = new HashSet(); + + public AttackedThisTurnWatcher() { + super("AttackedThisTurn", Constants.WatcherScope.GAME); + } + + public AttackedThisTurnWatcher(final AttackedThisTurnWatcher watcher) { + super(watcher); + this.attackedThisTurnCreatures = watcher.attackedThisTurnCreatures; + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { + this.attackedThisTurnCreatures.add(event.getSourceId()); + } + } + + public Set getAttackedThisTurnCreatures() { + return this.attackedThisTurnCreatures; + } + + @Override + public AttackedThisTurnWatcher copy() { + return new AttackedThisTurnWatcher(this); + } + + @Override + public void reset() { + super.reset(); + this.attackedThisTurnCreatures.clear(); + } + +} \ No newline at end of file