Search in sources :

Example 86 with Cost

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

the class HarnessedLightningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        new GetEnergyCountersControllerEffect(3).apply(game, source);
        int numberToPay = controller.getAmount(0, controller.getCounters().getCount(CounterType.ENERGY), "How many {E} do you like to pay?", game);
        if (numberToPay > 0) {
            Cost cost = new PayEnergyCost(numberToPay);
            if (cost.pay(source, game, source, source.getControllerId(), true)) {
                Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
                if (targetCreature != null) {
                    targetCreature.damage(numberToPay, source.getSourceId(), source, game, false, true);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) GetEnergyCountersControllerEffect(mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) Cost(mage.abilities.costs.Cost) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost)

Example 87 with Cost

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

the class HornOfPlentyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player caster = game.getPlayer(targetPointer.getFirst(game, source));
    if (caster != null) {
        if (caster.chooseUse(Outcome.DrawCard, "Pay {1} to draw a card at the beginning of the next end step?", source, game)) {
            Cost cost = new ManaCostsImpl("{1}");
            if (cost.pay(source, game, source, caster.getId(), false, null)) {
                Effect effect = new DrawCardTargetEffect(1);
                effect.setTargetPointer(new FixedTarget(caster.getId()));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY), source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 88 with Cost

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

the class JhoiraOfTheGhituSuspendEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Card> cards = new ArrayList<>();
    for (Cost cost : source.getCosts()) {
        if (cost instanceof ExileFromHandCost) {
            cards = ((ExileFromHandCost) cost).getCards();
        }
    }
    if (cards != null && !cards.isEmpty()) {
        // always one card to exile
        Card card = game.getCard(cards.get(0).getId());
        if (card == null) {
            return false;
        }
        card = card.getMainCard();
        boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
        UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
        if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getName(), source, game, Zone.HAND, true)) {
            card.addCounters(CounterType.TIME.createInstance(4), source.getControllerId(), source, game);
            if (!hasSuspend) {
                game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
            }
            game.informPlayers(controller.getLogName() + " suspends 4 - " + card.getName());
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) ArrayList(java.util.ArrayList) UUID(java.util.UUID) GainSuspendEffect(mage.abilities.effects.common.continuous.GainSuspendEffect) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Cost(mage.abilities.costs.Cost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) MageObjectReference(mage.MageObjectReference) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 89 with Cost

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

the class MagneticMountainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        int countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
        while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {4} and untap a tapped blue creature under your control?", source, game)) {
            Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter2, true);
            if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
                Cost cost = ManaUtil.createManaCost(4, false);
                Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
                if (tappedCreature != null && cost.pay(source, game, source, player.getId(), false)) {
                    tappedCreature.untap(game);
                } else {
                    break;
                }
            } else {
                break;
            }
            countBattlefield = game.getBattlefield().getAllActivePermanents(filter2, game.getActivePlayerId(), game).size();
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost)

Example 90 with Cost

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

the class MercadianLiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int numberOfCounters = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof RemoveVariableCountersSourceCost) {
                numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
            }
        }
        System.out.println("The number is " + numberOfCounters);
        FilterCreatureCard filter = new FilterCreatureCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
        filter.setMessage("creature card with mana value " + numberOfCounters);
        TargetCardInHand target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            target.setRequired(false);
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterCreatureCard(mage.filter.common.FilterCreatureCard) 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