Search in sources :

Example 6 with ManaCost

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

the class ManaUtilTest method testManaAvailEnough.

/**
 * Checks if the given available Mana is enough to pay a given mana cost
 *
 * @param manaCostsToPay
 * @param availablyAny
 * @param available
 * @param expected
 */
private void testManaAvailEnough(String manaCostsToPay, int availablyAny, String available, boolean expected) {
    ManaCost unpaid = new ManaCostsImpl(manaCostsToPay);
    ManaCost costAvailable = new ManaCostsImpl(available);
    Mana manaAvailable = costAvailable.getMana();
    manaAvailable.setAny(availablyAny);
    if (expected) {
        Assert.assertTrue("The available Mana " + costAvailable.getText() + " should be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
    } else {
        Assert.assertFalse("The available Mana " + costAvailable.getText() + " shouldn't be enough to pay the costs " + unpaid.getText(), unpaid.getMana().enough(manaAvailable));
    }
}
Also used : Mana(mage.Mana) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 7 with ManaCost

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

the class ManaUtilTest method testManaToPayVsLand.

/**
 * Another way to test ManaUtil.tryToAutoPay Here we also check what ability
 * was auto chosen
 *
 * N.B. This method can be used ONLY if we have one ability left that auto
 * choose mode! That's why we assert the following: Assert.assertEquals(1,
 * useableAbilities.size());
 *
 * 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 expectedChosen
 */
private void testManaToPayVsLand(String manaToPay, String landName, int expected1, Class<? extends BasicManaAbility> expectedChosen) {
    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(1, useableAbilities.size());
    ActivatedManaAbilityImpl ability = useableAbilities.values().iterator().next();
    Assert.assertTrue("Wrong mana ability has been chosen", expectedChosen.isInstance(ability));
}
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 8 with ManaCost

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

the class SpellAbility method getConvertedXManaCost.

public int getConvertedXManaCost(Card card) {
    int xMultiplier = 0;
    int amount = 0;
    if (card == null) {
        return 0;
    }
    // mana cost instances
    for (ManaCost manaCost : card.getManaCost()) {
        if (manaCost instanceof VariableManaCost) {
            xMultiplier = ((VariableManaCost) manaCost).getXInstancesCount();
            break;
        }
    }
    // mana cost final X value
    boolean hasNonManaXCost = false;
    for (Cost cost : getCosts()) {
        if (cost instanceof VariableCost) {
            hasNonManaXCost = true;
            amount = ((VariableCost) cost).getAmount();
            break;
        }
    }
    if (!hasNonManaXCost) {
        amount = getManaCostsToPay().getX();
    }
    return amount * xMultiplier;
}
Also used : VariableCost(mage.abilities.costs.VariableCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) Cost(mage.abilities.costs.Cost) VariableCost(mage.abilities.costs.VariableCost) ManaCost(mage.abilities.costs.mana.ManaCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Example 9 with ManaCost

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

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

the class PowerLeakEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
    String message = "Pay {X} to prevent X damage from " + permanent.getLogName() + "?";
    int xValue = 0;
    if (player.chooseUse(Outcome.Neutral, message, source, game)) {
        xValue = player.announceXMana(0, Integer.MAX_VALUE, "Choose the amount of mana to pay", game, source);
        cost.add(new GenericManaCost(xValue));
        if (cost.pay(source, game, source, player.getId(), false, null)) {
            game.informPlayers(player.getLogName() + " paid {" + xValue + "} for " + permanent.getLogName());
        } else {
            game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
        }
    } else {
        game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
    }
    PreventDamageByTargetEffect effect = new PreventDamageByTargetEffect(Duration.OneUse, xValue, false);
    if (xValue != 0 && cost.isPaid()) {
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    }
    player.damage(2, source.getSourceId(), source, game);
    effect.discard();
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) TargetEnchantmentPermanent(mage.target.common.TargetEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

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