Search in sources :

Example 16 with Cost

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

the class FalkenrathAristocratEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            Permanent sacrificedCreature = ((SacrificeTargetCost) cost).getPermanents().get(0);
            Permanent sourceCreature = game.getPermanent(source.getSourceId());
            if (sacrificedCreature.hasSubtype(SubType.HUMAN, game) && sourceCreature != null) {
                sourceCreature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
                break;
            }
        }
    }
    return true;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 17 with Cost

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

the class FoodChainManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int manaCostExiled = 0;
        for (Cost cost : source.getCosts()) {
            if (cost.isPaid() && cost instanceof ExileTargetCost) {
                for (Card card : ((ExileTargetCost) cost).getPermanents()) {
                    manaCostExiled += card.getManaValue();
                }
            }
        }
        ChoiceColor choice = new ChoiceColor();
        if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
            return mana;
        }
        Mana chosen = choice.getMana(manaCostExiled + 1);
        return manaBuilder.setMana(chosen, source, game).build();
    }
    return mana;
}
Also used : Player(mage.players.Player) ExileTargetCost(mage.abilities.costs.common.ExileTargetCost) CreatureCastConditionalMana(mage.abilities.mana.conditional.CreatureCastConditionalMana) ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) ChoiceColor(mage.choices.ChoiceColor) Cost(mage.abilities.costs.Cost) ExileTargetCost(mage.abilities.costs.common.ExileTargetCost) Card(mage.cards.Card)

Example 18 with Cost

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

the class SacrificedWasCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            UUID targetId = cost.getTargets().getFirstTarget();
            Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
            if (filter.match(permanent, game)) {
                return true;
            }
        }
    }
    return false;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 19 with Cost

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

the class MudslideEffect 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(filter, game.getActivePlayerId(), game).size();
        while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Pay {2} and untap a tapped creature without flying under your control?", source, game)) {
            Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
            if (player.choose(Outcome.Untap, tappedCreatureTarget, source.getSourceId(), game)) {
                Cost cost = ManaUtil.createManaCost(2, 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(filter, 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 20 with Cost

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

the class MtendaLionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getCombat().getDefendingPlayerId(source.getSourceId(), game));
    if (player == null) {
        return false;
    }
    Cost cost = new ManaCostsImpl("{U}");
    if (!player.chooseUse(outcome, "Pay {U} to prevent damage?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
        return false;
    }
    game.addEffect(new PreventCombatDamageBySourceEffect(Duration.EndOfTurn), source);
    return true;
}
Also used : Player(mage.players.Player) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) PreventCombatDamageBySourceEffect(mage.abilities.effects.common.PreventCombatDamageBySourceEffect)

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