Search in sources :

Example 41 with Cost

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

the class AthreosDiesCreatureTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    UUID creatureId = (UUID) this.getValue("creatureId");
    Card creature = game.getCard(creatureId);
    if (creature == null) {
        return true;
    }
    Player opponent = game.getPlayer(source.getFirstTarget());
    boolean paid = false;
    if (opponent != null) {
        Cost cost = new PayLifeCost(3);
        if (cost.canPay(source, source, opponent.getId(), game) && opponent.chooseUse(outcome, "Pay 3 life to prevent that " + creature.getLogName() + " returns to " + controller.getLogName() + "'s hand?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
            paid = true;
        }
    }
    if ((opponent != null && paid) || game.getState().getZone(creature.getId()) != Zone.GRAVEYARD) {
        return true;
    }
    controller.moveCards(creature, Zone.HAND, source, game);
    return true;
}
Also used : Player(mage.players.Player) PayLifeCost(mage.abilities.costs.common.PayLifeCost) UUID(java.util.UUID) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 42 with Cost

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

the class CrookedScalesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent yourGuy = game.getPermanent(getTargetPointer().getFirst(game, source));
        Permanent theirGuy = game.getPermanent(source.getTargets().get(1).getFirstTarget());
        boolean keepGoing;
        Cost cost;
        String message = "You lost the flip. Pay {3} to prevent your creature from being destroyed?";
        do {
            if (controller.flipCoin(source, game, true)) {
                if (theirGuy != null) {
                    theirGuy.destroy(source, game, false);
                }
                keepGoing = false;
            } else {
                cost = ManaUtil.createManaCost(3, false);
                if (!(controller.chooseUse(Outcome.Benefit, message, source, game) && cost.pay(source, game, source, controller.getId(), false, null))) {
                    if (yourGuy != null) {
                        yourGuy.destroy(source, game, false);
                    }
                    keepGoing = false;
                } else {
                    keepGoing = true;
                }
            }
        } while (keepGoing && controller.canRespond());
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponentsCreaturePermanent(mage.target.common.TargetOpponentsCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost)

Example 43 with Cost

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

the class EldritchEvolutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent != null && controller != null) {
        int newConvertedCost = sacrificedPermanent.getManaValue() + 2;
        FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost + " or less");
        filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, newConvertedCost + 1));
        filter.add(CardType.CREATURE.getPredicate());
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 44 with Cost

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

the class NeoformReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            ContinuousEffectImpl effect = new NeoformReplacementEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
            if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                effect.discard();
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 45 with Cost

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

the class PhyrexianProcessorCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int payAmount = controller.getAmount(0, controller.getLife(), "Pay any amount of life", game);
    Cost cost = new PayLifeCost(payAmount);
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    game.informPlayers((sourceCard != null ? sourceCard.getName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life.");
    String key = CardUtil.getCardZoneString("lifePaid", source.getSourceId(), game);
    game.getState().setValue(key, payAmount);
    permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Card(mage.cards.Card)

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