Search in sources :

Example 76 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class SpellSyphonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        if (player != null && controller != null) {
            int amount = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
            if (amount == 0) {
                game.informPlayers("Spell Syphon: no blue permanents in controller's battlefield.");
            } else {
                Cost cost = ManaUtil.createManaCost(amount, false);
                if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
                    game.informPlayers("Spell Syphon: cost wasn't payed - countering target spell.");
                    return game.getStack().counter(source.getFirstTarget(), source, game);
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost)

Example 77 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class SwordOfTheAgesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Set<Card> cardsToExile = new HashSet<>();
    if (controller != null) {
        int totalPower = 0;
        Card card = game.getCard(source.getSourceId());
        if (card != null) {
            // consulted this on mtgjudges - regardless of what zone they end up in after sac, the creature cards and Sword will be moved to exile (unless there's another replacement effect for exiling them)
            cardsToExile.add(card);
        }
        for (Cost cost : source.getCosts()) {
            // Sword of the Ages doesn't count itself for total damage if it's a creature: http://www.mtgsalvation.com/forums/the-game/commander-edh/202963-sword-of-the-ages
            if (cost instanceof SacrificeTargetCost) {
                for (Permanent permanent : ((SacrificeTargetCost) cost).getPermanents()) {
                    totalPower += permanent.getPower().getValue();
                    Card permanentCard = game.getCard(permanent.getId());
                    if (permanentCard != null) {
                        cardsToExile.add(permanentCard);
                    }
                }
            }
        }
        if (totalPower > 0) {
            Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
            if (player != null) {
                player.damage(totalPower, source.getSourceId(), source, game);
            } else {
                Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
                if (creature != null) {
                    creature.damage(totalPower, source.getSourceId(), source, game, false, true);
                }
            }
        }
        return controller.moveCards(cardsToExile, Zone.EXILED, source, game);
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 78 with Cost

use of mage.abilities.costs.Cost 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 79 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class PayCostToAttackBlockEffectImpl method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaCosts attackBlockManaTax = getManaCostToPay(event, source, game);
    if (attackBlockManaTax != null) {
        return handleManaCosts(attackBlockManaTax.copy(), event, source, game);
    }
    Cost attackBlockOtherTax = getOtherCostToPay(event, source, game);
    if (attackBlockOtherTax != null) {
        return handleOtherCosts(attackBlockOtherTax.copy(), event, source, game);
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Cost(mage.abilities.costs.Cost)

Example 80 with Cost

use of mage.abilities.costs.Cost in project mage by magefree.

the class EndemicPlagueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Permanent permanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            permanent = ((SacrificeTargetCost) cost).getPermanents().get(0);
            break;
        }
    }
    if (permanent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new SharesCreatureTypePredicate(permanent));
    return new DestroyAllEffect(filter, true).apply(game, source);
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Aggregations

Cost (mage.abilities.costs.Cost)174 Player (mage.players.Player)142 Permanent (mage.game.permanent.Permanent)86 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)41 Card (mage.cards.Card)32 UUID (java.util.UUID)30 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)29 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)26 TapSourceCost (mage.abilities.costs.common.TapSourceCost)23 FilterCard (mage.filter.FilterCard)22 MageObject (mage.MageObject)19 PayLifeCost (mage.abilities.costs.common.PayLifeCost)17 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)16 FixedTarget (mage.target.targetpointer.FixedTarget)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)13 ContinuousEffect (mage.abilities.effects.ContinuousEffect)12 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)11 OneShotEffect (mage.abilities.effects.OneShotEffect)9