Search in sources :

Example 91 with Mana

use of mage.Mana in project mage by magefree.

the class IceCauldronManaCondition method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Permanent iceCauldron = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (iceCauldron != null && controller != null) {
        storedMana = (Mana) game.getState().getValue("IceCauldronMana" + source.getSourceId().toString());
        exiledCardMor = (MageObjectReference) game.getState().getValue("IceCauldronCard" + source.getSourceId().toString());
        if (storedMana != null) {
            // should be adding the mana even if exiled card is null
            Card card = exiledCardMor.getCard(game);
            if (card == null) {
                card = game.getCard(exiledCardMor.getSourceId());
                if (card != null && !(card.getZoneChangeCounter(game) == exiledCardMor.getZoneChangeCounter() + 1 && game.getState().getZone(card.getId()) == Zone.STACK)) {
                    card = null;
                }
            }
            if (card != null) {
                return new IceCauldronConditionalMana(storedMana, card);
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 92 with Mana

use of mage.Mana in project mage by magefree.

the class NakedSingularityEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    TappedForManaEvent manaEvent = (TappedForManaEvent) event;
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = manaEvent.getPermanent();
    if (controller == null || permanent == null) {
        return false;
    }
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a color to produce");
    if (permanent.hasSubtype(SubType.PLAINS, game)) {
        choice.getChoices().add("Red");
    }
    if (permanent.hasSubtype(SubType.ISLAND, game)) {
        choice.getChoices().add("Green");
    }
    if (permanent.hasSubtype(SubType.SWAMP, game)) {
        choice.getChoices().add("White");
    }
    if (permanent.hasSubtype(SubType.MOUNTAIN, game)) {
        choice.getChoices().add("Blue");
    }
    if (permanent.hasSubtype(SubType.FOREST, game)) {
        choice.getChoices().add("Black");
    }
    String chosenColor;
    if (choice.getChoices().size() == 1) {
        chosenColor = choice.getChoices().iterator().next();
    } else {
        controller.choose(Outcome.PutManaInPool, choice, game);
        chosenColor = choice.getChoice();
    }
    if (chosenColor == null) {
        return false;
    }
    Mana mana = manaEvent.getMana();
    int amount = mana.count();
    switch(chosenColor) {
        case "White":
            mana.setToMana(Mana.WhiteMana(amount));
            break;
        case "Blue":
            mana.setToMana(Mana.BlueMana(amount));
            break;
        case "Black":
            mana.setToMana(Mana.BlackMana(amount));
            break;
        case "Red":
            mana.setToMana(Mana.RedMana(amount));
            break;
        case "Green":
            mana.setToMana(Mana.GreenMana(amount));
            break;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Mana(mage.Mana) Permanent(mage.game.permanent.Permanent) ChoiceColor(mage.choices.ChoiceColor) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 93 with Mana

use of mage.Mana in project mage by magefree.

the class RitualOfSubdualReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaEvent manaEvent = (ManaEvent) event;
    Mana mana = manaEvent.getMana();
    mana.setToMana(Mana.ColorlessMana(mana.count()));
    return false;
}
Also used : Mana(mage.Mana) ManaEvent(mage.game.events.ManaEvent) TappedForManaEvent(mage.game.events.TappedForManaEvent)

Example 94 with Mana

use of mage.Mana in project mage by magefree.

the class YurlokOfScorchThrashManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Mana manaToAdd = produceMana(game, source);
        if (manaToAdd == null || manaToAdd.count() <= 0) {
            continue;
        }
        checkToFirePossibleEvents(manaToAdd, game, source);
        addManaToPool(player, manaToAdd, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) UUID(java.util.UUID)

Example 95 with Mana

use of mage.Mana in project mage by magefree.

the class SpellsCostReductionControllerEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (manaCostsToReduce != null) {
        CardUtil.adjustCost((SpellAbility) abilityToModify, manaCostsToReduce, false);
    } else {
        if (upTo) {
            Mana mana = abilityToModify.getManaCostsToPay().getMana();
            int reduceMax = mana.getGeneric();
            if (reduceMax > this.amount) {
                reduceMax = this.amount;
            }
            if (reduceMax > 0) {
                Player controller = game.getPlayer(abilityToModify.getControllerId());
                if (controller == null) {
                    return false;
                }
                int reduce = reduceMax;
                if (!game.inCheckPlayableState()) {
                    ChoiceImpl choice = new ChoiceImpl(false);
                    Set<String> set = new LinkedHashSet<>();
                    for (int i = 0; i <= reduceMax; i++) {
                        set.add(String.valueOf(i));
                    }
                    choice.setChoices(set);
                    MageObject mageObject = game.getObject(abilityToModify.getSourceId());
                    choice.setMessage("Reduce cost of " + (mageObject != null ? mageObject.getIdName() : filter.getMessage()));
                    if (controller.choose(Outcome.Benefit, choice, game)) {
                        reduce = Integer.parseInt(choice.getChoice());
                    } else {
                        // cancel will be set to max possible reduce
                        reduce = reduceMax;
                    }
                }
                if (reduce > 0) {
                    CardUtil.reduceCost(abilityToModify, reduce);
                }
            }
        } else {
            CardUtil.reduceCost(abilityToModify, this.amount);
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Mana(mage.Mana) MageObject(mage.MageObject) ChoiceImpl(mage.choices.ChoiceImpl)

Aggregations

Mana (mage.Mana)147 Player (mage.players.Player)76 ConditionalMana (mage.ConditionalMana)33 Permanent (mage.game.permanent.Permanent)32 ArrayList (java.util.ArrayList)26 Choice (mage.choices.Choice)23 ChoiceColor (mage.choices.ChoiceColor)23 ChoiceImpl (mage.choices.ChoiceImpl)14 TappedForManaEvent (mage.game.events.TappedForManaEvent)14 Card (mage.cards.Card)13 ManaEvent (mage.game.events.ManaEvent)11 ObjectColor (mage.ObjectColor)8 ManaOptions (mage.abilities.mana.ManaOptions)8 FilterMana (mage.filter.FilterMana)8 LinkedHashSet (java.util.LinkedHashSet)7 UUID (java.util.UUID)7 FilterPermanent (mage.filter.FilterPermanent)6 MageObject (mage.MageObject)5 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)5 FilterCard (mage.filter.FilterCard)5