Search in sources :

Example 6 with Cost

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

the class RescueFromTheUnderworldReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    DelayedTriggeredAbility delayedAbility = ability.copy();
    delayedAbility.getTargets().addAll(source.getTargets());
    for (Effect effect : delayedAbility.getEffects()) {
        effect.getTargetPointer().init(game, source);
    }
    // add the sacrificed creature as target
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
            TargetCardInGraveyard target = new TargetCardInGraveyard();
            for (Permanent permanent : sacCost.getPermanents()) {
                target.add(permanent.getId(), game);
                delayedAbility.getTargets().add(target);
            }
        }
    }
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) Effect(mage.abilities.effects.Effect) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 7 with Cost

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

the class TezzeretTheSeekerEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof PayVariableLoyaltyCost) {
            cmc = ((PayVariableLoyaltyCost) cost).getAmount();
        }
    }
    FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) FilterArtifactCard(mage.filter.common.FilterArtifactCard) Cost(mage.abilities.costs.Cost) PayVariableLoyaltyCost(mage.abilities.costs.common.PayVariableLoyaltyCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 8 with Cost

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

the class TetravusPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (player == null || permanent == null) {
        return false;
    }
    int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1);
    if (countersToRemove == 0) {
        return false;
    }
    countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game);
    Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove));
    if (cost.pay(source, game, source, source.getControllerId(), true)) {
        CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove);
        effect.apply(game, source);
        Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
        Set<UUID> tokensCreated;
        if (object != null) {
            tokensCreated = (Set<UUID>) object;
        } else {
            tokensCreated = new HashSet<>();
        }
        for (UUID tokenId : effect.getLastAddedTokenIds()) {
            if (tokenId != null) {
                tokensCreated.add(tokenId);
            }
        }
        game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
    }
    return false;
}
Also used : Player(mage.players.Player) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) TetraviteToken(mage.game.permanent.token.TetraviteToken) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ExileTargetCost(mage.abilities.costs.common.ExileTargetCost) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost)

Example 9 with Cost

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

the class TransmuteArtifactEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // Sacrifice an artifact.
    int manaValue = 0;
    boolean sacrifice = false;
    TargetControlledPermanent targetArtifact = new TargetControlledPermanent(new FilterControlledArtifactPermanent());
    if (controller.chooseTarget(Outcome.Sacrifice, targetArtifact, source, game)) {
        Permanent permanent = game.getPermanent(targetArtifact.getFirstTarget());
        if (permanent != null) {
            manaValue = permanent.getManaValue();
            sacrifice = permanent.sacrifice(source, game);
        }
    } else {
        return true;
    }
    // If you do, search your library for an artifact card.
    if (sacrifice && controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                if (card != null) {
                    // If that card's converted mana cost is less than or equal to the sacrificed artifact's converted mana cost, put it onto the battlefield.
                    if (card.getManaValue() <= manaValue) {
                        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                    } else {
                        // If it's greater, you may pay {X}, where X is the difference. If you do, put it onto the battlefield.
                        Cost cost = ManaUtil.createManaCost(card.getManaValue() - manaValue, true);
                        boolean payed = false;
                        if (controller.chooseUse(Outcome.Benefit, "Do you want to pay " + cost.getText() + " to put it onto the battlefield?", source, game) && cost.pay(source, game, source, source.getControllerId(), false)) {
                            payed = true;
                        }
                        if (payed) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
                        } else {
                            // If you don't, put it into its owner's graveyard. Then shuffle your library
                            controller.moveCards(card, Zone.GRAVEYARD, source, game);
                        }
                    }
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Card(mage.cards.Card) FilterArtifactCard(mage.filter.common.FilterArtifactCard)

Example 10 with Cost

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

the class UrzasTomeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    new DrawCardSourceControllerEffect(1).apply(game, source);
    if (controller != null && controller.chooseUse(Outcome.Exile, "Exile a historic card from your graveyard?", source, game)) {
        Cost cost = new ExileFromGraveCost(new TargetCardInYourGraveyard(new FilterHistoricCard()));
        if (cost.canPay(source, source, controller.getId(), game)) {
            if (cost.pay(source, game, source, controller.getId(), false, null)) {
                return true;
            }
        }
    }
    if (controller != null) {
        controller.discard(1, false, false, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterHistoricCard(mage.filter.common.FilterHistoricCard) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost)

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