diff --git a/Mage.Sets/src/mage/sets/saviorsofkamigawa/CowedByWisdom.java b/Mage.Sets/src/mage/sets/saviorsofkamigawa/CowedByWisdom.java index 0176bd77ecd..9ad1c7827ba 100644 --- a/Mage.Sets/src/mage/sets/saviorsofkamigawa/CowedByWisdom.java +++ b/Mage.Sets/src/mage/sets/saviorsofkamigawa/CowedByWisdom.java @@ -30,8 +30,9 @@ package mage.sets.saviorsofkamigawa; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.costs.Cost; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.PayCostToAttackBlockEffectImpl; import mage.abilities.effects.common.AttachEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; @@ -64,9 +65,9 @@ public class CowedByWisdom extends CardImpl { this.getSpellAbility().addEffect(new AttachEffect(Outcome.UnboostCreature)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); - + // Enchanted creature can't attack or block unless its controller pays {1} for each card in your hand. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CowedByWisdomEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CowedByWisdomayCostToAttackBlockEffect())); } public CowedByWisdom(final CowedByWisdom card) { @@ -79,65 +80,35 @@ public class CowedByWisdom extends CardImpl { } } -class CowedByWisdomEffect extends ReplacementEffectImpl { +class CowedByWisdomayCostToAttackBlockEffect extends PayCostToAttackBlockEffectImpl { - private static final String effectText = "Enchanted creature can't attack or block unless its controller pays {1} for each card in your hand"; - - CowedByWisdomEffect ( ) { - super(Duration.WhileOnBattlefield, Outcome.Neutral); - staticText = effectText; + CowedByWisdomayCostToAttackBlockEffect() { + super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK_AND_BLOCK, null); + staticText = "Enchanted creature can't attack or block unless its controller pays {1} for each card in your hand"; } - CowedByWisdomEffect ( CowedByWisdomEffect effect ) { + CowedByWisdomayCostToAttackBlockEffect(CowedByWisdomayCostToAttackBlockEffect effect) { super(effect); } @Override - public boolean apply(Game game, Ability source) { - throw new UnsupportedOperationException("Not supported."); - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DECLARE_ATTACKER || event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER); + public Cost getCostToPay(GameEvent event, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null && !controller.getHand().isEmpty()) { + return new GenericManaCost(controller.getHand().size()); + } + return null; } @Override public boolean applies(GameEvent event, Ability source, Game game) { - Permanent enchantment = game.getPermanent(event.getSourceId()); - return enchantment != null && enchantment.getAttachments().contains(source.getSourceId()); + Permanent enchantment = game.getPermanent(source.getSourceId()); + return enchantment != null && enchantment.getAttachedTo().equals(event.getSourceId()); } - + @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - Player controller = game.getPlayer(source.getControllerId()); - if (player != null && controller != null) { - if (controller.getHand().isEmpty()) { - return false; - } - String chooseText; - int cardsInHand = controller.getHand().size(); - if (event.getType().equals(GameEvent.EventType.DECLARE_ATTACKER)) { - chooseText = "Pay {" + cardsInHand + "} to attack?"; - } else { - chooseText = "Pay {" + cardsInHand + "} to block?"; - } - ManaCostsImpl attackBlockTax = new ManaCostsImpl("{" + cardsInHand + "}"); - if (attackBlockTax.canPay(source, source.getSourceId(), event.getPlayerId(), game) - && player.chooseUse(Outcome.Neutral, chooseText, source, game)) { - if (attackBlockTax.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) { - return false; - } - } - return true; - } - return false; - } - - @Override - public CowedByWisdomEffect copy() { - return new CowedByWisdomEffect(this); + public CowedByWisdomayCostToAttackBlockEffect copy() { + return new CowedByWisdomayCostToAttackBlockEffect(this); } } diff --git a/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffect.java b/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffect.java new file mode 100644 index 00000000000..63920ccddd9 --- /dev/null +++ b/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffect.java @@ -0,0 +1,42 @@ +/* + * 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; + +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author LevelX2 + */ +public interface PayCostToAttackBlockEffect extends ReplacementEffect { + + Cost getCostToPay(GameEvent event, Ability source, Game game); +} diff --git a/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffectImpl.java b/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffectImpl.java new file mode 100644 index 00000000000..917665ca827 --- /dev/null +++ b/Mage/src/mage/abilities/effects/PayCostToAttackBlockEffectImpl.java @@ -0,0 +1,113 @@ +/* + * 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; + +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.abilities.costs.mana.ManaCostImpl; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectImpl implements PayCostToAttackBlockEffect { + + public static enum RestrictType { + + ATTACK, ATTACK_AND_BLOCK, BLOCK + } + + private final Cost cost; + private final RestrictType restrictType; + + public PayCostToAttackBlockEffectImpl(Duration duration, Outcome outcome, RestrictType restrictType, Cost cost) { + super(duration, outcome, false); + this.restrictType = restrictType; + this.cost = cost; + } + + public PayCostToAttackBlockEffectImpl(PayCostToAttackBlockEffectImpl effect) { + super(effect); + if (effect.cost != null) { + this.cost = effect.cost.copy(); + } else { + this.cost = null; + } + this.restrictType = effect.restrictType; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + switch (restrictType) { + case ATTACK: + return event.getType() == GameEvent.EventType.DECLARE_ATTACKER; + case BLOCK: + return event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER); + case ATTACK_AND_BLOCK: + return event.getType() == GameEvent.EventType.DECLARE_ATTACKER || event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER); + } + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Player player = game.getPlayer(event.getPlayerId()); + Cost attackBlockTax = getCostToPay(event, source, game); + if (player != null && attackBlockTax != null) { + String chooseText; + if (event.getType().equals(GameEvent.EventType.DECLARE_ATTACKER)) { + chooseText = "Pay " + attackBlockTax.getText() + " to attack?"; + } else { + chooseText = "Pay " + attackBlockTax.getText() + " to block?"; + } + if (attackBlockTax.canPay(source, source.getSourceId(), player.getId(), game) + && player.chooseUse(Outcome.Neutral, chooseText, source, game)) { + if (attackBlockTax instanceof ManaCostImpl) { + ManaCostsImpl manaCosts = new ManaCostsImpl(attackBlockTax.getText()); + if (manaCosts.payOrRollback(source, game, source.getSourceId(), event.getPlayerId())) { + return false; + } + } + } + return true; + } + return false; + } + + @Override + public Cost getCostToPay(GameEvent event, Ability source, Game game) { + return cost; + } + +}