Search in sources :

Example 1 with Costs

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

the class WolfOfDevilsBreachDiscardCostCardConvertedManaCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    for (Effect sourceEffect : sourceAbility.getEffects()) {
        if (sourceEffect instanceof DoIfCostPaid) {
            Cost doCosts = ((DoIfCostPaid) sourceEffect).getCost();
            if (doCosts instanceof Costs) {
                Costs costs = (Costs) doCosts;
                for (Object cost : costs) {
                    if (cost instanceof DiscardCardCost) {
                        DiscardCardCost discardCost = (DiscardCardCost) cost;
                        int cmc = 0;
                        for (Card card : discardCost.getCards()) {
                            cmc += card.getManaValue();
                        }
                        return cmc;
                    }
                }
            }
        }
    }
    return 0;
}
Also used : DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Costs(mage.abilities.costs.Costs) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) DiscardCardCost(mage.abilities.costs.common.DiscardCardCost) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card)

Example 2 with Costs

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

the class JourneyToTheOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    controller.revealCards(source, new CardsImpl(card), game);
    if (card.isLand(game)) {
        // note that MDFC land cards are handled differently: they can't be moved
        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    // query player
    if (!controller.chooseUse(outcome, "Cast " + card.getName() + " by paying {1}?", source, game)) {
        return false;
    }
    // handle split-cards
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        // get additional cost if any
        Costs additionalCostsLeft = leftHalfCard.getSpellAbility().getCosts();
        Costs additionalCostsRight = rightHalfCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsLeft);
        controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsRight);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle MDFC
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        // some MDFC cards are lands.  IE: sea gate restoration
        if (!leftHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCLeft = leftHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(leftHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCLeft);
        }
        if (!rightHalfCard.isLand(game)) {
            // get additional cost if any
            Costs additionalCostsMDFCRight = rightHalfCard.getSpellAbility().getCosts();
            // set alternative cost and any additional cost
            controller.setCastSourceIdWithAlternateMana(rightHalfCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsMDFCRight);
        }
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), Boolean.TRUE);
    }
    // handle adventure cards
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        // get additional cost if any
        Costs additionalCostsCreature = creatureCard.getSpellAbility().getCosts();
        Costs additionalCostsSpellCard = spellCard.getSpellAbility().getCosts();
        // set alternative cost and any additional cost
        controller.setCastSourceIdWithAlternateMana(creatureCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsCreature);
        controller.setCastSourceIdWithAlternateMana(spellCard.getId(), new ManaCostsImpl<>("{1}"), additionalCostsSpellCard);
        // allow the card to be cast
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), Boolean.TRUE);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), Boolean.TRUE);
    }
    // normal card
    if (!(card instanceof SplitCard) || !(card instanceof ModalDoubleFacesCard) || !(card instanceof AdventureCard)) {
        // get additional cost if any
        Costs additionalCostsNormalCard = card.getSpellAbility().getCosts();
        controller.setCastSourceIdWithAlternateMana(card.getMainCard().getId(), new ManaCostsImpl<>("{1}"), additionalCostsNormalCard);
    }
    // cast it
    controller.cast(controller.chooseAbilityForCast(card.getMainCard(), game, false), game, false, new ApprovingObject(source, game));
    // turn off effect after cast on every possible card-face
    if (card instanceof SplitCard) {
        SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
        SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof ModalDoubleFacesCard) {
        ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
        ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + leftHalfCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + rightHalfCard.getId(), null);
    }
    if (card instanceof AdventureCard) {
        Card creatureCard = card.getMainCard();
        Card spellCard = ((AdventureCard) card).getSpellCard();
        game.getState().setValue("PlayFromNotOwnHandZone" + creatureCard.getId(), null);
        game.getState().setValue("PlayFromNotOwnHandZone" + spellCard.getId(), null);
    }
    // turn off effect on a normal card
    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ApprovingObject(mage.ApprovingObject) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) CardsImpl(mage.cards.CardsImpl) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

Example 3 with Costs

use of mage.abilities.costs.Costs 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)

Example 4 with Costs

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

the class YidaroWanderingMonsterWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Costs<Cost> costs = (Costs) this.getValue("cycleCosts");
    if (costs == null) {
        return false;
    }
    MageObjectReference cycledCard = costs.stream().filter(CyclingDiscardCost.class::isInstance).map(CyclingDiscardCost.class::cast).map(CyclingDiscardCost::getCycledCard).findFirst().orElse(null);
    if (cycledCard == null || game.getState().getZone(cycledCard.getSourceId()) != Zone.GRAVEYARD) {
        return false;
    }
    Card card = cycledCard.getCard(game);
    if (card == null) {
        return false;
    }
    YidaroWanderingMonsterWatcher watcher = game.getState().getWatcher(YidaroWanderingMonsterWatcher.class);
    if (watcher == null || watcher.getYidaroCount(player.getId()) < 4) {
        player.putCardsOnBottomOfLibrary(card, game, source, true);
        player.shuffleLibrary(source, game);
    } else {
        player.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Costs(mage.abilities.costs.Costs) Cost(mage.abilities.costs.Cost) CyclingDiscardCost(mage.abilities.costs.common.CyclingDiscardCost) MageObjectReference(mage.MageObjectReference) CyclingDiscardCost(mage.abilities.costs.common.CyclingDiscardCost) Card(mage.cards.Card)

Aggregations

Costs (mage.abilities.costs.Costs)4 Card (mage.cards.Card)4 Player (mage.players.Player)3 Cost (mage.abilities.costs.Cost)2 ApprovingObject (mage.ApprovingObject)1 MageObjectReference (mage.MageObjectReference)1 CostsImpl (mage.abilities.costs.CostsImpl)1 CyclingDiscardCost (mage.abilities.costs.common.CyclingDiscardCost)1 DiscardCardCost (mage.abilities.costs.common.DiscardCardCost)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 Effect (mage.abilities.effects.Effect)1 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)1 DoIfCostPaid (mage.abilities.effects.common.DoIfCostPaid)1 AdventureCard (mage.cards.AdventureCard)1 CardsImpl (mage.cards.CardsImpl)1 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)1 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)1 SplitCard (mage.cards.SplitCard)1 SplitCardHalf (mage.cards.SplitCardHalf)1