Search in sources :

Example 91 with Cost

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

the class TapXTargetCost method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    for (Cost cost : source.getCosts()) {
        if (cost instanceof TapXTargetCost) {
            xValue = ((TapXTargetCost) cost).getAmount();
            break;
        }
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, xValue));
    controller.lookAtCards(sourceObject.getIdName(), cards, game);
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
    target.setNotTarget(true);
    if (controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.HAND, source, game);
            cards.remove(card);
        }
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TapTargetCost(mage.abilities.costs.common.TapTargetCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 92 with Cost

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

the class MomentousFallEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int power = 0;
        int toughness = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
                power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
                toughness = ((SacrificeTargetCost) cost).getPermanents().get(0).getToughness().getValue();
                break;
            }
        }
        if (power > 0) {
            controller.drawCards(power, source, game);
        }
        if (toughness > 0) {
            controller.gainLife(toughness, game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 93 with Cost

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

the class MysticRemoraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && opponent != null && sourceObject != null) {
        if (controller.chooseUse(Outcome.DrawCard, "Draw a card (" + sourceObject.getLogName() + ')', source, game)) {
            Cost cost = ManaUtil.createManaCost(4, false);
            if (opponent.chooseUse(Outcome.Benefit, "Pay {4}?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
                return true;
            }
            controller.drawCards(1, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost)

Example 94 with Cost

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

the class OsgirTheReconstructorCreateArtifactTokensEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = null;
    for (Cost cost : source.getCosts()) {
        if (!(cost instanceof ExileFromGraveCost)) {
            continue;
        }
        card = ((ExileFromGraveCost) cost).getExiledCards().get(0);
    }
    if (player == null || card == null) {
        return false;
    }
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(player.getId(), null, false, 2);
    effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
    effect.apply(game, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) VariableCost(mage.abilities.costs.VariableCost) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard) FilterCard(mage.filter.FilterCard)

Example 95 with Cost

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

the class ProwlingPangolinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        boolean costPaid = false;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledCreaturePermanent("two creatures"), true));
            Player player = game.getPlayer(playerId);
            if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice two creatures?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
                costPaid = true;
            }
        }
        if (costPaid) {
            Permanent sourceObject = game.getPermanent(source.getSourceId());
            if (sourceObject != null) {
                sourceObject.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

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