Search in sources :

Example 96 with Cost

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

the class RootwaterThiefEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || damagedPlayer == null) {
        return false;
    }
    String message = "Pay {2} to exile a card from damaged player's library?";
    Cost cost = new ManaCostsImpl("{2}");
    if (controller.chooseUse(Outcome.Benefit, message, source, game) && cost.pay(source, game, source, controller.getId(), false, null)) {
        TargetCardInLibrary target = new TargetCardInLibrary();
        if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) {
            if (!target.getTargets().isEmpty()) {
                Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game);
                if (card != null) {
                    controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
                }
            }
        }
        damagedPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card)

Example 97 with Cost

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

the class GreatestPowerCountCreatureYouControl method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        Player controller = game.getPlayer(source.getControllerId());
        MageObject sourceObject = game.getObject(source.getSourceId());
        if (player != null && controller != null && sourceObject != null) {
            int maxPower = new GreatestPowerCountCreatureYouControl().calculate(game, source, this);
            Cost cost = ManaUtil.createManaCost(maxPower, true);
            if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + "? (otherwise " + spell.getName() + " will be countered)", source, game) && cost.pay(source, game, source, player.getId(), false)) {
                return true;
            }
            game.informPlayers(sourceObject.getName() + ": cost wasn't payed - countering " + spell.getName());
            return game.getStack().counter(source.getFirstTarget(), source, game);
        }
    }
    return false;
}
Also used : Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Cost(mage.abilities.costs.Cost) ValueHint(mage.abilities.hint.ValueHint)

Example 98 with Cost

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

the class StenchOfEvilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Permanent land : game.getBattlefield().getAllActivePermanents(filter, game)) {
        UUID landControllerId = land.getControllerId();
        if (land.destroy(source, game, false)) {
            Cost cost = new ManaCostsImpl("{2}");
            Player landController = game.getPlayer(landControllerId);
            if (landController != null && cost.canPay(source, source, landControllerId, game) && !cost.pay(source, game, source, landControllerId, false)) {
                landController.damage(1, source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 99 with Cost

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

the class TortureChamberEffect2 method apply.

@Override
public boolean apply(Game game, Ability source) {
    int countersRemoved = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof RemoveAllCountersSourceCost) {
            countersRemoved = ((RemoveAllCountersSourceCost) cost).getRemovedCounters();
        }
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        permanent.damage(countersRemoved, source.getSourceId(), source, game, false, true);
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) RemoveAllCountersSourceCost(mage.abilities.costs.common.RemoveAllCountersSourceCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost)

Example 100 with Cost

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

the class TormentedThoughtsDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        int power = 0;
        COSTS: for (Cost cost : source.getCosts()) {
            if (cost instanceof SacrificeTargetCost) {
                SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
                for (Permanent permanent : sacCost.getPermanents()) {
                    power = permanent.getPower().getValue();
                    break COSTS;
                }
            }
        }
        if (power > 0) {
            targetPlayer.discard(power, false, false, source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) 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)

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