From 3ea281ffbf5fd16acaeab34e54c68437719f297c Mon Sep 17 00:00:00 2001 From: LoneFox Date: Sat, 25 Jul 2015 20:12:43 +0300 Subject: [PATCH] Add DamageTargetControllerEffect and use it for existing cards. Implement card: Illuminate --- .../src/mage/sets/apocalypse/Illuminate.java | 79 ++++++++++++++ .../sets/betrayersofkamigawa/FirstVolley.java | 50 ++------- .../mage/sets/magic2011/ChandrasOutrage.java | 61 +++-------- .../mage/sets/magicorigins/RavagingBlaze.java | 56 ++-------- .../common/DamageTargetControllerEffect.java | 103 ++++++++++++++++++ 5 files changed, 215 insertions(+), 134 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/apocalypse/Illuminate.java create mode 100644 Mage/src/mage/abilities/effects/common/DamageTargetControllerEffect.java diff --git a/Mage.Sets/src/mage/sets/apocalypse/Illuminate.java b/Mage.Sets/src/mage/sets/apocalypse/Illuminate.java new file mode 100644 index 00000000000..d5e8769fbb2 --- /dev/null +++ b/Mage.Sets/src/mage/sets/apocalypse/Illuminate.java @@ -0,0 +1,79 @@ +/* + * 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.abilities.condition.common.KickedCostCondition; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.common.DamageTargetControllerEffect; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.keyword.KickerAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author LoneFox + */ +public class Illuminate extends CardImpl { + + public Illuminate(UUID ownerId) { + super(ownerId, 63, "Illuminate", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{R}"); + this.expansionSetCode = "APC"; + + // Kicker {2}{R} and/or {3}{U} + KickerAbility kickerAbility = new KickerAbility("{2}{R}"); + kickerAbility.addKickerCost("{3}{U}"); + this.addAbility(kickerAbility); + // Illuminate deals X damage to target creature. If Illuminate was kicked with its {2}{R} kicker, it deals X damage to that creature's controller. If Illuminate was kicked with its {3}{U} kicker, you draw X cards. + this.getSpellAbility().addEffect(new DamageTargetEffect(new ManacostVariableValue())); + this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + this.getSpellAbility().addEffect(new ConditionalOneShotEffect( + new DamageTargetControllerEffect(new ManacostVariableValue()), + new KickedCostCondition("{2}{R}"), + "If {this} was kicked with its {2}{R} kicker, it deals X damage to that creature's controller.")); + this.getSpellAbility().addEffect(new ConditionalOneShotEffect( + new DrawCardSourceControllerEffect(new ManacostVariableValue()), + new KickedCostCondition("{3}{U}"), + "If {this} was kicked with its {3}{U} kicker, you draw X cards.")); + + } + + public Illuminate(final Illuminate card) { + super(card); + } + + @Override + public Illuminate copy() { + return new Illuminate(this); + } +} diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/FirstVolley.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/FirstVolley.java index 8f20e822b03..58ad9dd54f7 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/FirstVolley.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/FirstVolley.java @@ -28,15 +28,12 @@ package mage.sets.betrayersofkamigawa; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.DamageTargetControllerEffect; +import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; +import mage.constants.CardType; +import mage.constants.Rarity; import mage.target.common.TargetCreaturePermanent; /** @@ -50,9 +47,11 @@ public class FirstVolley extends CardImpl { this.expansionSetCode = "BOK"; this.subtype.add("Arcane"); - // First Volley deals 1 damage to target creature and 1 damage to that creature's controller. - this.getSpellAbility().addEffect(new FirstVolleyEffect()); + this.getSpellAbility().addEffect(new DamageTargetEffect(1)); + Effect effect = new DamageTargetControllerEffect(1); + effect.setText("and 1 damage to that creature's controller"); + this.getSpellAbility().addEffect(effect); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); } @@ -66,34 +65,3 @@ public class FirstVolley extends CardImpl { return new FirstVolley(this); } } - -class FirstVolleyEffect extends OneShotEffect { - - public FirstVolleyEffect() { - super(Outcome.Damage); - this.staticText = "{this} deals 1 damage to target creature and 1 damage to that creature's controller"; - } - - public FirstVolleyEffect(final FirstVolleyEffect effect) { - super(effect); - } - - @Override - public FirstVolleyEffect copy() { - return new FirstVolleyEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); - if (permanent != null) { - Player controller = game.getPlayer(permanent.getControllerId()); - if (controller != null) { - permanent.damage(1, source.getSourceId(), game, false, true); - controller.damage(1, source.getSourceId(), game, false, true); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java b/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java index a5ee07e9ce7..98d75760c25 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java +++ b/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.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,15 +29,12 @@ package mage.sets.magic2011; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.DamageTargetControllerEffect; +import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; +import mage.constants.CardType; +import mage.constants.Rarity; import mage.target.common.TargetCreaturePermanent; /** @@ -50,7 +47,11 @@ public class ChandrasOutrage extends CardImpl { super(ownerId, 128, "Chandra's Outrage", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{2}{R}{R}"); this.expansionSetCode = "M11"; - this.getSpellAbility().addEffect(new ChandrasOutrageEffect()); + // Chandra's Outrage deals 4 damage to target creature and 2 damage to that creature's controller. + this.getSpellAbility().addEffect(new DamageTargetEffect(4)); + Effect effect = new DamageTargetControllerEffect(2); + effect.setText("and 2 damage to that creature's controller"); + this.getSpellAbility().addEffect(effect); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); } @@ -64,35 +65,3 @@ public class ChandrasOutrage extends CardImpl { } } - -class ChandrasOutrageEffect extends OneShotEffect { - - public ChandrasOutrageEffect() { - super(Outcome.Damage); - staticText = "{this} deals 4 damage to target creature and 2 damage to that creature's controller"; - } - - public ChandrasOutrageEffect(final ChandrasOutrageEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getFirstTarget()); - if (permanent != null) { - Player player = game.getPlayer(permanent.getControllerId()); - if (player != null) { - permanent.damage(4, source.getSourceId(), game, false, true); - player.damage(2, source.getSourceId(), game, false, true); - return true; - } - } - return false; - } - - @Override - public ChandrasOutrageEffect copy() { - return new ChandrasOutrageEffect(this); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/magicorigins/RavagingBlaze.java b/Mage.Sets/src/mage/sets/magicorigins/RavagingBlaze.java index 15d9672c16f..a22d8aa8feb 100644 --- a/Mage.Sets/src/mage/sets/magicorigins/RavagingBlaze.java +++ b/Mage.Sets/src/mage/sets/magicorigins/RavagingBlaze.java @@ -28,16 +28,14 @@ package mage.sets.magicorigins; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.condition.common.SpellMasteryCondition; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.common.DamageTargetControllerEffect; +import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Rarity; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -50,10 +48,12 @@ public class RavagingBlaze extends CardImpl { super(ownerId, 159, "Ravaging Blaze", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{X}{R}{R}"); this.expansionSetCode = "ORI"; - // Ravaging Blaze deals X damage to target creature. - // Spell mastery — If there are two or more instant and/or sorcery cards in your graveyard, Ravaging Blaze also deals X damage to that creature's controller. - this.getSpellAbility().addEffect(new RavagingBlazeEffect()); + // Ravaging Blaze deals X damage to target creature. + this.getSpellAbility().addEffect(new DamageTargetEffect(new ManacostVariableValue())); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + // Spell mastery — If there are two or more instant and/or sorcery cards in your graveyard, Ravaging Blaze also deals X damage to that creature's controller. + this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new DamageTargetControllerEffect(new ManacostVariableValue()), + SpellMasteryCondition.getInstance(), "
Spell mastery — If there are two or more instant and/or sorcery cards in your graveyard, Ravaging Blaze also deals X damage to that creature's controller.")); } public RavagingBlaze(final RavagingBlaze card) { @@ -65,41 +65,3 @@ public class RavagingBlaze extends CardImpl { return new RavagingBlaze(this); } } - -class RavagingBlazeEffect extends OneShotEffect { - - public RavagingBlazeEffect() { - super(Outcome.Damage); - staticText = "{this} deals X damage to target creature.
" - + "Spell mastery — If there are two or more instant and/or sorcery cards in your graveyard, {this} also deals X damage to that creature's controller."; - } - - public RavagingBlazeEffect(final RavagingBlazeEffect effect) { - super(effect); - } - - @Override - public RavagingBlazeEffect copy() { - return new RavagingBlazeEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); - if (permanent != null) { - int xValue = source.getManaCostsToPay().getX(); - if (xValue > 0) { - permanent.damage(xValue, source.getSourceId(), game, false, true); - if (SpellMasteryCondition.getInstance().apply(game, source)) { - Player targetController = game.getPlayer(permanent.getControllerId()); - if (targetController != null) { - targetController.damage(xValue, source.getSourceId(), game, false, true); - } - } - } - return true; - } - return false; - } - -} diff --git a/Mage/src/mage/abilities/effects/common/DamageTargetControllerEffect.java b/Mage/src/mage/abilities/effects/common/DamageTargetControllerEffect.java new file mode 100644 index 00000000000..d8d7216746f --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DamageTargetControllerEffect.java @@ -0,0 +1,103 @@ +/* + * 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.Mode; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author LoneFox + */ +public class DamageTargetControllerEffect extends OneShotEffect { + + protected DynamicValue amount; + protected boolean preventable; + + public DamageTargetControllerEffect(int amount) { + this(new StaticValue(amount), true); + } + + public DamageTargetControllerEffect(int amount, boolean preventable) { + this(new StaticValue(amount), preventable); + } + + public DamageTargetControllerEffect(DynamicValue amount) { + this(amount, true); + } + + public DamageTargetControllerEffect(DynamicValue amount, boolean preventable) { + super(Outcome.Damage); + this.amount = amount; + this.preventable = preventable; + } + + public DamageTargetControllerEffect(final DamageTargetControllerEffect effect) { + super(effect); + amount = effect.amount.copy(); + preventable = effect.preventable; + } + + @Override + public DamageTargetControllerEffect copy() { + return new DamageTargetControllerEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); + if(permanent != null) { + Player targetController = game.getPlayer(permanent.getControllerId()); + if(targetController != null) { + targetController.damage(amount.calculate(game, source, this), source.getSourceId(), game, false, preventable); + } + return true; + } + return false; + } + + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + String text = "{this} deals " + amount.getMessage() + " damage to target " + + mode.getTargets().get(0).getTargetName() + "'s controller"; + if(!preventable) { + text += ". The damage can't be prevented"; + } + return text; + } +}