Search in sources :

Example 1 with CostsImpl

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

the class DemilichPlayEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (source.getSourceId().equals(objectId) && source.isControlledBy(affectedControllerId) && game.getState().getZone(objectId) == Zone.GRAVEYARD) {
        Player controller = game.getPlayer(affectedControllerId);
        if (controller != null) {
            Costs<Cost> costs = new CostsImpl<>();
            costs.add(new ExileFromGraveCost(new TargetCardInYourGraveyard(4, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY_FROM_YOUR_GRAVEYARD)));
            controller.setCastSourceIdWithAlternateMana(objectId, new ManaCostsImpl<>("{U}{U}{U}{U}"), costs);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) CostsImpl(mage.abilities.costs.CostsImpl) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cost(mage.abilities.costs.Cost) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost)

Example 2 with CostsImpl

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

the class ScourgeOfNelTothPlayEffect method applies.

@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
    if (sourceId.equals(source.getSourceId()) && source.isControlledBy(affectedControllerId)) {
        if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
            Player player = game.getPlayer(affectedControllerId);
            if (player != null) {
                // can sometimes be cast with base mana cost from grave????
                Costs<Cost> costs = new CostsImpl<>();
                costs.add(new SacrificeTargetCost(new TargetControlledCreaturePermanent(2)));
                player.setCastSourceIdWithAlternateMana(sourceId, new ManaCostsImpl<>("{B}{B}"), costs);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) CostsImpl(mage.abilities.costs.CostsImpl) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 3 with CostsImpl

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

the class NashiMoonSagesScionPlayEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (!super.applies(objectId, source, affectedControllerId, game) || !NashiMoonSagesScionWatcher.checkCard(game, source, mor)) {
        return false;
    }
    Card cardToCheck = mor.getCard(game);
    if (cardToCheck.isLand(game)) {
        return true;
    }
    // allows to play/cast with alternative life cost
    Player controller = game.getPlayer(source.getControllerId());
    PayLifeCost lifeCost = new PayLifeCost(cardToCheck.getSpellAbility().getManaCosts().manaValue());
    Costs<Cost> newCosts = new CostsImpl<>();
    newCosts.add(lifeCost);
    newCosts.addAll(cardToCheck.getSpellAbility().getCosts());
    controller.setCastSourceIdWithAlternateMana(cardToCheck.getId(), null, newCosts);
    return true;
}
Also used : Player(mage.players.Player) CostsImpl(mage.abilities.costs.CostsImpl) PayLifeCost(mage.abilities.costs.common.PayLifeCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Cost(mage.abilities.costs.Cost)

Example 4 with CostsImpl

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

the class CumulativeUpkeepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player != null && permanent != null) {
        int ageCounter = permanent.getCounters(game).getCount(CounterType.AGE);
        if (cumulativeCost instanceof ManaCost) {
            ManaCostsImpl totalCost = new ManaCostsImpl<>();
            for (int i = 0; i < ageCounter; i++) {
                totalCost.add((ManaCost) cumulativeCost.copy());
            }
            if (player.chooseUse(Outcome.Benefit, "Pay " + totalCost.getText() + '?', source, game)) {
                totalCost.clearPaid();
                if (totalCost.payOrRollback(source, game, source, source.getControllerId())) {
                    game.fireEvent(new ManaEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), totalCost.getUsedManaToPay()));
                    return true;
                }
            }
            game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
            if (source.getControllerId().equals(permanent.getControllerId())) {
                // Permanent can only be sacrificed if you still control it
                permanent.sacrifice(source, game);
            }
            return true;
        } else {
            CostsImpl<Cost> totalCost = new CostsImpl<>();
            for (int i = 0; i < ageCounter; i++) {
                totalCost.add(cumulativeCost.copy());
            }
            if (player.chooseUse(Outcome.Benefit, totalCost.getText() + '?', source, game)) {
                totalCost.clearPaid();
                int bookmark = game.bookmarkState();
                if (totalCost.pay(source, game, source, source.getControllerId(), false, null)) {
                    game.fireEvent(new GameEvent(GameEvent.EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
                    return true;
                } else {
                    player.restoreState(bookmark, source.getRule(), game);
                }
            }
            game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
            permanent.sacrifice(source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCost(mage.abilities.costs.mana.ManaCost) CostsImpl(mage.abilities.costs.CostsImpl) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GameEvent(mage.game.events.GameEvent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ManaEvent(mage.game.events.ManaEvent) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost) OrCost(mage.abilities.costs.OrCost)

Example 5 with CostsImpl

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

the class BolassCitadelPlayTheTopCardEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    // current card's part
    Card cardToCheck = game.getCard(objectId);
    if (cardToCheck == null) {
        return false;
    }
    // must be you
    if (!affectedControllerId.equals(source.getControllerId())) {
        return false;
    }
    // must be your card
    Player player = game.getPlayer(cardToCheck.getOwnerId());
    if (player == null || !player.getId().equals(affectedControllerId)) {
        return false;
    }
    // must be from your library
    Card topCard = player.getLibrary().getFromTop(game);
    if (topCard == null || !topCard.getId().equals(cardToCheck.getMainCard().getId())) {
        return false;
    }
    // allows to play/cast with alternative life cost
    if (!cardToCheck.isLand(game)) {
        PayLifeCost lifeCost = new PayLifeCost(cardToCheck.getSpellAbility().getManaCosts().manaValue());
        Costs newCosts = new CostsImpl();
        newCosts.add(lifeCost);
        newCosts.addAll(cardToCheck.getSpellAbility().getCosts());
        player.setCastSourceIdWithAlternateMana(cardToCheck.getId(), null, newCosts);
    }
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) CostsImpl(mage.abilities.costs.CostsImpl) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Card(mage.cards.Card)

Aggregations

CostsImpl (mage.abilities.costs.CostsImpl)6 Player (mage.players.Player)6 Cost (mage.abilities.costs.Cost)5 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)4 PayLifeCost (mage.abilities.costs.common.PayLifeCost)3 Costs (mage.abilities.costs.Costs)1 OrCost (mage.abilities.costs.OrCost)1 DiscardCardCost (mage.abilities.costs.common.DiscardCardCost)1 ExileFromGraveCost (mage.abilities.costs.common.ExileFromGraveCost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 Card (mage.cards.Card)1 GameEvent (mage.game.events.GameEvent)1 ManaEvent (mage.game.events.ManaEvent)1 Permanent (mage.game.permanent.Permanent)1 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1