Search in sources :

Example 21 with Cost

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

the class PrimeSpeakerVannifarEffect 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);
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    controller.shuffleLibrary(source, game);
    return true;
}
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) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 22 with Cost

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

the class RhysticScryingEffect 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) {
        boolean result = true;
        boolean doEffect = false;
        Cost cost = ManaUtil.createManaCost(2, false);
        // check if any player is willing to pay
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.canRespond() && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " for " + sourceObject.getLogName() + "?", source, game)) {
                cost.clearPaid();
                if (cost.pay(source, game, source, player.getId(), false, null)) {
                    if (!game.isSimulation()) {
                        game.informPlayers(player.getLogName() + " pays the cost for " + sourceObject.getLogName());
                    }
                    doEffect = true;
                    break;
                }
            }
        }
        // do the effects if anybody paid
        if (doEffect) {
            controller.discard(3, false, false, source, game);
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost)

Example 23 with Cost

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

the class RhysticStudyDrawEffect 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(1, false);
            if (opponent.chooseUse(Outcome.Benefit, "Pay {1}?", 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 24 with Cost

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

the class ScourgeOfNelTothPlayEffect method applies.

@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
    if (sourceId.equals(source.getSourceId()) && source.isControlledBy(affectedControllerId)) {
        if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
            Player player = game.getPlayer(affectedControllerId);
            if (player != null) {
                // can sometimes be cast with base mana cost from grave????
                Costs<Cost> costs = new CostsImpl<>();
                costs.add(new SacrificeTargetCost(new TargetControlledCreaturePermanent(2)));
                player.setCastSourceIdWithAlternateMana(sourceId, new ManaCostsImpl<>("{B}{B}"), costs);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) CostsImpl(mage.abilities.costs.CostsImpl) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 25 with Cost

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

the class ScourgeOfSkolaValeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            int amount = ((SacrificeTargetCost) cost).getPermanents().get(0).getToughness().getValue();
            Player player = game.getPlayer(source.getControllerId());
            if (amount > 0 && player != null) {
                return new AddCountersSourceEffect(CounterType.P1P1.createInstance(amount), true).apply(game, source);
            }
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

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