Search in sources :

Example 26 with ManaCostsImpl

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

the class ManaUtilTest method testManaReduction.

/**
 * Checks if a given mana reduction left the expected amount of mana costs
 *
 * @param manaCostsToPay
 * @param availablyAny
 * @param available
 * @param expected
 */
private void testManaReduction(String manaCostsToPay, String manaToReduce, String restMana) {
    SpellAbility spellAbility = new SpellAbility(new ManaCostsImpl(manaCostsToPay), "Test");
    CardUtil.adjustCost(spellAbility, new ManaCostsImpl(manaToReduce), true);
    Assert.assertTrue("The mana cost to pay " + manaCostsToPay + " reduced by " + manaToReduce + " should left " + restMana + " but the rest was " + spellAbility.getManaCostsToPay().getText(), spellAbility.getManaCostsToPay().getText().equals(restMana));
}
Also used : SpellAbility(mage.abilities.SpellAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 27 with ManaCostsImpl

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

the class StriveCostIncreasingEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    for (Target target : abilityToModify.getTargets()) {
        if (target.getMaxNumberOfTargets() == Integer.MAX_VALUE) {
            // strive works with "any number of target" only
            int additionalTargets = target.getTargets().size() - 1;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < additionalTargets; i++) {
                // Build up a string of strive costs for each target
                sb.append(striveCosts.getText());
            }
            String finalCost = ManaUtil.condenseManaCostString(sb.toString());
            abilityToModify.getManaCostsToPay().add(new ManaCostsImpl(finalCost));
            return true;
        }
    }
    return false;
}
Also used : Target(mage.target.Target) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 28 with ManaCostsImpl

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

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

the class DashAddDelayedTriggeredAbilityEffect method addDashCost.

public final AlternativeCost2 addDashCost(String manaString) {
    AlternativeCost2 evokeCost = new AlternativeCost2Impl(KEYWORD, REMINDER_TEXT, new ManaCostsImpl(manaString));
    alternativeSourceCosts.add(evokeCost);
    return evokeCost;
}
Also used : ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 30 with ManaCostsImpl

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

the class ConspireTriggeredAbility method addOptionalAdditionalCosts.

@Override
public void addOptionalAdditionalCosts(Ability ability, Game game) {
    if (!(ability instanceof SpellAbility)) {
        return;
    }
    Player player = game.getPlayer(getControllerId());
    if (player == null) {
        return;
    }
    // AI supports conspire
    if (!conspireCost.canPay(ability, this, getControllerId(), game) || !player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
        return;
    }
    ability.getEffects().setValue("ConspireActivation" + conspireId + addedById, true);
    for (Iterator<Cost> it = ((Costs<Cost>) conspireCost).iterator(); it.hasNext(); ) {
        Cost cost = (Cost) it.next();
        if (cost instanceof ManaCostsImpl) {
            ability.getManaCostsToPay().add((ManaCostsImpl<?>) cost.copy());
        } else {
            ability.getCosts().add(cost.copy());
        }
    }
}
Also used : Player(mage.players.Player) SpellAbility(mage.abilities.SpellAbility) TapTargetCost(mage.abilities.costs.common.TapTargetCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

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