Search in sources :

Example 26 with Cost

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

the class ShroudedLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && opponent != null) {
        FilterCard filter = new FilterCard();
        filter.add(new OwnerIdPredicate(you.getId()));
        Cost cost = new ManaCostsImpl("{B}");
        TargetCardInGraveyard chosenCard;
        Card card = null;
        boolean done = false;
        do {
            chosenCard = new TargetCardInGraveyard(filter);
            chosenCard.setNotTarget(true);
            if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
                opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
                card = game.getCard(chosenCard.getFirstTarget());
                if (card != null) {
                    filter.add(Predicates.not(new CardIdPredicate(card.getId())));
                    game.informPlayers("Shrouded Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
                }
            } else {
                done = true;
            }
            if (!done) {
                done = true;
                if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {B} to choose a different card ?", source, game)) {
                    cost.clearPaid();
                    if (cost.pay(source, game, source, you.getId(), false, null)) {
                        done = false;
                    }
                }
            }
        } while (!done);
        if (card != null) {
            Cards cardsToHand = new CardsImpl();
            cardsToHand.add(card);
            you.moveCards(cardsToHand, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) FilterCard(mage.filter.FilterCard) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 27 with Cost

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

the class WolfOfDevilsBreachDiscardCostCardConvertedManaCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    for (Effect sourceEffect : sourceAbility.getEffects()) {
        if (sourceEffect instanceof DoIfCostPaid) {
            Cost doCosts = ((DoIfCostPaid) sourceEffect).getCost();
            if (doCosts instanceof Costs) {
                Costs costs = (Costs) doCosts;
                for (Object cost : costs) {
                    if (cost instanceof DiscardCardCost) {
                        DiscardCardCost discardCost = (DiscardCardCost) cost;
                        int cmc = 0;
                        for (Card card : discardCost.getCards()) {
                            cmc += card.getManaValue();
                        }
                        return cmc;
                    }
                }
            }
        }
    }
    return 0;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Costs(mage.abilities.costs.Costs) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 28 with Cost

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

the class CounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell == null) {
        return false;
    }
    Player player = game.getPlayer(spell.getControllerId());
    if (player == null) {
        return false;
    }
    Cost costToPay;
    String costValueMessage;
    if (cost != null) {
        costToPay = cost.copy();
        costValueMessage = costToPay.getText();
    } else {
        costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
        costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
    }
    String message = "";
    if (costToPay instanceof ManaCost) {
        message += "Pay ";
    }
    message += costValueMessage + '?';
    costToPay.clearPaid();
    if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
        game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
        if (exile) {
            game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
        } else {
            return game.getStack().counter(spell.getId(), source, game);
        }
    }
    game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
    return true;
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 29 with Cost

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

the class CrystalShardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller == null || targetCreature == null) {
        return true;
    }
    Player player = game.getPlayer(targetCreature.getControllerId());
    if (player == null) {
        return true;
    }
    Cost cost = ManaUtil.createManaCost(1, false);
    String message = "Pay {1}? (Otherwise " + targetCreature.getName() + " will be returned to its owner's hand)";
    if (player.chooseUse(Outcome.Benefit, message, source, game)) {
        cost.pay(source, game, source, targetCreature.getControllerId(), false, null);
    }
    return cost.isPaid() || controller.moveCards(targetCreature, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) CompositeCost(mage.abilities.costs.CompositeCost) OrCost(mage.abilities.costs.OrCost)

Example 30 with Cost

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

the class CrypticGatewayPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (source.getCosts() == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
    for (Cost cost : source.getCosts()) {
        if (cost instanceof CrypticGatewayCost) {
            Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
            filter.add(predicate);
            return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) Cost(mage.abilities.costs.Cost) Predicate(mage.filter.predicate.Predicate) TappedPredicate(mage.filter.predicate.permanent.TappedPredicate)

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