diff --git a/Mage.Sets/src/mage/sets/commander/SkullbriarTheWalkingGrave.java b/Mage.Sets/src/mage/sets/commander/SkullbriarTheWalkingGrave.java new file mode 100644 index 00000000000..a55039f349d --- /dev/null +++ b/Mage.Sets/src/mage/sets/commander/SkullbriarTheWalkingGrave.java @@ -0,0 +1,149 @@ +/* + * 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.commander; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.StaticAbility; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.abilities.keyword.HasteAbility; +import mage.cards.CardImpl; +import mage.constants.*; +import mage.counters.Counter; +import mage.counters.CounterType; +import mage.counters.Counters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author anonymous + */ +public class SkullbriarTheWalkingGrave extends CardImpl { + private Counters counters; + + public SkullbriarTheWalkingGrave(UUID ownerId) { + super(ownerId, 227, "Skullbriar, the Walking Grave", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{B}{G}"); + this.expansionSetCode = "CMD"; + this.supertype.add("Legendary"); + this.subtype.add("Zombie"); + this.subtype.add("Elemental"); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // Haste + this.addAbility(HasteAbility.getInstance()); + // Whenever Skullbriar, the Walking Grave deals combat damage to a player, put a +1/+1 counter on it. + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility( + new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false)); + // Counters remain on Skullbriar as it moves to any zone other than a player's hand or library. + this.addAbility(new SimpleStaticAbility(Zone.ALL, new SkullbriarEffect())); + } + + public SkullbriarTheWalkingGrave(SkullbriarTheWalkingGrave card) { super(card); } + + @Override + public SkullbriarTheWalkingGrave copy() { + return new SkullbriarTheWalkingGrave(this); + } + + + @Override + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { + boolean skullBriarEffectApplied = false; + if (event.getToZone() != Zone.HAND && event.getToZone() != Zone.LIBRARY) { + for (StaticAbility ability : getAbilities (game).getStaticAbilities(event.getFromZone())) { + for (Effect effect : ability.getEffects(game, EffectType.REPLACEMENT)) { + if (effect instanceof SkullbriarEffect && event.getAppliedEffects().contains(effect.getId())) { + skullBriarEffectApplied = true; + } + } + } + } + Counters copyFrom = null; + if (skullBriarEffectApplied) { + if (event.getTarget() != null && event.getFromZone() == Zone.BATTLEFIELD) { + copyFrom = new Counters(event.getTarget().getCounters(game)); + } else { + copyFrom = new Counters(this.getCounters(game)); + } + } + super.updateZoneChangeCounter(game, event); + Counters copyTo = null; + if (event.getTarget() != null && event.getToZone() == Zone.BATTLEFIELD) { + if (event.getFromZone() != Zone.BATTLEFIELD) { + copyTo = event.getTarget().getCounters(game); + } + } else { + copyTo = this.getCounters(game); + } + if (copyTo != null && copyFrom != null) { + for(Counter counter : copyFrom.values()) { + copyTo.addCounter(counter); + } + } + } +} + +class SkullbriarEffect extends ReplacementEffectImpl { + public SkullbriarEffect() { + super(Duration.EndOfGame, Outcome.Benefit); + staticText = "Counters remain on {this} as it moves to any zone other than a player's hand or library."; + } + + public SkullbriarEffect(SkullbriarEffect effect) { + super(effect); + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + return false; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return source.getSourceId().equals(event.getTargetId()); + } + + @Override + public ContinuousEffect copy() { + return new SkullbriarEffect(this); + } +} \ No newline at end of file diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/SkullbriarTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/SkullbriarTest.java new file mode 100644 index 00000000000..78099db8a82 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/SkullbriarTest.java @@ -0,0 +1,93 @@ +/* + * 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.replacement; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author Dilnu + */ +public class SkullbriarTest extends CardTestPlayerBase { + + /** + * Skullbriar retains counters even when Humility is on the field. + */ + @Test + public void testSkullbriarCloudshift() { + // Counters remain on Skullbriar as it moves to any zone other than a player's hand or library. + addCard(Zone.BATTLEFIELD, playerB, "Skullbriar, the Walking Grave"); + addCard(Zone.BATTLEFIELD, playerB, "Plains"); + addCard(Zone.BATTLEFIELD, playerB, "Forest"); + + // Put a +1/+1 counter on target creature. + addCard(Zone.HAND, playerB, "Battlegrowth"); + // Exile target creature you control, then return that card to the battlefield under your control. + addCard(Zone.HAND, playerB, "Cloudshift"); + + castSpell(1, PhaseStep.UPKEEP, playerB, "Battlegrowth", "Skullbriar, the Walking Grave"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cloudshift", "Skullbriar, the Walking Grave"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertCounterCount("Skullbriar, the Walking Grave", CounterType.P1P1, 1); + } + + /** + * Skullbriar should not retain counters when Humility is on the field. + */ + @Test + public void testHumilityAndSkullbriarCloudshift() { + // Counters remain on Skullbriar as it moves to any zone other than a player's hand or library. + addCard(Zone.BATTLEFIELD, playerB, "Skullbriar, the Walking Grave"); + + // Enchantment {2}{W}{W} + // All creatures lose all abilities and are 1/1. + addCard(Zone.BATTLEFIELD, playerA, "Humility"); + addCard(Zone.BATTLEFIELD, playerB, "Plains"); + addCard(Zone.BATTLEFIELD, playerB, "Forest"); + + // Put a +1/+1 counter on target creature. + addCard(Zone.HAND, playerB, "Battlegrowth"); + // Exile target creature you control, then return that card to the battlefield under your control. + addCard(Zone.HAND, playerB, "Cloudshift"); + + castSpell(1, PhaseStep.UPKEEP, playerB, "Battlegrowth", "Skullbriar, the Walking Grave"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cloudshift", "Skullbriar, the Walking Grave"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertCounterCount("Skullbriar, the Walking Grave", CounterType.P1P1, 0); + } +} diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index a0d9c5bc0ce..33d5047f0d7 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -10,6 +10,7 @@ import mage.abilities.costs.mana.ManaCosts; import mage.cards.FrameStyle; import mage.constants.CardType; import mage.game.Game; +import mage.game.events.ZoneChangeEvent; public interface MageObject extends MageItem, Serializable { @@ -75,7 +76,7 @@ public interface MageObject extends MageItem, Serializable { int getZoneChangeCounter(Game game); - void updateZoneChangeCounter(Game game); + void updateZoneChangeCounter(Game game, ZoneChangeEvent event); void setZoneChangeCounter(int value, Game game); diff --git a/Mage/src/main/java/mage/MageObjectImpl.java b/Mage/src/main/java/mage/MageObjectImpl.java index daea728b079..8ab42221b1e 100644 --- a/Mage/src/main/java/mage/MageObjectImpl.java +++ b/Mage/src/main/java/mage/MageObjectImpl.java @@ -42,6 +42,7 @@ import mage.abilities.mana.ManaAbility; import mage.cards.FrameStyle; import mage.constants.CardType; import mage.game.Game; +import mage.game.events.ZoneChangeEvent; import mage.util.CardUtil; import mage.util.GameLog; @@ -287,7 +288,7 @@ public abstract class MageObjectImpl implements MageObject { } @Override - public void updateZoneChangeCounter(Game game) { + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { game.getState().updateZoneChangeCounter(objectId); } diff --git a/Mage/src/main/java/mage/abilities/effects/AuraReplacementEffect.java b/Mage/src/main/java/mage/abilities/effects/AuraReplacementEffect.java index be9335c3c63..d0382e571c1 100644 --- a/Mage/src/main/java/mage/abilities/effects/AuraReplacementEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/AuraReplacementEffect.java @@ -174,8 +174,9 @@ public class AuraReplacementEffect extends ReplacementEffectImpl { if (targetCard != null || targetPermanent != null || targetPlayer != null) { card = game.getCard(event.getTargetId()); card.removeFromZone(game, fromZone, sourceId); - card.updateZoneChangeCounter(game); PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game); + ZoneChangeEvent zoneChangeEvent = new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD); + permanent.updateZoneChangeCounter(game, zoneChangeEvent); game.getBattlefield().addPermanent(permanent); card.setZone(Zone.BATTLEFIELD, game); if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) { @@ -188,7 +189,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl { } game.applyEffects(); - game.fireEvent(new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD)); + game.fireEvent(zoneChangeEvent); return true; } diff --git a/Mage/src/main/java/mage/cards/MeldCard.java b/Mage/src/main/java/mage/cards/MeldCard.java index 9644ddc680f..df7628f176d 100644 --- a/Mage/src/main/java/mage/cards/MeldCard.java +++ b/Mage/src/main/java/mage/cards/MeldCard.java @@ -36,8 +36,6 @@ import mage.counters.Counter; import mage.game.Game; import mage.game.events.ZoneChangeEvent; import mage.game.permanent.Permanent; -import mage.game.permanent.PermanentMeld; -import mage.players.Player; /** * @@ -192,20 +190,20 @@ public abstract class MeldCard extends CardImpl { } @Override - public void updateZoneChangeCounter(Game game) { + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { if (isCopy() || !isMelded()) { - super.updateZoneChangeCounter(game); + super.updateZoneChangeCounter(game, event); return; } game.getState().updateZoneChangeCounter(objectId); if (topLastZoneChangeCounter == topHalfCard.getZoneChangeCounter(game) && halves.contains(topHalfCard.getId())) { - topHalfCard.updateZoneChangeCounter(game); + topHalfCard.updateZoneChangeCounter(game, event); topLastZoneChangeCounter = topHalfCard.getZoneChangeCounter(game); } if (bottomLastZoneChangeCounter == bottomHalfCard.getZoneChangeCounter(game) && halves.contains(bottomHalfCard.getId())) { - bottomHalfCard.updateZoneChangeCounter(game); + bottomHalfCard.updateZoneChangeCounter(game, event); bottomLastZoneChangeCounter = bottomHalfCard.getZoneChangeCounter(game); } } diff --git a/Mage/src/main/java/mage/game/ZonesHandler.java b/Mage/src/main/java/mage/game/ZonesHandler.java index 71e35447382..4b1efae4c50 100644 --- a/Mage/src/main/java/mage/game/ZonesHandler.java +++ b/Mage/src/main/java/mage/game/ZonesHandler.java @@ -73,6 +73,7 @@ public class ZonesHandler { toZone = subInfo.event.getToZone(); placeInDestinationZone(subInfo, game); } + // We arbitrarily prefer the bottom half card. This should never be relevant. if (toZone != null) { game.setZone(unmelded.event.getTargetId(), toZone); } @@ -180,7 +181,8 @@ public class ZonesHandler { if (unmelded.subInfo.isEmpty()) { return false; } - meld.updateZoneChangeCounter(game); + // We arbitrarily prefer the bottom half card. This should never be relevant. + meld.updateZoneChangeCounter(game, unmelded.subInfo.get(unmelded.subInfo.size() - 1).event); return true; } // Handle all normal cases @@ -235,9 +237,9 @@ public class ZonesHandler { } if (success) { if (event.getToZone() == Zone.BATTLEFIELD && event.getTarget() != null) { - event.getTarget().updateZoneChangeCounter(game); + event.getTarget().updateZoneChangeCounter(game, event); } else { - card.updateZoneChangeCounter(game); + card.updateZoneChangeCounter(game, event); } } return success; diff --git a/Mage/src/main/java/mage/game/command/Commander.java b/Mage/src/main/java/mage/game/command/Commander.java index 3831292c623..b89cbc22b5d 100644 --- a/Mage/src/main/java/mage/game/command/Commander.java +++ b/Mage/src/main/java/mage/game/command/Commander.java @@ -42,6 +42,7 @@ import mage.cards.Card; import mage.cards.FrameStyle; import mage.constants.CardType; import mage.game.Game; +import mage.game.events.ZoneChangeEvent; import mage.util.GameLog; public class Commander implements CommandObject { @@ -214,8 +215,8 @@ public class Commander implements CommandObject { } @Override - public void updateZoneChangeCounter(Game game) { - card.updateZoneChangeCounter(game); + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { + card.updateZoneChangeCounter(game, event); } @Override diff --git a/Mage/src/main/java/mage/game/command/Emblem.java b/Mage/src/main/java/mage/game/command/Emblem.java index eb9acc3b3a0..cfe9fa14c23 100644 --- a/Mage/src/main/java/mage/game/command/Emblem.java +++ b/Mage/src/main/java/mage/game/command/Emblem.java @@ -41,6 +41,7 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.cards.FrameStyle; import mage.constants.CardType; import mage.game.Game; +import mage.game.events.ZoneChangeEvent; import mage.util.GameLog; /** @@ -233,7 +234,7 @@ public class Emblem implements CommandObject { } @Override - public void updateZoneChangeCounter(Game game) { + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { throw new UnsupportedOperationException("Unsupported operation"); } diff --git a/Mage/src/main/java/mage/game/permanent/PermanentCard.java b/Mage/src/main/java/mage/game/permanent/PermanentCard.java index 30cb926552d..bf3b2ec798f 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentCard.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentCard.java @@ -240,8 +240,8 @@ public class PermanentCard extends PermanentImpl { } @Override - public void updateZoneChangeCounter(Game game) { - card.updateZoneChangeCounter(game); + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { + card.updateZoneChangeCounter(game, event); zoneChangeCounter = card.getZoneChangeCounter(game); } diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index 7d3d7db703b..47cac645506 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -778,7 +778,7 @@ public class Spell extends StackObjImpl implements Card { } @Override - public void updateZoneChangeCounter(Game game) { + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { throw new UnsupportedOperationException("Unsupported operation"); } diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index 17e4bb29106..34f857fa6a5 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -58,6 +58,7 @@ import mage.constants.Zone; import mage.constants.ZoneDetail; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; import mage.players.Player; import mage.target.Target; import mage.target.Targets; @@ -557,7 +558,7 @@ public class StackAbility extends StackObjImpl implements Ability { } @Override - public void updateZoneChangeCounter(Game game) { + public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) { throw new UnsupportedOperationException("Not supported."); }