Search in sources :

Example 1 with SacrificeXTargetCost

use of mage.abilities.costs.common.SacrificeXTargetCost 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)

Example 2 with SacrificeXTargetCost

use of mage.abilities.costs.common.SacrificeXTargetCost in project mage by magefree.

the class YasharnImplacableEarthEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    boolean canTargetLand = true;
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || event.getType() == GameEvent.EventType.CAST_SPELL) {
        if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
            if (permanent == null) {
                return false;
            }
        }
        Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
        for (Cost cost : ability.get().getCosts()) {
            if (cost instanceof PayLifeCost || cost instanceof PayVariableLifeCost) {
                // can't pay with life
                return true;
            }
            if (cost instanceof SacrificeSourceCost && !permanent.isLand()) {
                return true;
            }
            if (cost instanceof SacrificeTargetCost) {
                SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
                Filter filter = sacrificeCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAllCost) {
                SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachedCost) {
                SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeAttachmentCost) {
                SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost;
                Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
            if (cost instanceof SacrificeXTargetCost) {
                SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost;
                Filter filter = sacrificeCost.getFilter();
                for (Object predicate : filter.getPredicates()) {
                    if (predicate instanceof CardType.CardTypePredicate) {
                        if (!predicate.toString().equals("CardType(Land)")) {
                            canTargetLand = false;
                        }
                    }
                }
                // must be nonland target
                return !canTargetLand;
            }
        }
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) SacrificeAttachedCost(mage.abilities.costs.common.SacrificeAttachedCost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Filter(mage.filter.Filter) SacrificeAttachmentCost(mage.abilities.costs.common.SacrificeAttachmentCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObject(mage.MageObject) SacrificeAllCost(mage.abilities.costs.common.SacrificeAllCost) PayVariableLifeCost(mage.abilities.costs.common.PayVariableLifeCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost)

Example 3 with SacrificeXTargetCost

use of mage.abilities.costs.common.SacrificeXTargetCost in project mage by magefree.

the class AwakenTheBloodAvatarCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    for (Cost cost : spellAbility.getCosts()) {
        if (!(cost instanceof SacrificeXTargetCost)) {
            continue;
        }
        if (game.inCheckPlayableState()) {
            // allows to cast in getPlayable
            int reduction = ((SacrificeXTargetCost) cost).getMaxValue(spellAbility, game);
            CardUtil.adjustCost(spellAbility, reduction * 2);
        } else {
            // real cast
            int reduction = ((SacrificeXTargetCost) cost).getAmount();
            CardUtil.adjustCost(spellAbility, reduction * 2);
        }
        break;
    }
    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

Cost (mage.abilities.costs.Cost)3 SacrificeXTargetCost (mage.abilities.costs.common.SacrificeXTargetCost)3 SpellAbility (mage.abilities.SpellAbility)2 MageObject (mage.MageObject)1 Ability (mage.abilities.Ability)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 PayVariableLifeCost (mage.abilities.costs.common.PayVariableLifeCost)1 SacrificeAllCost (mage.abilities.costs.common.SacrificeAllCost)1 SacrificeAttachedCost (mage.abilities.costs.common.SacrificeAttachedCost)1 SacrificeAttachmentCost (mage.abilities.costs.common.SacrificeAttachmentCost)1 SacrificeSourceCost (mage.abilities.costs.common.SacrificeSourceCost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 Filter (mage.filter.Filter)1 Permanent (mage.game.permanent.Permanent)1