/* * 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.cards.m; import java.util.UUID; import mage.ConditionalMana; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.effects.OneShotEffect; import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.conditional.CreatureCastConditionalMana; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; import mage.game.Game; import mage.target.common.TargetControlledCreaturePermanent; import mage.abilities.effects.common.AddConditionalManaOfAnyColorEffect; /** * * @author MarcoMarin */ public class Metamorphosis extends CardImpl { public Metamorphosis(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{G}"); // As an additional cost to cast Metamorphosis, sacrifice a creature. this.getSpellAbility().addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent())); this.getSpellAbility().addEffect(new MetamorphosisEffect()); // Add X mana of any one color to your mana pool, where X is one plus the sacrificed creature's converted mana cost. Spend this mana only to cast creature spells. } public Metamorphosis(final Metamorphosis card) { super(card); } @Override public Metamorphosis copy() { return new Metamorphosis(this); } } class MetamorphosisEffect extends OneShotEffect { public MetamorphosisEffect() { super(Outcome.PutManaInPool); staticText = "Add X mana of any one color to your mana pool, for creatures."; } public MetamorphosisEffect(final MetamorphosisEffect effect) { super(effect); } @Override public boolean apply(Game game, Ability source) { int amount = 0; for (Cost cost: source.getCosts()) { if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) { amount = ((SacrificeTargetCost)cost).getPermanents().get(0).getConvertedManaCost()+1; break; } } if (amount > 0) { AddConditionalManaOfAnyColorEffect anyMana = new AddConditionalManaOfAnyColorEffect(amount, new MetamorphosisManaBuilder()); anyMana.apply(game, source); //There probably is a more elegant way of doing this but.. I'm still learning :p } return false; } @Override public MetamorphosisEffect copy() { return new MetamorphosisEffect(this); } } class MetamorphosisManaBuilder extends ConditionalManaBuilder { @Override public ConditionalMana build(Object... options) { return new CreatureCastConditionalMana(this.mana); } @Override public String getRule() { return "Spend this mana only to cast creature spells"; } }