Search in sources :

Example 86 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class ThelonsCurseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
        while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.AIDontUseIt, "Pay {U} and untap a tapped blue creature under your control?", source, game)) {
            Target tappedCreatureTarget = new TargetControlledCreaturePermanent(1, 1, filter, true);
            if (player.choose(Outcome.Detriment, tappedCreatureTarget, source.getSourceId(), game)) {
                Cost cost = new ManaCostsImpl("U");
                Permanent tappedCreature = game.getPermanent(tappedCreatureTarget.getFirstTarget());
                if (cost.pay(source, game, source, player.getId(), false)) {
                    tappedCreature.untap(game);
                }
            }
            countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game).size();
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 87 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class VarolzTheScarStripedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID cardId : controller.getGraveyard()) {
            Card card = game.getCard(cardId);
            if (card != null && card.isCreature(game)) {
                ScavengeAbility ability = new ScavengeAbility(new ManaCostsImpl(card.getManaCost().getText()));
                ability.setSourceId(cardId);
                ability.setControllerId(card.getOwnerId());
                game.getState().addOtherAbility(card, ability);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) ScavengeAbility(mage.abilities.keyword.ScavengeAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card)

Example 88 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class ReplicateCopyEffect method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (ability instanceof SpellAbility) {
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            this.resetReplicate();
            boolean again = true;
            while (player.canRespond() && again) {
                String times = "";
                if (additionalCost.isRepeatable()) {
                    int numActivations = additionalCost.getActivateCount();
                    times = (numActivations + 1) + (numActivations == 0 ? " time " : " times ");
                }
                // canPay checks only single mana available, not total mana usage
                if (additionalCost.canPay(ability, this, ability.getControllerId(), game) && player.chooseUse(/*Outcome.Benefit*/
                Outcome.AIDontUseIt, new StringBuilder("Pay ").append(times).append(additionalCost.getText(false)).append(" ?").toString(), ability, game)) {
                    additionalCost.activate();
                    for (Iterator it = ((Costs) additionalCost).iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCostsImpl) {
                            ability.getManaCostsToPay().add((ManaCostsImpl) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                } else {
                    again = false;
                }
            }
        }
    }
}
Also used : Player(mage.players.Player) Iterator(java.util.Iterator) SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 89 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class PlayerImpl method canPlayCardByAlternateCost.

protected boolean canPlayCardByAlternateCost(Card sourceObject, ManaOptions availableMana, Ability ability, Game game) {
    if (sourceObject != null && !(sourceObject instanceof Permanent)) {
        // for alternative cost and reduce tries
        Ability copyAbility;
        for (Ability alternateSourceCostsAbility : sourceObject.getAbilities()) {
            // if cast for noMana no Alternative costs are allowed
            if (alternateSourceCostsAbility instanceof AlternativeSourceCosts) {
                if (((AlternativeSourceCosts) alternateSourceCostsAbility).isAvailable(ability, game)) {
                    if (alternateSourceCostsAbility.getCosts().canPay(ability, ability, playerId, game)) {
                        ManaCostsImpl manaCosts = new ManaCostsImpl();
                        for (Cost cost : alternateSourceCostsAbility.getCosts()) {
                            // AlternativeCost2 replaced by real cost on activate, so getPlayable need to extract that costs here
                            if (cost instanceof AlternativeCost2) {
                                if (((AlternativeCost2) cost).getCost() instanceof ManaCost) {
                                    manaCosts.add((ManaCost) ((AlternativeCost2) cost).getCost());
                                }
                            } else {
                                if (cost instanceof ManaCost) {
                                    manaCosts.add((ManaCost) cost);
                                }
                            }
                        }
                        if (manaCosts.isEmpty()) {
                            return true;
                        } else {
                            if (availableMana == null) {
                                return true;
                            }
                            // alternative cost reduce
                            copyAbility = ability.copy();
                            copyAbility.getManaCostsToPay().clear();
                            copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
                            sourceObject.adjustCosts(copyAbility, game);
                            game.getContinuousEffects().costModification(copyAbility, game);
                            // reduced all cost
                            if (copyAbility.getManaCostsToPay().isEmpty()) {
                                return true;
                            }
                            for (Mana mana : copyAbility.getManaCostsToPay().getOptions()) {
                                if (availableMana.enough(mana)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
        // controller specific alternate spell costs
        for (AlternativeSourceCosts alternateSourceCosts : getAlternativeSourceCosts()) {
            if (alternateSourceCosts instanceof Ability) {
                if (alternateSourceCosts.isAvailable(ability, game)) {
                    if (((Ability) alternateSourceCosts).getCosts().canPay(ability, ability, playerId, game)) {
                        ManaCostsImpl manaCosts = new ManaCostsImpl();
                        for (Cost cost : ((Ability) alternateSourceCosts).getCosts()) {
                            // AlternativeCost2 replaced by real cost on activate, so getPlayable need to extract that costs here
                            if (cost instanceof AlternativeCost2) {
                                if (((AlternativeCost2) cost).getCost() instanceof ManaCost) {
                                    manaCosts.add((ManaCost) ((AlternativeCost2) cost).getCost());
                                }
                            } else {
                                if (cost instanceof ManaCost) {
                                    manaCosts.add((ManaCost) cost);
                                }
                            }
                        }
                        if (manaCosts.isEmpty()) {
                            return true;
                        } else {
                            if (availableMana == null) {
                                return true;
                            }
                            // alternative cost reduce
                            copyAbility = ability.copy();
                            copyAbility.getManaCostsToPay().clear();
                            copyAbility.getManaCostsToPay().addAll(manaCosts.copy());
                            sourceObject.adjustCosts(copyAbility, game);
                            game.getContinuousEffects().costModification(copyAbility, game);
                            // reduced all cost
                            if (copyAbility.getManaCostsToPay().isEmpty()) {
                                return true;
                            }
                            for (Mana mana : copyAbility.getManaCostsToPay().getOptions()) {
                                if (availableMana.enough(mana)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : AlternateManaPaymentAbility(mage.abilities.costs.mana.AlternateManaPaymentAbility) StackAbility(mage.game.stack.StackAbility) WhileSearchingPlayFromLibraryAbility(mage.abilities.common.WhileSearchingPlayFromLibraryAbility) AtTheEndOfTurnStepPostDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility) PassAbility(mage.abilities.common.PassAbility) PlayLandAsCommanderAbility(mage.abilities.common.PlayLandAsCommanderAbility) FilterMana(mage.filter.FilterMana) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 90 with ManaCostsImpl

use of mage.abilities.costs.mana.ManaCostsImpl in project mage by magefree.

the class SimulatedPlayer2 method addVariableXOptions.

@Override
protected void addVariableXOptions(List<Ability> options, Ability ability, int targetNum, Game game) {
    // calculate the mana that can be used for the x part
    int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
    Card card = game.getCard(ability.getSourceId());
    if (card != null && numAvailable > 0) {
        // check if variable mana costs is included and get the multiplier
        VariableManaCost variableManaCost = null;
        for (ManaCost cost : ability.getManaCostsToPay()) {
            if (cost instanceof VariableManaCost && !cost.isPaid()) {
                variableManaCost = (VariableManaCost) cost;
                // only one VariableManCost per spell (or is it possible to have more?)
                break;
            }
        }
        if (variableManaCost != null) {
            int xInstancesCount = variableManaCost.getXInstancesCount();
            for (int mana = variableManaCost.getMinX(); mana <= numAvailable; mana++) {
                if (mana % xInstancesCount == 0) {
                    // use only values dependant from multiplier
                    // find possible X value to pay
                    int xAnnounceValue = mana / xInstancesCount;
                    Ability newAbility = ability.copy();
                    VariableManaCost varCost = null;
                    for (ManaCost cost : newAbility.getManaCostsToPay()) {
                        if (cost instanceof VariableManaCost && !cost.isPaid()) {
                            varCost = (VariableManaCost) cost;
                            // only one VariableManCost per spell (or is it possible to have more?)
                            break;
                        }
                    }
                    // find real X value after replace events
                    int xMultiplier = 1;
                    if (newAbility instanceof AbilityImpl) {
                        xMultiplier = ((AbilityImpl) newAbility).handleManaXMultiplier(game, xMultiplier);
                    }
                    newAbility.getManaCostsToPay().add(new ManaCostsImpl(new StringBuilder("{").append(xAnnounceValue).append('}').toString()));
                    newAbility.getManaCostsToPay().setX(xAnnounceValue * xMultiplier, xAnnounceValue * xInstancesCount);
                    if (varCost != null) {
                        varCost.setPaid();
                    }
                    card.adjustTargets(newAbility, game);
                    // add the different possible target option for the specific X value
                    if (!newAbility.getTargets().getUnchosen().isEmpty()) {
                        addTargetOptions(options, newAbility, targetNum, game);
                    }
                }
            }
        }
    }
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) AbilityImpl(mage.abilities.AbilityImpl) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Aggregations

ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)98 Player (mage.players.Player)63 Permanent (mage.game.permanent.Permanent)33 Ability (mage.abilities.Ability)26 Cost (mage.abilities.costs.Cost)26 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)23 UUID (java.util.UUID)16 Card (mage.cards.Card)16 ManaCosts (mage.abilities.costs.mana.ManaCosts)15 SpellAbility (mage.abilities.SpellAbility)14 FixedTarget (mage.target.targetpointer.FixedTarget)13 Test (org.junit.Test)13 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)12 ManaCost (mage.abilities.costs.mana.ManaCost)11 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)7 TargetPermanent (mage.target.TargetPermanent)7 MageObjectReference (mage.MageObjectReference)6 Effect (mage.abilities.effects.Effect)6 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)6