From 7bc8ff9955bb5fcc04d1d09b64247d195f09c7d5 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 13 May 2015 17:45:44 +0200 Subject: [PATCH] * Otherworldly Journey - Fixed that the returning creature did not get the +1/+1 counter. --- .../OtherworldlyJourney.java | 114 ++++++++++++++++-- .../cards/triggers/DelayedTriggerTest.java | 88 ++++++++++++++ .../counter/AddCountersTargetEffect.java | 9 +- 3 files changed, 194 insertions(+), 17 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/triggers/DelayedTriggerTest.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/OtherworldlyJourney.java b/Mage.Sets/src/mage/sets/championsofkamigawa/OtherworldlyJourney.java index d8a0daeb564..7eea5e90a57 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/OtherworldlyJourney.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/OtherworldlyJourney.java @@ -29,21 +29,28 @@ package mage.sets.championsofkamigawa; import java.util.UUID; +import mage.MageObjectReference; import mage.constants.CardType; import mage.constants.Rarity; import mage.abilities.Ability; +import mage.abilities.DelayedTriggeredAbility; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.ReturnFromExileEffect; +import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; import mage.counters.CounterType; import mage.game.ExileZone; import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCreaturePermanent; import mage.target.targetpointer.FixedTarget; @@ -56,7 +63,7 @@ public class OtherworldlyJourney extends CardImpl { super(ownerId, 37, "Otherworldly Journey", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{1}{W}"); this.expansionSetCode = "CHK"; this.subtype.add("Arcane"); - this.color.setWhite(true); + // Exile target creature. At the beginning of the next end step, return that card to the battlefield under its owner's control with a +1/+1 counter on it. this.getSpellAbility().addEffect(new OtherworldlyJourneyEffect()); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); @@ -94,16 +101,19 @@ class OtherworldlyJourneyEffect extends OneShotEffect { ExileZone exile = game.getExile().getExileZone(source.getSourceId()); // only if permanent is in exile (tokens would be stop to exist) if (exile != null && !exile.isEmpty()) { - //create delayed triggered ability - AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility( - new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD, "return that card to the battlefield under its owner's control with a +1/+1 counter on it")); - delayedAbility.setSourceId(source.getSourceId()); - delayedAbility.setControllerId(source.getControllerId()); - delayedAbility.setSourceObject(source.getSourceObject(game), game); - AddCountersTargetEffect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance()); - effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); - delayedAbility.addEffect(effect); - game.addDelayedTriggeredAbility(delayedAbility); + Card card = game.getCard(permanent.getId()); + if (card != null) { + //create delayed triggered ability + DelayedTriggeredAbility delayedAbility = + new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new OtherworldlyJourneyReturnFromExileEffect(new MageObjectReference(card, game))); + delayedAbility.setSourceId(source.getSourceId()); + delayedAbility.setControllerId(source.getControllerId()); + delayedAbility.setSourceObject(source.getSourceObject(game), game); + AddCountersTargetEffect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance()); + effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); + delayedAbility.addEffect(effect); + game.addDelayedTriggeredAbility(delayedAbility); + } } return true; } @@ -117,3 +127,83 @@ class OtherworldlyJourneyEffect extends OneShotEffect { } } + +class OtherworldlyJourneyReturnFromExileEffect extends OneShotEffect { + + MageObjectReference objectToReturn; + public OtherworldlyJourneyReturnFromExileEffect(MageObjectReference objectToReturn) { + super(Outcome.PutCardInPlay); + this.objectToReturn = objectToReturn; + staticText = "return that card to the battlefield under its owner's control with a +1/+1 counter on it"; + } + + public OtherworldlyJourneyReturnFromExileEffect(final OtherworldlyJourneyReturnFromExileEffect effect) { + super(effect); + this.objectToReturn = effect.objectToReturn; + } + + @Override + public OtherworldlyJourneyReturnFromExileEffect copy() { + return new OtherworldlyJourneyReturnFromExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Card card = game.getCard(objectToReturn.getSourceId()); + if (card != null && objectToReturn.refersTo(card, game)) { + game.addEffect(new OtherworldlyJourneyEntersBattlefieldEffect(objectToReturn), source); + controller.putOntoBattlefieldWithInfo(card, game, Zone.EXILED, source.getSourceId()); + } + return true; + } + return false; + } +} + + +class OtherworldlyJourneyEntersBattlefieldEffect extends ReplacementEffectImpl { + + MageObjectReference objectToReturn; + + public OtherworldlyJourneyEntersBattlefieldEffect(MageObjectReference objectToReturn) { + super(Duration.Custom, Outcome.BoostCreature); + this.objectToReturn = objectToReturn; + staticText = "that card returns to the battlefield with a +1/+1 counter on it"; + } + + public OtherworldlyJourneyEntersBattlefieldEffect(OtherworldlyJourneyEntersBattlefieldEffect effect) { + super(effect); + this.objectToReturn = effect.objectToReturn; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return EventType.ENTERS_THE_BATTLEFIELD.equals(event.getType()); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getType() == EventType.ENTERS_THE_BATTLEFIELD) { + return event.getTargetId().equals(objectToReturn.getSourceId()); + } + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null) { + permanent.addCounters(CounterType.P1P1.createInstance(), game); + discard(); // use only once + } + return false; + } + + @Override + public OtherworldlyJourneyEntersBattlefieldEffect copy() { + return new OtherworldlyJourneyEntersBattlefieldEffect(this); + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/DelayedTriggerTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/DelayedTriggerTest.java new file mode 100644 index 00000000000..49aebd4b326 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/DelayedTriggerTest.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.triggers; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class DelayedTriggerTest extends CardTestPlayerBase { + + /** + * Activated Sunforger's unequip ability and cast Otherworldly Journey for free, targeting Cathodion. + * When Cathodion returned to the battlefield, it did not get a +1/+1 counter. * + * + */ + @Test + public void testOtherworldlyJourney1() { + // Exile target creature. At the beginning of the next end step, return that card to the battlefield under its owner's control with a +1/+1 counter on it. + addCard(Zone.HAND, playerA, "Otherworldly Journey"); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Otherworldly Journey", "Silvercoat Lion"); + + setStopAt(2, PhaseStep.DRAW); + execute(); + + assertGraveyardCount(playerA, "Otherworldly Journey", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + assertPowerToughness(playerA, "Silvercoat Lion", 3, 3); + + } + + @Test + public void testOtherworldlyJourney2() { + // Exile target creature. At the beginning of the next end step, return that card to the battlefield under its owner's control with a +1/+1 counter on it. + addCard(Zone.HAND, playerA, "Otherworldly Journey"); + addCard(Zone.HAND, playerA, "Cloudshift"); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Otherworldly Journey", "Silvercoat Lion"); + + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Cloudshift", "Silvercoat Lion"); + + setStopAt(3, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Otherworldly Journey", 1); + assertGraveyardCount(playerA, "Cloudshift", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + assertPowerToughness(playerA, "Silvercoat Lion", 2, 2); // one one use of +1/+1 + + } +} diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java index 922f5a03dd2..25df790451c 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java @@ -107,11 +107,10 @@ public class AddCountersTargetEffect extends OneShotEffect { newCounter.add(amount.calculate(game, source, this)); player.addCounters(newCounter, game); affectedTargets ++; - if (!game.isSimulation()) - game.informPlayers(new StringBuilder(sourceObject.getLogName()).append(": ") - .append(controller.getLogName()).append(" puts ") - .append(counter.getCount()).append(" ").append(counter.getName().toLowerCase()) - .append(" counter on ").append(player.getLogName()).toString()); + if (!game.isSimulation()) { + game.informPlayers(sourceObject.getLogName() +": " + controller.getLogName() + " puts " + + counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName()); + } } } }