Search in sources :

Example 56 with Cost

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

the class ConfiscationCoupEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        new GetEnergyCountersControllerEffect(4).apply(game, source);
        Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (targetPermanent != null) {
            Cost cost = new PayEnergyCost(targetPermanent.getManaCost().manaValue());
            if (cost.canPay(source, source, source.getControllerId(), game)) {
                int manaValue = targetPermanent.getManaCost().manaValue();
                StringBuilder energy = new StringBuilder(manaValue);
                for (int i = 0; i < manaValue; i++) {
                    energy.append("{E}");
                }
                if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
                    if (cost.pay(source, game, source, source.getControllerId(), true)) {
                        ContinuousEffect controllEffect = new GainControlTargetEffect(Duration.Custom);
                        controllEffect.setTargetPointer(new FixedTarget(targetPermanent, game));
                        game.addEffect(controllEffect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GetEnergyCountersControllerEffect(mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 57 with Cost

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

the class DivertEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(source.getFirstTarget());
    Cost cost = ManaUtil.createManaCost(2, false);
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        if (player != null) {
            if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
                return spell.chooseNewTargets(game, source.getControllerId(), true, true, null);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 58 with Cost

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

the class DisruptionAuraEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player != null && permanent != null) {
        String message = CardUtil.replaceSourceName("Pay {this} mana cost ?", permanent.getLogName());
        Cost cost = permanent.getManaCost().copy();
        if (player.chooseUse(Outcome.Benefit, message, source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        permanent.sacrifice(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Cost(mage.abilities.costs.Cost)

Example 59 with Cost

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

the class DreamTidesEffect 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.AIDontUseIt, "Pay {2} and untap a tapped nongreen creature under your control?", source, game)) {
            Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
            if (player.choose(Outcome.Detriment, tappedCreatureTarget, source.getSourceId(), game)) {
                Cost cost = ManaUtil.createManaCost(2, false);
                Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
                if (cost.pay(source, game, source, player.getId(), false)) {
                    tappedCreature.untap(game);
                }
            }
            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 60 with Cost

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

the class IceCaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (sourcePermanent != null && spell != null && controller != null) {
        Player spellController = game.getPlayer(spell.getControllerId());
        Cost cost = new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
        if (spellController != null) {
            for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null && !player.equals(spellController)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Pay " + cost.getText() + " to counter " + spell.getIdName() + '?', source, game)) {
                        if (cost.pay(source, game, source, playerId, false, null)) {
                            game.informPlayers(player.getLogName() + " pays" + cost.getText() + " to counter " + spell.getIdName() + '.');
                            game.getStack().counter(spell.getId(), source, game);
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Spell(mage.game.stack.Spell)

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