Search in sources :

Example 21 with ManaCost

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

the class ManaUtilTest method testManaToPayVsLand.

/**
 * Common way to test ManaUtil.tryToAutoPay
 *
 * We get all mana abilities, then try to auto pay and compare to expected1
 * and expected2 params.
 *
 * @param manaToPay Mana that should be paid using land.
 * @param landName Land to use as mana producer.
 * @param expected1 The amount of mana abilities the land should have.
 * @param expected2 The amount of mana abilities that ManaUtil.tryToAutoPay
 * should be returned after optimization.
 */
private void testManaToPayVsLand(String manaToPay, String landName, int expected1, int expected2) {
    ManaCost unpaid = new ManaCostsImpl(manaToPay);
    Card card = CardRepository.instance.findCard(landName).getCard();
    Assert.assertNotNull(card);
    Map<UUID, ActivatedManaAbilityImpl> useableAbilities = getManaAbilities(card);
    Assert.assertEquals(expected1, useableAbilities.size());
    useableAbilities = ManaUtil.tryToAutoPay(unpaid, (LinkedHashMap<UUID, ActivatedManaAbilityImpl>) useableAbilities);
    Assert.assertEquals(expected2, useableAbilities.size());
}
Also used : ManaCost(mage.abilities.costs.mana.ManaCost) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with ManaCost

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

the class MadnessCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    Player owner = game.getPlayer(card.getOwnerId());
    if (owner == null) {
        return false;
    }
    // Replace with the new cost
    SpellAbility castByMadness = card.getSpellAbility().copy();
    ManaCosts<ManaCost> costRef = castByMadness.getManaCostsToPay();
    castByMadness.setSpellAbilityType(SpellAbilityType.BASE_ALTERNATE);
    castByMadness.setSpellAbilityCastMode(SpellAbilityCastMode.MADNESS);
    castByMadness.getCosts().clear();
    castByMadness.addCost(new PayLifeCost(this.lifeCost));
    costRef.clear();
    costRef.add(madnessCost);
    return owner.cast(castByMadness, game, false, new ApprovingObject(source, game));
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ManaCost(mage.abilities.costs.mana.ManaCost) PayLifeCost(mage.abilities.costs.common.PayLifeCost) Card(mage.cards.Card)

Example 23 with ManaCost

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

the class MorphAbility method askToActivateAlternativeCosts.

@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
    if (ability.getAbilityType() == AbilityType.SPELL) {
        Player player = game.getPlayer(ability.getControllerId());
        Spell spell = game.getStack().getSpell(ability.getId());
        if (player != null && spell != null) {
            this.resetMorph();
            // so only the back is visible
            spell.setFaceDown(true, game);
            if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
                if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
                    game.getState().setValue("MorphAbility" + ability.getSourceId(), // Gift of Doom
                    "activated");
                    activateMorph(game);
                    // change mana costs
                    ability.getManaCostsToPay().clear();
                    ability.getCosts().clear();
                    for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                    // change spell colors and subtype *TODO probably this needs to be done by continuous effect (while on the stack)
                    ObjectColor spellColor = spell.getColor(game);
                    spellColor.setBlack(false);
                    spellColor.setRed(false);
                    spellColor.setGreen(false);
                    spellColor.setWhite(false);
                    spellColor.setBlue(false);
                    game.getState().getCreateMageObjectAttribute(spell.getCard(), game).getSubtype().clear();
                } else {
                    spell.setFaceDown(false, game);
                }
            }
        }
    }
    if (ability.getAbilityType() == AbilityType.PLAY_LAND) {
        Player player = game.getPlayer(ability.getControllerId());
        if (player != null) {
            this.resetMorph();
            if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
                if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
                    activateMorph(game);
                    // change mana costs
                    ability.getManaCostsToPay().clear();
                    ability.getCosts().clear();
                    for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
                        Cost cost = (Cost) it.next();
                        if (cost instanceof ManaCost) {
                            ability.getManaCostsToPay().add((ManaCost) cost.copy());
                        } else {
                            ability.getCosts().add(cost.copy());
                        }
                    }
                }
            }
        }
    }
    return isActivated(ability, game);
}
Also used : Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) Iterator(java.util.Iterator) ObjectColor(mage.ObjectColor) Cost(mage.abilities.costs.Cost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) Spell(mage.game.stack.Spell)

Example 24 with ManaCost

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

the class MiracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    // use target pointer here, so it's the same card that triggered the event (not gone back to library e.g.)
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller != null && card != null) {
        SpellAbility abilityToCast = card.getSpellAbility().copy();
        ManaCosts<ManaCost> costRef = abilityToCast.getManaCostsToPay();
        // replace with the new cost
        costRef.clear();
        costRef.add(miracleCosts);
        controller.cast(abilityToCast, game, false, new ApprovingObject(source, game));
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) ManaCost(mage.abilities.costs.mana.ManaCost) SpellAbility(mage.abilities.SpellAbility) Card(mage.cards.Card)

Example 25 with ManaCost

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

Aggregations

ManaCost (mage.abilities.costs.mana.ManaCost)26 Player (mage.players.Player)16 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)11 Permanent (mage.game.permanent.Permanent)9 Card (mage.cards.Card)8 Cost (mage.abilities.costs.Cost)6 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)6 UUID (java.util.UUID)4 Ability (mage.abilities.Ability)4 VariableManaCost (mage.abilities.costs.mana.VariableManaCost)4 TargetPermanent (mage.target.TargetPermanent)4 ArrayList (java.util.ArrayList)3 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)3 FilterPermanent (mage.filter.FilterPermanent)3 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ApprovingObject (mage.ApprovingObject)2 Mana (mage.Mana)2 ObjectColor (mage.ObjectColor)2