Search in sources :

Example 31 with SpellAbility

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

the class FeedingGroundsEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (abilityToModify instanceof SpellAbility) {
        Plane cPlane = game.getState().getCurrentPlane();
        if (cPlane == null) {
            return false;
        }
        if (!cPlane.getPlaneType().equals(Planes.PLANE_FEEDING_GROUNDS)) {
            return false;
        }
        Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
        if (spell != null) {
            return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
        } else {
            // used at least for flashback ability because Flashback ability doesn't use stack
            Card sourceCard = game.getCard(abilityToModify.getSourceId());
            return filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
        }
    }
    return false;
}
Also used : Plane(mage.game.command.Plane) SpellAbility(mage.abilities.SpellAbility) Spell(mage.game.stack.Spell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 32 with SpellAbility

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

the class GorexTheTombshellReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    for (Cost cost : spellAbility.getCosts()) {
        if (!(cost instanceof ExileXFromYourGraveCost)) {
            continue;
        }
        if (game.inCheckPlayableState()) {
            // allows to cast in getPlayable
            int reduction = ((ExileXFromYourGraveCost) cost).getMaxValue(spellAbility, game);
            CardUtil.adjustCost(spellAbility, reduction * 2);
        } else {
            // real cast
            int reduction = ((ExileXFromYourGraveCost) cost).getAmount();
            CardUtil.adjustCost(spellAbility, reduction * 2);
        }
        break;
    }
    return true;
}
Also used : ExileXFromYourGraveCost(mage.abilities.costs.common.ExileXFromYourGraveCost) SpellAbility(mage.abilities.SpellAbility) ExileXFromYourGraveCost(mage.abilities.costs.common.ExileXFromYourGraveCost) Cost(mage.abilities.costs.Cost)

Example 33 with SpellAbility

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

the class MaelstromMuseWatcher method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    MaelstromMuseWatcher watcher = game.getState().getWatcher(MaelstromMuseWatcher.class);
    if (watcher == null) {
        return false;
    }
    if (watcher.getCount(source.getControllerId()) > spellsCast) {
        // only one use
        discard();
        return false;
    }
    if (!(abilityToModify instanceof SpellAbility) || !abilityToModify.isControlledBy(source.getControllerId())) {
        return false;
    }
    Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
    return spellCard != null && spellCard.isInstantOrSorcery(game);
}
Also used : SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 34 with SpellAbility

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

the class MythUnboundCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    Ability spellAbility = abilityToModify;
    if (spellAbility != null) {
        CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
        int castCount = watcher.getPlaysCount(abilityToModify.getSourceId());
        CardUtil.reduceCost(spellAbility, castCount);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ZoneChangeAllTriggeredAbility(mage.abilities.common.ZoneChangeAllTriggeredAbility) PlayLandAbility(mage.abilities.PlayLandAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher)

Example 35 with SpellAbility

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

the class AlternativeCostSourceAbility method askToActivateAlternativeCosts.

@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
    if (ability != null && AbilityType.SPELL == ability.getAbilityType()) {
        if (filter != null) {
            Card card = game.getCard(ability.getSourceId());
            if (!filter.match(card, ability.getSourceId(), ability.getControllerId(), game)) {
                return false;
            }
        }
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            Costs<AlternativeCost2> alternativeCostsToCheck;
            if (dynamicCost != null) {
                alternativeCostsToCheck = new CostsImpl<>();
                alternativeCostsToCheck.add(convertToAlternativeCost(dynamicCost.getCost(ability, game)));
            } else {
                alternativeCostsToCheck = this.alternateCosts;
            }
            String costChoiceText;
            if (dynamicCost != null) {
                costChoiceText = dynamicCost.getText(ability, game);
            } else {
                costChoiceText = alternativeCostsToCheck.isEmpty() ? "Cast without paying its mana cost?" : "Pay alternative costs? (" + alternativeCostsToCheck.getText() + ')';
            }
            if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
                if (ability instanceof SpellAbility) {
                    ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
                    CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
                } else {
                    ability.getManaCostsToPay().clear();
                }
                if (!onlyMana) {
                    ability.getCosts().clear();
                }
                for (AlternativeCost2 alternateCost : alternativeCostsToCheck) {
                    alternateCost.activate();
                    for (Iterator it = ((Costs) alternateCost).iterator(); it.hasNext(); ) {
                        Cost costDetailed = (Cost) it.next();
                        if (costDetailed instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) costDetailed.copy());
                        } else if (costDetailed != null) {
                            ability.getCosts().add(costDetailed.copy());
                        }
                    }
                }
                // save activated status
                game.getState().setValue(getActivatedKey(ability), Boolean.TRUE);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    return isActivated(ability, game);
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCost(mage.abilities.costs.mana.ManaCost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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