From 823291c35858419594ebd52b1c4540a6e83601ab Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 27 Aug 2014 17:10:01 +0200 Subject: [PATCH] * Jace, Architect of Thought - fixed first ability that wrongly stopped working as soon as Jace left battlefield. Added tests. --- .../JaceArchitectOfThought.java | 110 ++++----------- .../rtr/JaceArchitectOfThoughtTest.java | 126 ++++++++++++++++++ 2 files changed, 151 insertions(+), 85 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/rtr/JaceArchitectOfThoughtTest.java diff --git a/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java b/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java index 243b5015140..e18963b7f60 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java @@ -40,12 +40,13 @@ import mage.constants.Rarity; import mage.constants.SubLayer; import mage.constants.Zone; import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; import mage.abilities.LoyaltyAbility; -import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.continious.BoostTargetEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.Card; @@ -86,7 +87,7 @@ public class JaceArchitectOfThought extends CardImpl { this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false)); // +1: Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn. - this.addAbility(new LoyaltyAbility(new JaceArchitectOfThoughtGainAbilityEffect(new JaceArchitectOfThoughtTriggeredAbility()),1)); + this.addAbility(new LoyaltyAbility(new CreateDelayedTriggeredAbilityEffect(new JaceArchitectOfThoughtDelayedTriggeredAbility()),1)); // -2: Reveal the top three cards of your library. An opponent separates those cards into two piles. Put one pile into your hand and the other on the bottom of your library in any order. this.addAbility(new LoyaltyAbility(new JaceArchitectOfThoughtEffect2(), -2)); @@ -106,63 +107,18 @@ public class JaceArchitectOfThought extends CardImpl { } } -class JaceArchitectOfThoughtGainAbilityEffect extends ContinuousEffectImpl { +class JaceArchitectOfThoughtDelayedTriggeredAbility extends DelayedTriggeredAbility { - protected Ability ability; - - public JaceArchitectOfThoughtGainAbilityEffect(Ability ability) { - super(Duration.Custom, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); - this.ability = ability; - staticText = "Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn"; + private int startingTurn; + + public JaceArchitectOfThoughtDelayedTriggeredAbility() { + super(new BoostTargetEffect(-1,0, Duration.EndOfTurn), Duration.Custom, false); } - public JaceArchitectOfThoughtGainAbilityEffect(final JaceArchitectOfThoughtGainAbilityEffect effect) { - super(effect); - this.ability = effect.ability.copy(); - } - - @Override - public JaceArchitectOfThoughtGainAbilityEffect copy() { - return new JaceArchitectOfThoughtGainAbilityEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null) { - permanent.addAbility(ability, game); - return true; - } - return false; - } - - @Override - public boolean isInactive(Ability source, Game game) { - if (game.getPhase().getStep().getType() == PhaseStep.UNTAP && game.getStep().getStepPart() == Step.StepPart.PRE) - { - if (game.getActivePlayerId().equals(source.getControllerId())) { - return true; - } - } - return false; - } -} - -class JaceArchitectOfThoughtTriggeredAbility extends TriggeredAbilityImpl { - - public JaceArchitectOfThoughtTriggeredAbility() { - super(Zone.BATTLEFIELD, new JaceArchitectOfThoughtEffectUnboostEffect(-1,0, Duration.EndOfTurn)); - } - - public JaceArchitectOfThoughtTriggeredAbility(final JaceArchitectOfThoughtTriggeredAbility ability) { + public JaceArchitectOfThoughtDelayedTriggeredAbility(JaceArchitectOfThoughtDelayedTriggeredAbility ability) { super(ability); } - @Override - public JaceArchitectOfThoughtTriggeredAbility copy() { - return new JaceArchitectOfThoughtTriggeredAbility(this); - } - @Override public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) { @@ -176,44 +132,28 @@ class JaceArchitectOfThoughtTriggeredAbility extends TriggeredAbilityImpl { return false; } + @Override + public JaceArchitectOfThoughtDelayedTriggeredAbility copy() { + return new JaceArchitectOfThoughtDelayedTriggeredAbility(this); + } + + @Override + public void init(Game game) { + startingTurn = game.getTurnNum(); + } + + + @Override + public boolean isInactive(Game game) { + return game.getActivePlayerId().equals(getControllerId()) && game.getTurnNum() != startingTurn; + } + @Override public String getRule() { return "Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn."; } } -/* - * effect only applies if creature continues to attack (if it's left the combat, it's no longer attacking - */ -class JaceArchitectOfThoughtEffectUnboostEffect extends BoostTargetEffect { - - public JaceArchitectOfThoughtEffectUnboostEffect(int power, int toughness, Duration duration) { - super(power, toughness, duration); - } - - - public JaceArchitectOfThoughtEffectUnboostEffect (final JaceArchitectOfThoughtEffectUnboostEffect effect) { - super(effect); - } - - @Override - public JaceArchitectOfThoughtEffectUnboostEffect copy() { - return new JaceArchitectOfThoughtEffectUnboostEffect(this); - } - - - @Override - public boolean apply(Game game, Ability source) { - for (UUID permanentId : targetPointer.getTargets(game, source)) { - Permanent target = (Permanent) game.getPermanent(permanentId); - if (target != null && target.isAttacking()) { - return super.apply(game, source); - } - } - return false; - } -} - class JaceArchitectOfThoughtEffect2 extends OneShotEffect { public JaceArchitectOfThoughtEffect2() { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/rtr/JaceArchitectOfThoughtTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/rtr/JaceArchitectOfThoughtTest.java new file mode 100644 index 00000000000..313bf1db091 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/rtr/JaceArchitectOfThoughtTest.java @@ -0,0 +1,126 @@ +/* + * 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.single.rtr; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Jace, Architect of Thought {2}{U}{U} + * Planeswalker — Jace + * Loyalty 4 + * +1: Until your next turn, whenever a creature an opponent controls attacks, it gets + * -1/-0 until end of turn. + * -2: Reveal the top three cards of your library. An opponent separates those cards into + * two piles. Put one pile into your hand and the other on the bottom of your library + * in any order. + * -8: For each player, search that player's library for a nonland card and exile it, then + * that player shuffles his or her library. You may cast those cards without paying + * their mana costs. + * + * @author LevelX2 + */ + +public class JaceArchitectOfThoughtTest extends CardTestPlayerBase { + + @Test + public void testAbility1normal() { + addCard(Zone.BATTLEFIELD, playerA, "Jace, Architect of Thought"); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn."); + + attack(2, playerB, "Silvercoat Lion"); + + setStopAt(2, PhaseStep.END_COMBAT); + execute(); + + assertCounterCount("Jace, Architect of Thought", CounterType.LOYALTY, 5); + assertPowerToughness(playerB, "Silvercoat Lion", 1, 2); + + assertLife(playerA, 19); + assertLife(playerB, 20); + + } + @Test + public void testAbilit1lastOnlyUntilNextTurn() { + addCard(Zone.BATTLEFIELD, playerA, "Jace, Architect of Thought"); + + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn."); + + attack(2, playerB, "Silvercoat Lion"); + attack(4, playerB, "Silvercoat Lion"); + + setStopAt(4, PhaseStep.END_COMBAT); + execute(); + + assertCounterCount("Jace, Architect of Thought", CounterType.LOYALTY, 5); + assertPowerToughness(playerB, "Silvercoat Lion", 2, 2); + + assertLife(playerA, 17); + assertLife(playerB, 20); + + } + /* + Ability 1 has still to trigger next turn if used also if Jace left the battlefield. + */ + @Test + public void testAbility1AfterJacesWasExiled() { + addCard(Zone.BATTLEFIELD, playerA, "Jace, Architect of Thought"); + + // Sorcery {R}{B} + // Destroy target creature or planeswalker. + addCard(Zone.HAND, playerB, "Dreadbore"); + addCard(Zone.BATTLEFIELD, playerB, "Mountain"); + addCard(Zone.BATTLEFIELD, playerB, "Swamp"); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Until your next turn, whenever a creature an opponent controls attacks, it gets -1/-0 until end of turn."); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Dreadbore", "Jace, Architect of Thought"); + attack(2, playerB, "Silvercoat Lion"); + + setStopAt(2, PhaseStep.END_COMBAT); + execute(); + + assertLife(playerA, 19); + assertLife(playerB, 20); + + assertPermanentCount(playerB, "Jace, Architect of Thought", 0); + assertPowerToughness(playerB, "Silvercoat Lion", 1, 2); + + } + +}