Search in sources :

Example 61 with Cost

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

the class LifesLegacyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int power = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            power = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
            break;
        }
    }
    if (power > 0) {
        controller.drawCards(power, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 62 with Cost

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

the class LightningRunnerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        new GetEnergyCountersControllerEffect(2).apply(game, source);
        if (controller.getCounters().getCount(CounterType.ENERGY) > 7) {
            Cost cost = new PayEnergyCost(8);
            if (controller.chooseUse(outcome, "Pay {E}{E}{E}{E}{E}{E}{E}{E} to use this? ", "Untap all creatures you control and after this phase, there is an additional combat phase.", "Yes", "No", source, game) && cost.pay(source, game, source, source.getControllerId(), true)) {
                new UntapAllControllerEffect(new FilterControlledCreaturePermanent()).apply(game, source);
                new AdditionalCombatPhaseEffect().apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) GetEnergyCountersControllerEffect(mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect) AdditionalCombatPhaseEffect(mage.abilities.effects.common.AdditionalCombatPhaseEffect) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) Cost(mage.abilities.costs.Cost) PayEnergyCost(mage.abilities.costs.common.PayEnergyCost) UntapAllControllerEffect(mage.abilities.effects.common.UntapAllControllerEffect)

Example 63 with Cost

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

the class NamelessRaceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int permanentsInPlay = new PermanentsOnBattlefieldCount(filter).calculate(game, source, null);
    int cardsInGraveyards = new CardsInAllGraveyardsCount(filter2).calculate(game, source, null);
    int maxAmount = Math.min(permanentsInPlay + cardsInGraveyards, controller.getLife());
    int payAmount = controller.getAmount(0, maxAmount, "Pay up to " + maxAmount + " life", game);
    Cost cost = new PayLifeCost(payAmount);
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    Card sourceCard = game.getCard(source.getSourceId());
    game.informPlayers((sourceCard != null ? sourceCard.getLogName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life");
    game.addEffect(new SetPowerToughnessSourceEffect(payAmount, payAmount, Duration.Custom, SubLayer.CharacteristicDefining_7a), source);
    permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game);
    return true;
}
Also used : SetPowerToughnessSourceEffect(mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) CardsInAllGraveyardsCount(mage.abilities.dynamicvalue.common.CardsInAllGraveyardsCount) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) Cost(mage.abilities.costs.Cost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 64 with Cost

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

the class OgreMarauderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player defender = game.getPlayer(defendingPlayerId);
    if (defender != null && sourceObject != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        if (cost.canPay(source, source, defendingPlayerId, game) && defender.chooseUse(Outcome.LoseAbility, "Sacrifice a creature to prevent that " + sourceObject.getLogName() + " can't be blocked?", source, game)) {
            if (!cost.pay(source, game, source, defendingPlayerId, false, null)) {
                // cost was not payed - so source can't be blocked
                ContinuousEffect effect = new CantBeBlockedSourceEffect(Duration.EndOfTurn);
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) MageObject(mage.MageObject) CantBeBlockedSourceEffect(mage.abilities.effects.common.combat.CantBeBlockedSourceEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 65 with Cost

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

the class SmotheringTitheEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    Cost cost = ManaUtil.createManaCost(2, false);
    if (!player.chooseUse(Outcome.Detriment, "Pay {2} to prevent this effect?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
        return new TreasureToken().putOntoBattlefield(1, game, source, source.getControllerId());
    }
    return false;
}
Also used : Player(mage.players.Player) TreasureToken(mage.game.permanent.token.TreasureToken) Cost(mage.abilities.costs.Cost)

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