From 16116ea0dad8d097e7aae1e2166b2c0046b533c7 Mon Sep 17 00:00:00 2001 From: LoneFox Date: Sat, 25 Jul 2015 21:10:54 +0300 Subject: [PATCH] Add DiscardOntoBattlefieldEffect and use it for existing cards. Implement card: Dodecapod --- .../src/mage/sets/apocalypse/Dodecapod.java | 97 +++++++++++++++++++ .../mage/sets/magic2011/ObstinateBaloth.java | 82 +++------------- .../sets/returntoravnica/LoxodonSmiter.java | 67 +------------ .../mage/sets/shadowmoor/WiltLeafLiege.java | 74 +------------- .../src/mage/sets/timeshifted/Dodecapod.java | 54 +++++++++++ .../common/DiscardOntoBattlefieldEffect.java | 96 ++++++++++++++++++ 6 files changed, 265 insertions(+), 205 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/apocalypse/Dodecapod.java create mode 100644 Mage.Sets/src/mage/sets/timeshifted/Dodecapod.java create mode 100644 Mage/src/mage/abilities/effects/common/DiscardOntoBattlefieldEffect.java diff --git a/Mage.Sets/src/mage/sets/apocalypse/Dodecapod.java b/Mage.Sets/src/mage/sets/apocalypse/Dodecapod.java new file mode 100644 index 00000000000..28c78bf997a --- /dev/null +++ b/Mage.Sets/src/mage/sets/apocalypse/Dodecapod.java @@ -0,0 +1,97 @@ +/* + * 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.apocalypse; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.common.DiscardOntoBattlefieldEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author LoneFox + */ +public class Dodecapod extends CardImpl { + + public Dodecapod(UUID ownerId) { + super(ownerId, 134, "Dodecapod", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{4}"); + this.expansionSetCode = "APC"; + this.subtype.add("Golem"); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // If a spell or ability an opponent controls causes you to discard Dodecapod, put it onto the battlefield with two +1/+1 counters on it instead of putting it into your graveyard. + this.addAbility(new SimpleStaticAbility(Zone.HAND, new DodecapodEffect())); + + } + + public Dodecapod(final Dodecapod card) { + super(card); + } + + @Override + public Dodecapod copy() { + return new Dodecapod(this); + } +} + + +class DodecapodEffect extends DiscardOntoBattlefieldEffect { + + public DodecapodEffect() { + super(); + staticText = "If a spell or ability an opponent controls causes you to discard {this}, put it onto the battlefield with two +1/+1 counters on it instead of putting it into your graveyard"; + } + + public DodecapodEffect(final DodecapodEffect effect) { + super(effect); + } + + @Override + public DodecapodEffect copy() { + return new DodecapodEffect(this); + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + if(super.replaceEvent(event, source, game)) { + new AddCountersSourceEffect(CounterType.P1P1.createInstance(2)).apply(game, source); + return true; + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java index f4675b3bc48..b4ec4152be9 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java +++ b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.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,7 +20,7 @@ * 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. @@ -29,25 +29,15 @@ package mage.sets.magic2011; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.DiscardOntoBattlefieldEffect; import mage.abilities.effects.common.GainLifeEffect; -import mage.cards.Card; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.events.ZoneChangeEvent; -import mage.game.stack.StackObject; -import mage.players.Player; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.constants.Zone; /** * @@ -65,9 +55,9 @@ public class ObstinateBaloth extends CardImpl { // When Obstinate Baloth enters the battlefield, you gain 4 life. this.addAbility(new EntersBattlefieldTriggeredAbility(new GainLifeEffect(4), false)); - + // If a spell or ability an opponent controls causes you to discard Obstinate Baloth, put it onto the battlefield instead of putting it into your graveyard. - this.addAbility(new SimpleStaticAbility(Zone.HAND, new ObstinateBalothEffect())); + this.addAbility(new SimpleStaticAbility(Zone.HAND, new DiscardOntoBattlefieldEffect())); } public ObstinateBaloth(final ObstinateBaloth card) { @@ -81,53 +71,3 @@ public class ObstinateBaloth extends CardImpl { } -class ObstinateBalothEffect extends ReplacementEffectImpl { - - public ObstinateBalothEffect() { - super(Duration.EndOfGame, Outcome.PutCardInPlay); - staticText = "If a spell or ability an opponent controls causes you to discard {this}, put it onto the battlefield instead of putting it into your graveyard"; - } - - public ObstinateBalothEffect(final ObstinateBalothEffect effect) { - super(effect); - } - - @Override - public ObstinateBalothEffect copy() { - return new ObstinateBalothEffect(this); - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == EventType.ZONE_CHANGE; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getSourceId())) { - ZoneChangeEvent zcEvent = (ZoneChangeEvent) event; - if (zcEvent.getFromZone() == Zone.HAND && zcEvent.getToZone() == Zone.GRAVEYARD) { - StackObject spell = game.getStack().getStackObject(event.getSourceId()); - if (spell != null && game.getOpponents(source.getControllerId()).contains(spell.getControllerId())) { - return true; - } - } - } - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Card card = game.getCard(source.getSourceId()); - if (card != null) { - Player owner = game.getPlayer(card.getOwnerId()); - if (owner != null) { - if (owner.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId())) { - return true; - } - } - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java index 3ec4636e9c7..e127fad6560 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java @@ -32,19 +32,12 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.CantBeCounteredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; -import mage.cards.Card; +import mage.abilities.effects.common.DiscardOntoBattlefieldEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.ZoneChangeEvent; -import mage.game.stack.StackObject; -import mage.players.Player; /** * @@ -67,7 +60,7 @@ public class LoxodonSmiter extends CardImpl { this.addAbility(new CantBeCounteredAbility()); // If a spell or ability an opponent controls causes you to discard Loxodon Smiter, put it onto the battlefield instead of putting it into your graveyard. - this.addAbility(new SimpleStaticAbility(Zone.HAND, new LoxodonSmiterEffect())); + this.addAbility(new SimpleStaticAbility(Zone.HAND, new DiscardOntoBattlefieldEffect())); } public LoxodonSmiter(final LoxodonSmiter card) { @@ -79,59 +72,3 @@ public class LoxodonSmiter extends CardImpl { return new LoxodonSmiter(this); } } - -class LoxodonSmiterEffect extends ReplacementEffectImpl { - - public LoxodonSmiterEffect() { - super(Duration.EndOfGame, Outcome.PutCardInPlay); - staticText = "If a spell or ability an opponent controls causes you to discard {this}, put it onto the battlefield instead of putting it into your graveyard"; - } - - public LoxodonSmiterEffect(final LoxodonSmiterEffect effect) { - super(effect); - } - - @Override - public LoxodonSmiterEffect copy() { - return new LoxodonSmiterEffect(this); - } - - @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) { - if (event.getTargetId().equals(source.getSourceId())) { - ZoneChangeEvent zcEvent = (ZoneChangeEvent) event; - if (zcEvent.getFromZone() == Zone.HAND && zcEvent.getToZone() == Zone.GRAVEYARD) { - StackObject spell = game.getStack().getStackObject(event.getSourceId()); - if (spell != null && game.getOpponents(source.getControllerId()).contains(spell.getControllerId())) { - return true; - } - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - Card card = game.getCard(source.getSourceId()); - if (card != null) { - Player player = game.getPlayer(card.getOwnerId()); - if (player != null) { - if (card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId())) { - return true; - } - } - } - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return apply(game, source); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java b/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java index 373f7aaa411..a8c72991aab 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java @@ -30,27 +30,18 @@ package mage.sets.shadowmoor; import java.util.UUID; import mage.MageInt; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.dynamicvalue.common.StaticValue; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.common.DiscardOntoBattlefieldEffect; import mage.abilities.effects.common.continuous.BoostAllEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.permanent.ControllerPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.ZoneChangeEvent; -import mage.game.stack.StackObject; -import mage.players.Player; /** * @@ -66,7 +57,7 @@ public class WiltLeafLiege extends CardImpl { filterWhite.add(new ColorPredicate(ObjectColor.WHITE)); filterWhite.add(new ControllerPredicate(TargetController.YOU)); } - + public WiltLeafLiege(UUID ownerId) { super(ownerId, 245, "Wilt-Leaf Liege", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{G/W}{G/W}{G/W}"); this.expansionSetCode = "SHM"; @@ -77,11 +68,11 @@ public class WiltLeafLiege extends CardImpl { this.toughness = new MageInt(4); // Other green creatures you control get +1/+1. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(new StaticValue(1), new StaticValue(1), Duration.WhileOnBattlefield, filterGreen, true))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filterGreen, true))); // Other white creatures you control get +1/+1. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(new StaticValue(1), new StaticValue(1), Duration.WhileOnBattlefield, filterWhite, true))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filterWhite, true))); // If a spell or ability an opponent controls causes you to discard Wilt-Leaf Liege, put it onto the battlefield instead of putting it into your graveyard. - this.addAbility(new SimpleStaticAbility(Zone.HAND, new WiltLeafLiegeEffect())); + this.addAbility(new SimpleStaticAbility(Zone.HAND, new DiscardOntoBattlefieldEffect())); } public WiltLeafLiege(final WiltLeafLiege card) { @@ -93,58 +84,3 @@ public class WiltLeafLiege extends CardImpl { return new WiltLeafLiege(this); } } - -class WiltLeafLiegeEffect extends ReplacementEffectImpl { - - public WiltLeafLiegeEffect() { - super(Duration.EndOfGame, Outcome.PutCardInPlay); - staticText = "If a spell or ability an opponent controls causes you to discard {this}, put it onto the battlefield instead of putting it into your graveyard"; - } - - public WiltLeafLiegeEffect(final WiltLeafLiegeEffect effect) { - super(effect); - } - - @Override - public WiltLeafLiegeEffect copy() { - return new WiltLeafLiegeEffect(this); - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType().equals(GameEvent.EventType.ZONE_CHANGE); - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getSourceId())) { - ZoneChangeEvent zcEvent = (ZoneChangeEvent) event; - if (zcEvent.getFromZone() == Zone.HAND && zcEvent.getToZone() == Zone.GRAVEYARD) { - StackObject spell = game.getStack().getStackObject(event.getSourceId()); - if (spell != null && game.getOpponents(source.getControllerId()).contains(spell.getControllerId())) { - return true; - } - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - Card card = game.getCard(source.getSourceId()); - if (card != null) { - Player player = game.getPlayer(card.getOwnerId()); - if (player != null) { - card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId()); - return true; - } - } - return false; - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - return apply(game, source); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/timeshifted/Dodecapod.java b/Mage.Sets/src/mage/sets/timeshifted/Dodecapod.java new file mode 100644 index 00000000000..73f7ddd1063 --- /dev/null +++ b/Mage.Sets/src/mage/sets/timeshifted/Dodecapod.java @@ -0,0 +1,54 @@ +/* + * 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.timeshifted; + +import java.util.UUID; +import mage.constants.Rarity; + +/** + * + * @author LoneFox + */ +public class Dodecapod extends mage.sets.apocalypse.Dodecapod { + + public Dodecapod(UUID ownerId) { + super(ownerId); + this.cardNumber = 108; + this.expansionSetCode = "TSB"; + this.rarity = Rarity.SPECIAL; + } + + public Dodecapod(final Dodecapod card) { + super(card); + } + + @Override + public Dodecapod copy() { + return new Dodecapod(this); + } +} diff --git a/Mage/src/mage/abilities/effects/common/DiscardOntoBattlefieldEffect.java b/Mage/src/mage/abilities/effects/common/DiscardOntoBattlefieldEffect.java new file mode 100644 index 00000000000..137b33c5145 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DiscardOntoBattlefieldEffect.java @@ -0,0 +1,96 @@ +/* + * 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.effects.common; + +import mage.abilities.Ability; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.cards.Card; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent.EventType; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.stack.StackObject; +import mage.players.Player; + +/** + * + * @author LoneFox + */ +public class DiscardOntoBattlefieldEffect extends ReplacementEffectImpl { + + public DiscardOntoBattlefieldEffect() { + super(Duration.EndOfGame, Outcome.PutCardInPlay); + staticText = "If a spell or ability an opponent controls causes you to discard {this}, put it onto the battlefield instead of putting it into your graveyard"; + } + + public DiscardOntoBattlefieldEffect(final DiscardOntoBattlefieldEffect effect) { + super(effect); + } + + @Override + public DiscardOntoBattlefieldEffect copy() { + return new DiscardOntoBattlefieldEffect(this); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getTargetId().equals(source.getSourceId())) { + ZoneChangeEvent zcEvent = (ZoneChangeEvent) event; + if (zcEvent.getFromZone() == Zone.HAND && zcEvent.getToZone() == Zone.GRAVEYARD) { + StackObject spell = game.getStack().getStackObject(event.getSourceId()); + if (spell != null && game.getOpponents(source.getControllerId()).contains(spell.getControllerId())) { + return true; + } + } + } + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Card card = game.getCard(source.getSourceId()); + if (card != null) { + Player owner = game.getPlayer(card.getOwnerId()); + if (owner != null) { + if (owner.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId())) { + return true; + } + } + } + return false; + } + +}