From 7cee34be546ab123d73f12b9585b1bfce76211d7 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 15 Oct 2015 08:32:58 +0200 Subject: [PATCH] * Some changed to card moving (not finished) --- .../avacynrestored/InfiniteReflection.java | 5 +- .../sets/timespiral/ScionOfTheUrDragon.java | 12 +-- .../cards/copy/InfiniteReflectionTest.java | 69 ++++++++++++++ .../org/mage/test/cards/copy/VesuvaTest.java | 22 ++--- .../java/org/mage/test/player/TestPlayer.java | 5 + .../common/AsEntersBattlefieldAbility.java | 7 +- .../abilities/effects/ContinuousEffects.java | 4 +- .../effects/EntersBattlefieldEffect.java | 6 +- .../effects/common/ChooseColorEffect.java | 9 +- .../abilities/effects/common/CopyEffect.java | 91 ++++++++++--------- ...romGraveyardToBattlefieldTargetEffect.java | 2 +- .../counter/AddCountersSourceEffect.java | 27 +++--- Mage/src/mage/game/stack/Spell.java | 5 + Mage/src/mage/players/Player.java | 3 + Mage/src/mage/players/PlayerImpl.java | 39 ++++---- 15 files changed, 202 insertions(+), 104 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/copy/InfiniteReflectionTest.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java b/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java index 1744100e91..e2b81f4ec5 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/InfiniteReflection.java @@ -46,6 +46,7 @@ import mage.constants.Zone; import mage.filter.FilterPermanent; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; +import mage.game.events.EntersTheBattlefieldEvent; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.game.permanent.PermanentToken; @@ -141,7 +142,7 @@ class InfiniteReflectionEntersBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - Permanent permanent = game.getPermanent(event.getTargetId()); + Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget(); return permanent != null && permanent.getControllerId().equals(source.getControllerId()) && permanent.getCardType().contains(CardType.CREATURE) && !(permanent instanceof PermanentToken); @@ -149,7 +150,7 @@ class InfiniteReflectionEntersBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - MageObject toCopyToObject = game.getObject(event.getTargetId()); + MageObject toCopyToObject = ((EntersTheBattlefieldEvent) event).getTarget(); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null && toCopyToObject != null && sourcePermanent.getAttachedTo() != null) { Permanent toCopyFromPermanent = game.getPermanent(sourcePermanent.getAttachedTo()); diff --git a/Mage.Sets/src/mage/sets/timespiral/ScionOfTheUrDragon.java b/Mage.Sets/src/mage/sets/timespiral/ScionOfTheUrDragon.java index 3112e6b86b..1a3700f00b 100644 --- a/Mage.Sets/src/mage/sets/timespiral/ScionOfTheUrDragon.java +++ b/Mage.Sets/src/mage/sets/timespiral/ScionOfTheUrDragon.java @@ -53,7 +53,6 @@ import mage.target.common.TargetCardInLibrary; /** * @author duncant */ - public class ScionOfTheUrDragon extends CardImpl { public ScionOfTheUrDragon(UUID ownerId) { @@ -69,8 +68,8 @@ public class ScionOfTheUrDragon extends CardImpl { // {2}: Search your library for a Dragon permanent card and put it into your graveyard. If you do, Scion of the Ur-Dragon becomes a copy of that card until end of turn. Then shuffle your library. this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, - new ScionOfTheUrDragonEffect(), - new ManaCostsImpl("{2}"))); + new ScionOfTheUrDragonEffect(), + new ManaCostsImpl("{2}"))); } public ScionOfTheUrDragon(final ScionOfTheUrDragon card) { @@ -84,15 +83,16 @@ public class ScionOfTheUrDragon extends CardImpl { } class ScionOfTheUrDragonEffect extends SearchEffect { + private static final FilterCard filter = new FilterPermanentCard("Dragon permanent card"); - + static { filter.add(new SubtypePredicate("Dragon")); } - + public ScionOfTheUrDragonEffect() { super(new TargetCardInLibrary(filter), Outcome.Copy); - staticText = "Search your library for a Dragon permanent card and put it into your graveyard. If you do, Scion of the Ur-Dragon becomes a copy of that card until end of turn. Then shuffle your library."; + staticText = "Search your library for a Dragon permanent card and put it into your graveyard. If you do, {this} becomes a copy of that card until end of turn. Then shuffle your library."; } ScionOfTheUrDragonEffect(final ScionOfTheUrDragonEffect effect) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/InfiniteReflectionTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/InfiniteReflectionTest.java new file mode 100644 index 0000000000..c60f7e912b --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/InfiniteReflectionTest.java @@ -0,0 +1,69 @@ +/* + * 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.copy; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class InfiniteReflectionTest extends CardTestPlayerBase { + + /** + * + */ + @Test + public void testCopyAsEnters() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 1); + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 9); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1); +// addCard(Zone.BATTLEFIELD, playerA, "Birds of Paradise", 1); +// addCard(Zone.HAND, playerA, "Nantuko Husk", 1);// {2}{B} + addCard(Zone.GRAVEYARD, playerA, "Pillarfield Ox", 1); + // Put target creature card from a graveyard onto the battlefield under your control. You lose life equal to its converted mana cost. + addCard(Zone.HAND, playerA, "Reanimate", 1); // {B} + + // Enchant creature + // When Infinite Reflection enters the battlefield attached to a creature, each other nontoken creature you control becomes a copy of that creature. + // Nontoken creatures you control enter the battlefield as a copy of enchanted creature. + addCard(Zone.HAND, playerA, "Infinite Reflection", 1); // {5}{U} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Infinite Reflection", "Silvercoat Lion"); +// castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nantuko Husk"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Reanimate", "Pillarfield Ox"); + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Silvercoat Lion", 2); + } + +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/VesuvaTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/VesuvaTest.java index 601be2d21f..48fc3962b1 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/VesuvaTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/VesuvaTest.java @@ -60,12 +60,11 @@ public class VesuvaTest extends CardTestPlayerBase { addCard(Zone.HAND, playerB, "Glimmerpost", 1); - playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Glimmerpost"); playLand(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Glimmerpost"); playLand(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Vesuva"); setChoice(playerA, "Glimmerpost"); - + setStopAt(3, PhaseStep.BEGIN_COMBAT); execute(); @@ -75,31 +74,32 @@ public class VesuvaTest extends CardTestPlayerBase { assertLife(playerA, 24); // 20 + 1 + 3 assertLife(playerB, 22); // 20 + 2 } - + @Test public void testDarkDepth() { // Dark Depths enters the battlefield with ten ice counters on it. // {3}: Remove an ice counter from Dark Depths. // When Dark Depths has no ice counters on it, sacrifice it. If you do, put a legendary 20/20 black Avatar creature token with flying and "This creature is indestructible" named Marit Lage onto the battlefield. addCard(Zone.BATTLEFIELD, playerB, "Dark Depths", 1); - + // You may have Vesuva enter the battlefield tapped as a copy of any land on the battlefield. - addCard(Zone.HAND, playerA, "Vesuva", 1); - + addCard(Zone.HAND, playerA, "Vesuva", 1); + playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Vesuva"); setChoice(playerA, "Dark Depths"); - + setStopAt(1, PhaseStep.BEGIN_COMBAT); execute(); - assertPermanentCount(playerA, "Dark Depths", 1); assertPermanentCount(playerB, "Dark Depths", 1); - + assertPermanentCount(playerA, "Vesuva", 0); + assertPermanentCount(playerA, "Dark Depths", 1); + Permanent darkDepth = getPermanent("Dark Depths", playerA); if (darkDepth != null) { - Assert.assertEquals(darkDepth.getCounters().getCount("ice"), 10); + Assert.assertEquals(10, darkDepth.getCounters().getCount("ice")); } - + assertTappedCount("Dark Depths", true, 1); } } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 55ebad8d17..5d0df67f11 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -1970,6 +1970,11 @@ public class TestPlayer implements Player { return computerPlayer.scry(value, source, game); } + @Override + public boolean moveCards(Card card, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects) { + return computerPlayer.moveCards(card, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); + } + @Override public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects) { return computerPlayer.moveCards(cards, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); diff --git a/Mage/src/mage/abilities/common/AsEntersBattlefieldAbility.java b/Mage/src/mage/abilities/common/AsEntersBattlefieldAbility.java index e41774bf77..d6f0e0fea6 100644 --- a/Mage/src/mage/abilities/common/AsEntersBattlefieldAbility.java +++ b/Mage/src/mage/abilities/common/AsEntersBattlefieldAbility.java @@ -39,11 +39,11 @@ import mage.constants.Zone; public class AsEntersBattlefieldAbility extends StaticAbility { public AsEntersBattlefieldAbility(Effect effect) { - super(Zone.BATTLEFIELD, new EntersBattlefieldEffect(effect)); + super(Zone.ALL, new EntersBattlefieldEffect(effect)); } public AsEntersBattlefieldAbility(Effect effect, String text) { - super(Zone.BATTLEFIELD, new EntersBattlefieldEffect(effect, text)); + super(Zone.ALL, new EntersBattlefieldEffect(effect, text)); } public AsEntersBattlefieldAbility(AsEntersBattlefieldAbility ability) { @@ -59,10 +59,9 @@ public class AsEntersBattlefieldAbility extends StaticAbility { return; } } - super.addEffect(effect); + super.addEffect(effect); } - @Override public AsEntersBattlefieldAbility copy() { return new AsEntersBattlefieldAbility(this); diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index de323f1202..c5b4661816 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -876,7 +876,9 @@ public class ContinuousEffects implements Serializable { } } // Must be called here for some effects to be able to work correctly - // TODO: add info which effects need that call + // For example: Vesuva copying a Dark Depth (VesuvaTest:testDarkDepth) + // This call should be removed if possible as replacement effects of EntersTheBattlefield events + // do no longer work correctly because the entering permanents are not yet on the battlefield (before they were). game.applyEffects(); } while (true); return caught; diff --git a/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java b/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java index 5a03cbcf33..ef6bb795d1 100644 --- a/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java +++ b/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java @@ -34,6 +34,7 @@ import mage.abilities.condition.Condition; import mage.constants.Duration; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.EntersTheBattlefieldEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.stack.Spell; @@ -51,6 +52,7 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl { protected Condition condition; protected boolean optional; + public static final String ENTERING_PERMANENT = "enteringPermanent"; public static final String SOURCE_CAST_SPELL_ABILITY = "sourceCastSpellAbility"; public EntersBattlefieldEffect(Effect baseEffect) { @@ -112,7 +114,7 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl { if (controller == null || object == null) { return false; } - if (!controller.chooseUse(outcome, new StringBuilder("Use effect of ").append(object.getLogName()).append("?").toString(), source, game)) { + if (!controller.chooseUse(outcome, "Use effect of " + object.getLogName() + "?", source, game)) { return false; } } @@ -131,6 +133,8 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl { if (spell != null) { effect.setValue(SOURCE_CAST_SPELL_ABILITY, spell.getSpellAbility()); } + // Because the permanent is not on the battlefield yet, it has to be taken from the event + effect.setValue(ENTERING_PERMANENT, ((EntersTheBattlefieldEvent) event).getTarget()); effect.apply(game, source); } } diff --git a/Mage/src/mage/abilities/effects/common/ChooseColorEffect.java b/Mage/src/mage/abilities/effects/common/ChooseColorEffect.java index 8f22a961ad..43836dd2f7 100644 --- a/Mage/src/mage/abilities/effects/common/ChooseColorEffect.java +++ b/Mage/src/mage/abilities/effects/common/ChooseColorEffect.java @@ -25,10 +25,10 @@ * 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.abilities.Ability; +import mage.abilities.effects.EntersBattlefieldEffect; import mage.abilities.effects.OneShotEffect; import mage.choices.ChoiceColor; import mage.constants.Outcome; @@ -56,6 +56,9 @@ public class ChooseColorEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT); + } if (controller != null && permanent != null) { ChoiceColor choice = new ChoiceColor(); while (!choice.isChosen()) { @@ -65,7 +68,7 @@ public class ChooseColorEffect extends OneShotEffect { } } if (!game.isSimulation()) { - game.informPlayers(permanent.getLogName()+": "+controller.getLogName()+" has chosen "+choice.getChoice()); + game.informPlayers(permanent.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice()); } game.getState().setValue(source.getSourceId() + "_color", choice.getColor()); permanent.addInfo("chosen color", CardUtil.addToolTipMarkTags("Chosen color: " + choice.getChoice()), game); @@ -79,4 +82,4 @@ public class ChooseColorEffect extends OneShotEffect { return new ChooseColorEffect(this); } -} \ No newline at end of file +} diff --git a/Mage/src/mage/abilities/effects/common/CopyEffect.java b/Mage/src/mage/abilities/effects/common/CopyEffect.java index 9d1194fda2..86bc3f060f 100644 --- a/Mage/src/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyEffect.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,15 +20,13 @@ * 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 java.util.UUID; import mage.MageObject; import mage.MageObjectReference; @@ -56,39 +54,42 @@ public class CopyEffect extends ContinuousEffectImpl { /** * Object we copy from */ - private MageObject target; - - private UUID sourceId; + private MageObject copyFromObject; + + private UUID copyToObjectId; private ApplyToPermanent applier; - - public CopyEffect(MageObject target, UUID sourceId) { - this(Duration.Custom, target, sourceId); + + public CopyEffect(MageObject copyFromObject, UUID copyToObjectId) { + this(Duration.Custom, copyFromObject, copyToObjectId); } - - public CopyEffect(Duration duration, MageObject target, UUID sourceId) { + + public CopyEffect(Duration duration, MageObject copyFromObject, UUID copyToObjectId) { super(duration, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); - this.target = target; - this.sourceId = sourceId; + this.copyFromObject = copyFromObject; + this.copyToObjectId = copyToObjectId; } public CopyEffect(final CopyEffect effect) { super(effect); - this.target = effect.target.copy(); - this.sourceId = effect.sourceId; + this.copyFromObject = effect.copyFromObject.copy(); + this.copyToObjectId = effect.copyToObjectId; this.applier = effect.applier; } @Override public void init(Ability source, Game game) { super.init(source, game); - if (!(target instanceof Permanent) && (target instanceof Card)) { - this.target = new PermanentCard((Card)target, source.getControllerId(), game); + if (!(copyFromObject instanceof Permanent) && (copyFromObject instanceof Card)) { + this.copyFromObject = new PermanentCard((Card) copyFromObject, source.getControllerId(), game); } - affectedObjectList.add(new MageObjectReference(getSourceId(), game)); + } @Override public boolean apply(Game game, Ability source) { + if (affectedObjectList.isEmpty()) { + affectedObjectList.add(new MageObjectReference(getSourceId(), game)); + } Permanent permanent = affectedObjectList.get(0).getPermanent(game); if (permanent == null) { permanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD, source.getSourceObjectZoneChangeCounter()); @@ -99,31 +100,31 @@ public class CopyEffect extends ContinuousEffectImpl { } } permanent.setCopy(true); - permanent.setName(target.getName()); - permanent.getColor(game).setColor(target.getColor(game)); + permanent.setName(copyFromObject.getName()); + permanent.getColor(game).setColor(copyFromObject.getColor(game)); permanent.getManaCost().clear(); - permanent.getManaCost().add(target.getManaCost()); + permanent.getManaCost().add(copyFromObject.getManaCost()); permanent.getCardType().clear(); - for (CardType type: target.getCardType()) { + for (CardType type : copyFromObject.getCardType()) { permanent.getCardType().add(type); } permanent.getSubtype().clear(); - for (String type: target.getSubtype()) { + for (String type : copyFromObject.getSubtype()) { permanent.getSubtype().add(type); } permanent.getSupertype().clear(); - for (String type: target.getSupertype()) { + for (String type : copyFromObject.getSupertype()) { permanent.getSupertype().add(type); } permanent.removeAllAbilities(source.getSourceId(), game); - for (Ability ability: target.getAbilities()) { - permanent.addAbility(ability, getSourceId(), game, false); // no new Id so consumed replacement effects are known while new continuousEffects.apply happen. + for (Ability ability : copyFromObject.getAbilities()) { + permanent.addAbility(ability, getSourceId(), game, false); // no new Id so consumed replacement effects are known while new continuousEffects.apply happen. } - permanent.getPower().setValue(target.getPower().getValue()); - permanent.getToughness().setValue(target.getToughness().getValue()); - if (target instanceof Permanent) { - Permanent targetPermanent = (Permanent) target; + permanent.getPower().setValue(copyFromObject.getPower().getValue()); + permanent.getToughness().setValue(copyFromObject.getToughness().getValue()); + if (copyFromObject instanceof Permanent) { + Permanent targetPermanent = (Permanent) copyFromObject; permanent.setTransformed(targetPermanent.isTransformed()); permanent.setSecondCardFace(targetPermanent.getSecondCardFace()); permanent.setFlipCard(targetPermanent.isFlipCard()); @@ -131,13 +132,13 @@ public class CopyEffect extends ContinuousEffectImpl { } // to get the image of the copied permanent copy number und expansionCode - if (target instanceof PermanentCard) { - permanent.setCardNumber(((PermanentCard) target).getCard().getCardNumber()); - permanent.setExpansionSetCode(((PermanentCard) target).getCard().getExpansionSetCode()); - } else if (target instanceof PermanentToken || target instanceof Card) { - permanent.setCardNumber(((Card) target).getCardNumber()); - permanent.setExpansionSetCode(((Card) target).getExpansionSetCode()); - } + if (copyFromObject instanceof PermanentCard) { + permanent.setCardNumber(((PermanentCard) copyFromObject).getCard().getCardNumber()); + permanent.setExpansionSetCode(((PermanentCard) copyFromObject).getCard().getExpansionSetCode()); + } else if (copyFromObject instanceof PermanentToken || copyFromObject instanceof Card) { + permanent.setCardNumber(((Card) copyFromObject).getCardNumber()); + permanent.setExpansionSetCode(((Card) copyFromObject).getExpansionSetCode()); + } return true; } @@ -147,15 +148,15 @@ public class CopyEffect extends ContinuousEffectImpl { } public MageObject getTarget() { - return target; + return copyFromObject; } public void setTarget(MageObject target) { - this.target = target; + this.copyFromObject = target; } public UUID getSourceId() { - return sourceId; + return copyToObjectId; } public ApplyToPermanent getApplier() { @@ -165,5 +166,5 @@ public class CopyEffect extends ContinuousEffectImpl { public void setApplier(ApplyToPermanent applier) { this.applier = applier; } - + } diff --git a/Mage/src/mage/abilities/effects/common/ReturnFromGraveyardToBattlefieldTargetEffect.java b/Mage/src/mage/abilities/effects/common/ReturnFromGraveyardToBattlefieldTargetEffect.java index da7960e743..dd2e279704 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnFromGraveyardToBattlefieldTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnFromGraveyardToBattlefieldTargetEffect.java @@ -73,7 +73,7 @@ public class ReturnFromGraveyardToBattlefieldTargetEffect extends OneShotEffect for (UUID targetId : getTargetPointer().getTargets(game, source)) { Card card = game.getCard(targetId); if (card != null) { - controller.putOntoBattlefieldWithInfo(card, game, Zone.GRAVEYARD, source.getSourceId(), tapped); + controller.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, false, null); } } return true; diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java index 82c14c0cdb..0633ff60c6 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,20 +20,20 @@ * 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.counter; -import mage.constants.Outcome; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.EntersBattlefieldEffect; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; +import mage.constants.Outcome; import mage.counters.Counter; import mage.game.Game; import mage.game.permanent.Permanent; @@ -63,11 +63,12 @@ public class AddCountersSourceEffect extends OneShotEffect { } /** - * + * * @param counter * @param amount this amount will be added to the counter instances * @param informPlayers - * @param putOnCard - counters have to be put on a card instead of a permanent + * @param putOnCard - counters have to be put on a card instead of a + * permanent */ public AddCountersSourceEffect(Counter counter, DynamicValue amount, boolean informPlayers, boolean putOnCard) { super(Outcome.Benefit); @@ -106,7 +107,7 @@ public class AddCountersSourceEffect extends OneShotEffect { if (informPlayers && !game.isSimulation()) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { - game.informPlayers(new StringBuilder(player.getLogName()).append(" puts ").append(newCounter.getCount()).append(" ").append(newCounter.getName().toLowerCase()).append(" counter on ").append(card.getLogName()).toString()); + game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + " " + newCounter.getName().toLowerCase() + " counter on " + card.getLogName()); } } } @@ -114,6 +115,9 @@ public class AddCountersSourceEffect extends OneShotEffect { } } else { Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + permanent = (Permanent) getValue(EntersBattlefieldEffect.ENTERING_PERMANENT); + } if (permanent != null) { if (counter != null) { Counter newCounter = counter.copy(); @@ -129,7 +133,7 @@ public class AddCountersSourceEffect extends OneShotEffect { int amountAdded = permanent.getCounters().getCount(newCounter.getName()) - before; Player player = game.getPlayer(source.getControllerId()); if (player != null) { - game.informPlayers(player.getLogName()+" puts "+amountAdded+" "+newCounter.getName().toLowerCase()+" counter on "+permanent.getLogName()); + game.informPlayers(player.getLogName() + " puts " + amountAdded + " " + newCounter.getName().toLowerCase() + " counter on " + permanent.getLogName()); } } } @@ -165,5 +169,4 @@ public class AddCountersSourceEffect extends OneShotEffect { return new AddCountersSourceEffect(this); } - } diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java index 2972b65d2d..482bfb8451 100644 --- a/Mage/src/mage/game/stack/Spell.java +++ b/Mage/src/mage/game/stack/Spell.java @@ -167,6 +167,10 @@ public class Spell extends StackObjImpl implements Card { @Override public boolean resolve(Game game) { boolean result; + Player controller = game.getPlayer(getControllerId()); + if (controller == null) { + return false; + } if (this.getCardType().contains(CardType.INSTANT) || this.getCardType().contains(CardType.SORCERY)) { int index = 0; result = false; @@ -261,6 +265,7 @@ public class Spell extends StackObjImpl implements Card { } } else { updateOptionalCosts(0); +// return controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null); result = card.putOntoBattlefield(game, Zone.STACK, ability.getSourceId(), controllerId, false, faceDown); return result; } diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index d00471867c..b484fb8ccf 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -635,6 +635,8 @@ public interface Player extends MageItem, Copyable { boolean moveCards(Set cards, Zone fromZone, Zone toZone, Ability source, Game game); + boolean moveCards(Card card, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects); + /** * * @param cards @@ -646,6 +648,7 @@ public interface Player extends MageItem, Copyable { * @param byOwner the card is moved (or put onto battlefield) by the owner * of the card and if target zone is battlefield controlls the permanent * (instead of the controller of the source) + * @param appliedEffects * @return */ boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index bb1250e1b5..011d716acd 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -1022,7 +1022,7 @@ public abstract class PlayerImpl implements Player, Serializable { game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LAND_PLAYED, card.getId(), card.getId(), playerId)); game.fireInformEvent(getLogName() + " plays " + card.getLogName()); // game.removeBookmark(bookmark); - resetStoredBookmark(game); + resetStoredBookmark(game); // prevent undo after playing a land return true; } // putOntoBattlefield retured false if putOntoBattlefield was replaced by replacement effect (e.g. Kjeldorian Outpost). @@ -2998,22 +2998,6 @@ public abstract class PlayerImpl implements Player, Serializable { successfulMovedCards = moveCardsToGraveyardWithInfo(cards, source, game, fromZone); break; case HAND: - for (Card card : cards) { - fromZone = game.getState().getZone(card.getId()); -// if (fromZone == Zone.STACK) { -// // If a spell is returned to its owner's hand, it's removed from the stack and thus will not resolve -// Spell spell = game.getStack().getSpell(card.getId()); -// if (spell != null) { -// game.getStack().remove(spell); -// } -// } - boolean hideCard = fromZone.equals(Zone.LIBRARY) - || (card.isFaceDown(game) && !fromZone.equals(Zone.STACK) && !fromZone.equals(Zone.BATTLEFIELD)); - if (moveCardToHandWithInfo(card, source == null ? null : source.getSourceId(), game, !hideCard)) { - successfulMovedCards.add(card); - } - } - break; case BATTLEFIELD: return moveCards(cards, toZone, source, game, false, false, false, null); case LIBRARY: @@ -3032,6 +3016,15 @@ public abstract class PlayerImpl implements Player, Serializable { return successfulMovedCards.size() > 0; } + @Override + public boolean moveCards(Card card, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects) { + Set cardList = new HashSet<>(); + if (card != null) { + cardList.add(card); + } + return moveCards(cardList, toZone, source, game, tapped, faceDown, byOwner, appliedEffects); + } + @Override public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, ArrayList appliedEffects) { if (cards.isEmpty()) { @@ -3070,7 +3063,6 @@ public abstract class PlayerImpl implements Player, Serializable { } } game.setScopeRelevant(false); - game.applyEffects(); for (Permanent permanent : permanentsEntered) { fromZone = game.getState().getZone(permanent.getId()); if (((Card) permanent).removeFromZone(game, fromZone, source.getSourceId())) { @@ -3086,6 +3078,17 @@ public abstract class PlayerImpl implements Player, Serializable { game.addSimultaneousEvent(new ZoneChangeEvent(permanent, permanent.getControllerId(), fromZone, Zone.BATTLEFIELD)); } } + game.applyEffects(); + break; + case HAND: + for (Card card : cards) { + fromZone = game.getState().getZone(card.getId()); + boolean hideCard = fromZone.equals(Zone.LIBRARY) + || (card.isFaceDown(game) && !fromZone.equals(Zone.STACK) && !fromZone.equals(Zone.BATTLEFIELD)); + if (moveCardToHandWithInfo(card, source == null ? null : source.getSourceId(), game, !hideCard)) { + successfulMovedCards.add(card); + } + } break; default: throw new UnsupportedOperationException("to Zone not supported yet");