Search in sources :

Example 21 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class ManaUtilTest method testManaReduction.

/**
 * Checks if a given mana reduction left the expected amount of mana costs
 *
 * @param manaCostsToPay
 * @param availablyAny
 * @param available
 * @param expected
 */
private void testManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
    SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl(manaCostsToPay), "Test");
    CardUtil.adjustCost(spellAbility, new ManaCostsImpl(manaToReduce), true);
    Assert.assertTrue("The mana cost to pay " + manaCostsToPay + " reduced by " + manaToReduce + " should left " + restMana + " but the rest was " + spellAbility.getManaCostsToPay().getText(), spellAbility.getManaCostsToPay().getText().equals(restMana));
}
Also used : SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 22 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class ConspireTriggeredAbility method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (!(ability instanceof SpellAbility)) {
        return;
    }
    Player player = game.getPlayer(getControllerId());
    if (player == null) {
        return;
    }
    // AI supports conspire
    if (!conspireCost.canPay(ability, this, getControllerId(), game) || !player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
        return;
    }
    ability.getEffects().setValue("ConspireActivation" + conspireId + addedById, true);
    for (Iterator<Cost> it = ((Costs<Cost>) conspireCost).iterator(); it.hasNext(); ) {
        Cost cost = (Cost) it.next();
        if (cost instanceof ManaCostsImpl) {
            ability.getManaCostsToPay().add((ManaCostsImpl<?>) cost.copy());
        } else {
            ability.getCosts().add(cost.copy());
        }
    }
}
Also used : Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility) TapTargetCost(mage.abilities.costs.common.TapTargetCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 23 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class EntwineAbility method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (!(ability instanceof SpellAbility)) {
        return;
    }
    Player player = game.getPlayer(ability.getControllerId());
    if (player == null) {
        return;
    }
    this.resetEntwine(game, ability);
    if (entwineCost == null) {
        return;
    }
    // AI can use it
    if (entwineCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + entwineCost.getText(false) + " ?", ability, game)) {
        for (Iterator it = ((Costs) entwineCost).iterator(); it.hasNext(); ) {
            Cost cost = (Cost) it.next();
            if (cost instanceof ManaCostsImpl) {
                ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
            } else {
                ability.getCosts().add(cost.copy());
            }
        }
        activateEntwine(game, ability);
    }
}
Also used : Player(mage.players.Player) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 24 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class FlashbackReplacementEffect method getSpellAbilityToResolve.

@Override
public SpellAbility getSpellAbilityToResolve(Game game) {
    Card card = game.getCard(getSourceId());
    if (card != null) {
        if (spellAbilityToResolve == null) {
            SpellAbility spellAbilityCopy = null;
            if (card instanceof SplitCard) {
                if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((SplitCard) card).getLeftHalfCard().getSpellAbility().copy();
                } else if (((SplitCard) card).getRightHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((SplitCard) card).getRightHalfCard().getSpellAbility().copy();
                }
            } else if (card instanceof ModalDoubleFacesCard) {
                if (((ModalDoubleFacesCard) card).getLeftHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((ModalDoubleFacesCard) card).getLeftHalfCard().getSpellAbility().copy();
                } else if (((ModalDoubleFacesCard) card).getRightHalfCard().getName().equals(abilityName)) {
                    spellAbilityCopy = ((ModalDoubleFacesCard) card).getRightHalfCard().getSpellAbility().copy();
                }
            } else {
                spellAbilityCopy = card.getSpellAbility().copy();
            }
            if (spellAbilityCopy == null) {
                return null;
            }
            spellAbilityCopy.setId(this.getId());
            spellAbilityCopy.getManaCosts().clear();
            spellAbilityCopy.getManaCostsToPay().clear();
            spellAbilityCopy.getCosts().addAll(this.getCosts().copy());
            spellAbilityCopy.addCost(this.getManaCosts().copy());
            spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
            spellAbilityToResolve = spellAbilityCopy;
            ContinuousEffect effect = new FlashbackReplacementEffect();
            effect.setTargetPointer(new FixedTarget(getSourceId(), game.getState().getZoneChangeCounter(getSourceId())));
            game.addEffect(effect, this);
        }
    }
    return spellAbilityToResolve;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SpellAbility(mage.abilities.SpellAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SplitCard(mage.cards.SplitCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Example 25 with SpellAbility

use of mage.abilities.SpellAbility in project mage by magefree.

the class OldGrowthTrollContinuousEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    if (game.getState().getZoneChangeCounter(source.getSourceId()) > zoneChangeCounter) {
        discard();
        return false;
    }
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (sourceObject == null) {
        sourceObject = game.getPermanentEntering(source.getSourceId());
    }
    if (sourceObject == null) {
        return false;
    }
    Permanent troll = sourceObject;
    switch(layer) {
        case TypeChangingEffects_4:
            troll.removeAllCardTypes(game);
            troll.addCardType(game, CardType.ENCHANTMENT);
            troll.removeAllSubTypes(game);
            troll.addSubType(game, SubType.AURA);
            break;
        case AbilityAddingRemovingEffects_6:
            // Spell Ability can be null with clone effects (ex. Moritte)
            if (troll.getSpellAbility() == null) {
                troll.addAbility(new SpellAbility(null, null), source.getSourceId(), game);
            }
            troll.getSpellAbility().getTargets().clear();
            troll.getSpellAbility().getEffects().clear();
            TargetPermanent auraTarget = new TargetPermanent(filter);
            troll.getSpellAbility().addTarget(auraTarget);
            troll.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
            troll.addAbility(new EnchantAbility(auraTarget.getTargetName()), source.getSourceId(), game);
            // add the activated ability
            troll.addAbility(makeAbility(), source.getSourceId(), game);
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) SpellAbility(mage.abilities.SpellAbility) TargetPermanent(mage.target.TargetPermanent) EnchantAbility(mage.abilities.keyword.EnchantAbility) AttachEffect(mage.abilities.effects.common.AttachEffect)

Aggregations

SpellAbility (mage.abilities.SpellAbility)75 Player (mage.players.Player)32 UUID (java.util.UUID)22 Card (mage.cards.Card)21 Permanent (mage.game.permanent.Permanent)21 Ability (mage.abilities.Ability)16 Spell (mage.game.stack.Spell)12 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)10 FilterCard (mage.filter.FilterCard)9 Iterator (java.util.Iterator)8 MageObject (mage.MageObject)7 Target (mage.target.Target)7 ArrayList (java.util.ArrayList)6 ApprovingObject (mage.ApprovingObject)4 ActivatedAbility (mage.abilities.ActivatedAbility)4 Cost (mage.abilities.costs.Cost)4 Effect (mage.abilities.effects.Effect)4 Outcome (mage.constants.Outcome)4 FilterPermanent (mage.filter.FilterPermanent)4 PassAbility (mage.abilities.common.PassAbility)3