From 74109afcbbcb913e577e9091cb6247f2f19ac35e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 2 Sep 2015 16:20:58 +0200 Subject: [PATCH] [BFZ] Added Awaken ability. --- .../cards/abilities/keywords/AwakenTest.java | 61 +++++++ ...yMoreToCastAsThoughtItHadFlashAbility.java | 3 +- .../effects/common/DestroyTargetEffect.java | 34 ++-- .../mage/abilities/keyword/AwakenAbility.java | 156 ++++++++++++++++++ .../abilities/keyword/RetraceAbility.java | 10 +- 5 files changed, 240 insertions(+), 24 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/AwakenTest.java create mode 100644 Mage/src/mage/abilities/keyword/AwakenAbility.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/AwakenTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/AwakenTest.java new file mode 100644 index 00000000000..e1692db1808 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/AwakenTest.java @@ -0,0 +1,61 @@ +/* + * 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 AwakenTest extends CardTestPlayerBase { + + @Test + public void testCastWithAwaken() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 6); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); + // Destroy target creature or planeswalker. + // Awaken 4-{5}{B}{B} + addCard(Zone.HAND, playerA, "Ruinous Path", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ruinous Path with awaken", "Silvercoat Lion"); + addTarget(playerA, "Plains"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPowerToughness(playerA, "Plains", 4, 4); + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + } + +} diff --git a/Mage/src/mage/abilities/common/PayMoreToCastAsThoughtItHadFlashAbility.java b/Mage/src/mage/abilities/common/PayMoreToCastAsThoughtItHadFlashAbility.java index 7045c08433b..d36f220ea0a 100644 --- a/Mage/src/mage/abilities/common/PayMoreToCastAsThoughtItHadFlashAbility.java +++ b/Mage/src/mage/abilities/common/PayMoreToCastAsThoughtItHadFlashAbility.java @@ -6,6 +6,7 @@ package mage.abilities.common; import mage.abilities.SpellAbility; +import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.cards.Card; import mage.constants.SpellAbilityType; @@ -21,7 +22,7 @@ public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility { private final ManaCosts costsToAdd; - public PayMoreToCastAsThoughtItHadFlashAbility(Card card, ManaCosts costsToAdd) { + public PayMoreToCastAsThoughtItHadFlashAbility(Card card, ManaCosts costsToAdd) { super(card.getSpellAbility().getManaCosts().copy(), card.getName() + " as though it had flash", Zone.HAND, SpellAbilityType.BASE_ALTERNATE); this.costsToAdd = costsToAdd; this.timing = TimingRule.INSTANT; diff --git a/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java b/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java index 9339079cb1f..c4521407e84 100644 --- a/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java @@ -35,7 +35,6 @@ import mage.constants.Outcome; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.Target; -import mage.target.targetpointer.FirstTargetPointer; import mage.target.targetpointer.SecondTargetPointer; import mage.util.CardUtil; @@ -74,23 +73,22 @@ public class DestroyTargetEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int affectedTargets = 0; - if (source.getTargets().size() > 1 && targetPointer instanceof FirstTargetPointer) { // for Rain of Thorns - for (Target target : source.getTargets()) { - for (UUID permanentId : target.getTargets()) { - Permanent permanent = game.getPermanent(permanentId); - if (permanent != null) { - permanent.destroy(source.getSourceId(), game, noRegen); - affectedTargets++; - } - } - } - } else if (targetPointer.getTargets(game, source).size() > 0) { - for (UUID permanentId : targetPointer.getTargets(game, source)) { - Permanent permanent = game.getPermanent(permanentId); - if (permanent != null) { - permanent.destroy(source.getSourceId(), game, noRegen); - affectedTargets++; - } +// if (source.getTargets().size() > 1 && targetPointer instanceof FirstTargetPointer) { // for Rain of Thorns +// for (Target target : source.getTargets()) { +// for (UUID permanentId : target.getTargets()) { +// Permanent permanent = game.getPermanent(permanentId); +// if (permanent != null) { +// permanent.destroy(source.getSourceId(), game, noRegen); +// affectedTargets++; +// } +// } +// } +// } else + for (UUID permanentId : targetPointer.getTargets(game, source)) { + Permanent permanent = game.getPermanent(permanentId); + if (permanent != null) { + permanent.destroy(source.getSourceId(), game, noRegen); + affectedTargets++; } } return affectedTargets > 0; diff --git a/Mage/src/mage/abilities/keyword/AwakenAbility.java b/Mage/src/mage/abilities/keyword/AwakenAbility.java new file mode 100644 index 00000000000..58becb86615 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/AwakenAbility.java @@ -0,0 +1,156 @@ +/* + * 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.keyword; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.cards.Card; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.SpellAbilityType; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.filter.common.FilterControlledLandPermanent; +import mage.game.Game; +import mage.game.permanent.token.Token; +import mage.target.Target; +import mage.target.common.TargetControlledPermanent; +import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; + +/** + * + * @author LevelX2 + */ +public class AwakenAbility extends SpellAbility { + + static private String filterMessage = "a land you control to awake"; + + private String rule; + private int awakenValue; + + public AwakenAbility(Card card, int awakenValue, String awakenCosts) { + super(new ManaCostsImpl<>(awakenCosts), card.getName() + " with awaken", Zone.HAND, SpellAbilityType.BASE_ALTERNATE); + this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); + this.getEffects().addAll(card.getSpellAbility().getEffects()); + this.getTargets().addAll(card.getSpellAbility().getTargets()); + this.getChoices().addAll(card.getSpellAbility().getChoices()); + this.getWatchers().addAll(card.getSpellAbility().getWatchers()); + this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; + this.timing = card.getSpellAbility().getTiming(); + this.addTarget(new TargetControlledPermanent(new FilterControlledLandPermanent(filterMessage))); + this.addEffect(new AwakenEffect()); + this.awakenValue = awakenValue; + rule = "Awaken " + awakenValue + "—" + awakenCosts + + " (If you cast this spell for " + awakenCosts + ", also put " + + CardUtil.numberToText(awakenValue, "a") + + " +1/+1 counters on target land you control and it becomes a 0/0 Elemental creature with haste. It's still a land.)"; + + } + + public AwakenAbility(final AwakenAbility ability) { + super(ability); + this.awakenValue = ability.awakenValue; + } + + @Override + public AwakenAbility copy() { + return new AwakenAbility(this); + } + + @Override + public String getRule(boolean all) { + return getRule(); + } + + @Override + public String getRule() { + return rule; + } + + class AwakenEffect extends OneShotEffect { + + private AwakenEffect() { + super(Outcome.BoostCreature); + this.staticText = "put " + CardUtil.numberToText(awakenValue, "a") + " +1/+1 counters on target land you control"; + } + + public AwakenEffect(final AwakenEffect effect) { + super(effect); + } + + @Override + public AwakenEffect copy() { + return new AwakenEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + UUID targetId = null; + for (Target target : source.getTargets()) { + if (target.getFilter().getMessage().equals(filterMessage)) { + targetId = target.getFirstTarget(); + } + } + if (targetId != null) { + FixedTarget fixedTarget = new FixedTarget(targetId); + ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom); + continuousEffect.setTargetPointer(fixedTarget); + game.addEffect(continuousEffect, source); + Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue)); + effect.setTargetPointer(fixedTarget); + return effect.apply(game, source); + } + return true; + } + } + +} + +class AwakenElementalToken extends Token { + + public AwakenElementalToken() { + super("", "0/0 Elemental creature with haste"); + this.cardType.add(CardType.CREATURE); + + this.subtype.add("Elemental"); + this.power = new MageInt(0); + this.toughness = new MageInt(0); + + this.addAbility(HasteAbility.getInstance()); + } +} diff --git a/Mage/src/mage/abilities/keyword/RetraceAbility.java b/Mage/src/mage/abilities/keyword/RetraceAbility.java index 4c26c31b6cd..e8346528405 100644 --- a/Mage/src/mage/abilities/keyword/RetraceAbility.java +++ b/Mage/src/mage/abilities/keyword/RetraceAbility.java @@ -39,19 +39,19 @@ import mage.target.common.TargetCardInHand; * * @author LevelX2 */ - public class RetraceAbility extends SpellAbility { public RetraceAbility(Card card) { super(card.getManaCost(), card.getName() + " with retrace", Zone.GRAVEYARD, SpellAbilityType.BASE_ALTERNATE); this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); this.addCost(new DiscardTargetCost(new TargetCardInHand(new FilterLandCard()))); - this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); - this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); - this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); + this.getEffects().addAll(card.getSpellAbility().getEffects()); + this.getTargets().addAll(card.getSpellAbility().getTargets()); + this.getChoices().addAll(card.getSpellAbility().getChoices()); + this.getWatchers().addAll(card.getSpellAbility().getWatchers()); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); - + } public RetraceAbility(final RetraceAbility ability) {