Search in sources :

Example 1 with ManaCost

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

the class RemnantOfTheRisingStarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
    if (player == null || !player.chooseUse(Outcome.BoostCreature, "Pay " + cost.getText() + "?", source, game)) {
        return false;
    }
    int xValue = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
    cost.add(new GenericManaCost(xValue));
    if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
        return false;
    }
    Permanent permanent = (Permanent) getValue("permanentEnteringBattlefield");
    if (permanent == null) {
        return false;
    }
    game.fireReflexiveTriggeredAbility(new ReflexiveTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance(xValue)).setTargetPointer(new FixedTarget(permanent, game)), false), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) Hint(mage.abilities.hint.Hint) ValueHint(mage.abilities.hint.ValueHint)

Example 2 with ManaCost

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

the class OrCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    selectedCost = null;
    // if only one can be paid select it
    if (!firstCost.canPay(ability, source, controllerId, game)) {
        selectedCost = secondCost;
    }
    if (!secondCost.canPay(ability, source, controllerId, game)) {
        selectedCost = firstCost;
    }
    // if both can be paid player has to select
    if (selectedCost == null) {
        Player controller = game.getPlayer(controllerId);
        if (controller != null) {
            StringBuilder sb = new StringBuilder();
            if (firstCost instanceof ManaCost) {
                sb.append("Pay ");
            }
            sb.append(firstCost.getText()).append('?');
            if (controller.chooseUse(Outcome.Detriment, sb.toString(), ability, game)) {
                selectedCost = firstCost;
            } else {
                selectedCost = secondCost;
            }
        }
    }
    if (selectedCost == null) {
        return false;
    }
    return selectedCost.pay(ability, game, source, controllerId, noMana, costToPay);
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 3 with ManaCost

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

the class OfferingCostReductionEffect method getManaOptions.

@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
    ManaOptions additionalManaOptionsForThisAbility = new ManaOptions();
    // Creatures from the offerd type
    game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game).stream().map(Card::getSpellAbility).filter(Objects::nonNull).forEach(spellAbility -> {
        ManaOptions manaOptionsForThisPermanent = new ManaOptions();
        for (ManaCost manaCost : spellAbility.getManaCosts()) {
            if (manaCost instanceof HybridManaCost) {
                ManaOptions manaOptionsForHybrid = new ManaOptions();
                manaOptionsForHybrid.addAll(manaCost.getManaOptions());
                manaOptionsForThisPermanent.addMana(manaOptionsForHybrid);
            } else {
                manaOptionsForThisPermanent.addMana(manaCost.getMana());
            }
        }
        additionalManaOptionsForThisAbility.addAll(manaOptionsForThisPermanent);
    });
    additionalManaOptionsForThisAbility.removeDuplicated();
    return additionalManaOptionsForThisAbility;
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) HybridManaCost(mage.abilities.costs.mana.HybridManaCost) HybridManaCost(mage.abilities.costs.mana.HybridManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) Card(mage.cards.Card)

Example 4 with ManaCost

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

the class CounterUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
    if (spell == null) {
        return false;
    }
    Player player = game.getPlayer(spell.getControllerId());
    if (player == null) {
        return false;
    }
    Cost costToPay;
    String costValueMessage;
    if (cost != null) {
        costToPay = cost.copy();
        costValueMessage = costToPay.getText();
    } else {
        costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
        costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
    }
    String message = "";
    if (costToPay instanceof ManaCost) {
        message += "Pay ";
    }
    message += costValueMessage + '?';
    costToPay.clearPaid();
    if (!(player.chooseUse(Outcome.Benefit, message, source, game) && costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
        game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
        if (exile) {
            game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
        } else {
            return game.getStack().counter(spell.getId(), source, game);
        }
    }
    game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
    return true;
}
Also used : Player(mage.players.Player) ManaCost(mage.abilities.costs.mana.ManaCost) StackObject(mage.game.stack.StackObject) Cost(mage.abilities.costs.Cost) ManaCost(mage.abilities.costs.mana.ManaCost)

Example 5 with ManaCost

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

the class DepalaPilotExemplarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
        int xValue = controller.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, source.getControllerId(), false) && xValue > 0) {
            new RevealLibraryPutIntoHandEffect(xValue, filter, Zone.LIBRARY, false).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) RevealLibraryPutIntoHandEffect(mage.abilities.effects.common.RevealLibraryPutIntoHandEffect) 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