Search in sources :

Example 11 with Cost

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

the class PayVariableLoyaltyCost method getMaxValue.

@Override
public int getMaxValue(Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return 0;
    }
    int maxValue = permanent.getCounters(game).getCount(CounterType.LOYALTY.getName());
    // apply cost modification
    if (source instanceof LoyaltyAbility) {
        LoyaltyAbility copiedAbility = ((LoyaltyAbility) source).copy();
        permanent.adjustCosts(copiedAbility, game);
        game.getContinuousEffects().costModification(copiedAbility, game);
        for (Cost cost : copiedAbility.getCosts()) {
            if (cost instanceof PayVariableLoyaltyCost) {
                maxValue += ((PayVariableLoyaltyCost) cost).getCostModification();
            }
        }
    }
    return Math.max(0, maxValue);
}
Also used : Permanent(mage.game.permanent.Permanent) LoyaltyAbility(mage.abilities.LoyaltyAbility) Cost(mage.abilities.costs.Cost)

Example 12 with Cost

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

the class RevealNinjutsuCardCost method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = game.getCard(source.getSourceId());
    if (card != null) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            UUID defendingPlayerId = null;
            for (Cost cost : source.getCosts()) {
                if (cost instanceof ReturnAttackerToHandTargetCost) {
                    defendingPlayerId = ((ReturnAttackerToHandTargetCost) cost).getDefendingPlayerId();
                }
            }
            if (defendingPlayerId != null) {
                game.getCombat().addAttackerToCombat(permanent.getId(), defendingPlayerId, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 13 with Cost

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

the class CephalidShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int count = 0;
    MageObject mageObject = game.getObject(source.getSourceId());
    if (mageObject != null) {
        Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
        if (spell != null) {
            Player controller = game.getPlayer(spell.getControllerId());
            if (controller != null) {
                String name = spell.getName();
                FilterCard filterCardName = new FilterCard();
                filterCardName.add(new NamePredicate(name));
                for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                    Player player = game.getPlayer(playerId);
                    if (player != null) {
                        count += player.getGraveyard().count(filterCardName, game);
                    }
                }
                // even if the cost is 0, we still offer
                Cost cost = ManaUtil.createManaCost(count, true);
                if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
                    return false;
                } else {
                    game.getStack().counter(spell.getId(), source, game);
                    game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 14 with Cost

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

the class DargoTheShipwreckerWatcher method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    SpellAbility spellAbility = (SpellAbility) abilityToModify;
    int reduction = 0;
    for (Cost cost : spellAbility.getCosts()) {
        if (!(cost instanceof SacrificeXTargetCost)) {
            continue;
        }
        if (game.inCheckPlayableState()) {
            // allows to cast in getPlayable
            reduction += ((SacrificeXTargetCost) cost).getMaxValue(spellAbility, game);
        } else {
            // real cast
            reduction += ((SacrificeXTargetCost) cost).getAmount();
        }
        break;
    }
    DargoTheShipwreckerWatcher watcher = game.getState().getWatcher(DargoTheShipwreckerWatcher.class);
    if (watcher != null) {
        reduction += watcher.getSacCount(source.getControllerId());
    }
    CardUtil.adjustCost(spellAbility, reduction * 2);
    return true;
}
Also used : SpellAbility(mage.abilities.SpellAbility) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost) SacrificeXTargetCost(mage.abilities.costs.common.SacrificeXTargetCost) Cost(mage.abilities.costs.Cost)

Example 15 with Cost

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

the class EnergyVortexEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    int counters = permanent.getCounters(game).getCount(CounterType.VORTEX);
    Cost cost = ManaUtil.createManaCost(counters, false);
    if (cost.pay(source, game, source, player.getId(), false)) {
        return true;
    }
    return player.damage(3, source.getSourceId(), source, game) > 0;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) 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