Search in sources :

Example 1 with SpellAbility

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

the class CardCanBeCastPredicate method apply.

@Override
public boolean apply(Card input, Game game) {
    SpellAbility ability = input.getSpellAbility().copy();
    ability.setControllerId(controllerId);
    input.adjustTargets(ability, game);
    return ability.canChooseTarget(game, controllerId);
}
Also used : SpellAbility(mage.abilities.SpellAbility)

Example 2 with SpellAbility

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

the class OfferingCostReductionEffect method applies.

@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
    if (game.inCheckPlayableState()) {
        // Cost modifaction does not work correctly for checking available spells
        return false;
    }
    if (abilityToModify.getSourceId().equals(source.getSourceId()) && abilityToModify instanceof SpellAbility) {
        Card card = game.getCard(source.getSourceId());
        if (card != null) {
            Object object = game.getState().getValue("offering_Id_" + card.getId());
            if (object != null && object.equals(this.activationId) && getTargetPointer().getFirst(game, source) != null) {
                return true;
            }
        }
        // to target to offer, no correct activation ID this effect is no longer valid
        this.discard();
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 3 with SpellAbility

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

the class ProwlAbility method askToActivateAlternativeCosts.

@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
    if (ability instanceof SpellAbility) {
        Player player = game.getPlayer(ability.getControllerId());
        if (player == null) {
            return false;
        }
        if (ProwlCondition.instance.apply(game, ability)) {
            this.resetProwl();
            for (AlternativeCost2 prowlCost : prowlCosts) {
                if (prowlCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(Outcome.Benefit, "Cast for " + PROWL_KEYWORD + " cost " + prowlCost.getText(true) + " ?", ability, game)) {
                    prowlCost.activate();
                    ability.getManaCostsToPay().clear();
                    ability.getCosts().clear();
                    for (Iterator it = ((Costs) prowlCost).iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCostsImpl) {
                            ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                }
            }
        }
    }
    return isActivated(ability, game);
}
Also used : Player(mage.players.Player) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 4 with SpellAbility

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

the class KickerAbility method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (ability instanceof SpellAbility) {
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            this.resetKicker();
            for (OptionalAdditionalCost kickerCost : kickerCosts) {
                boolean again = true;
                while (player.canRespond() && again) {
                    String times = "";
                    if (kickerCost.isRepeatable()) {
                        int activatedCount = getKickedCounterStrict(game, ability, kickerCost.getText(true));
                        times = (activatedCount + 1) + (activatedCount == 0 ? " time " : " times ");
                    }
                    // canPay checks only single mana available, not total mana usage
                    if (kickerCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(/*Outcome.Benefit*/
                    Outcome.AIDontUseIt, "Pay " + times + kickerCost.getText(false) + " ?", ability, game)) {
                        this.activateKicker(kickerCost, ability, game);
                        if (kickerCost instanceof Costs) {
                            // as multiple costs
                            for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext(); ) {
                                Object kickerCostObject = itKickerCost.next();
                                if ((kickerCostObject instanceof Costs)) {
                                    for (@SuppressWarnings("unchecked") Iterator<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext(); ) {
                                        addKickerCostsToAbility(itDetails.next(), ability, game);
                                    }
                                } else {
                                    addKickerCostsToAbility((Cost) kickerCostObject, ability, game);
                                }
                            }
                        } else {
                            // as single cost
                            addKickerCostsToAbility(kickerCost, ability, game);
                        }
                        again = kickerCost.isRepeatable();
                    } else {
                        again = false;
                    }
                }
            }
        }
    }
}
Also used : Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility) MageObject(mage.MageObject)

Example 5 with SpellAbility

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

the class DargoTheShipwreckerWatcher method apply.

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

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