Search in sources :

Example 96 with Mana

use of mage.Mana in project mage by magefree.

the class SpellsCostReductionAllEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    if (upTo) {
        if (game.inCheckPlayableState()) {
            CardUtil.reduceCost(abilityToModify, this.amount);
            return true;
        }
        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;
            }
            ChoiceImpl choice = new ChoiceImpl(true);
            Set<String> set = new LinkedHashSet<>();
            for (int i = 0; i <= reduceMax; i++) {
                set.add(String.valueOf(i));
            }
            choice.setChoices(set);
            choice.setMessage("Reduce cost of " + filter);
            if (controller.choose(Outcome.Benefit, choice, game)) {
                int reduce = Integer.parseInt(choice.getChoice());
                CardUtil.reduceCost(abilityToModify, reduce);
            } else {
                return false;
            }
        }
    } else {
        CardUtil.reduceCost(abilityToModify, this.amount);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Mana(mage.Mana) ChoiceImpl(mage.choices.ChoiceImpl)

Example 97 with Mana

use of mage.Mana in project mage by magefree.

the class AnyColorLandsProduceManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), onlyColors);
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (choice.getChoices().size() == 1) {
            choice.setChoice(choice.getChoices().iterator().next());
        } else {
            if (player == null || !player.choose(outcome, choice, game)) {
                return null;
            }
        }
        if (choice.getChoice() != null) {
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
                case "Colorless":
                    mana.setColorless(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice)

Example 98 with Mana

use of mage.Mana in project mage by magefree.

the class AnyColorPermanentTypesManaEffect method getManaTypes.

private Mana getManaTypes(Game game, Ability source) {
    Mana types = new Mana();
    if (game == null || game.getPhase() == null) {
        return types;
    }
    if (inManaTypeCalculation) {
        return types;
    }
    inManaTypeCalculation = true;
    ObjectColor permanentColor;
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    for (Permanent permanent : permanents) {
        permanentColor = permanent.getColor(game);
        if (permanentColor.isColorless()) {
            types.add(Mana.ColorlessMana(1));
        } else {
            List<ObjectColor> permanentColors = permanent.getColor(game).getColors();
            for (ObjectColor color : permanentColors) {
                types.add(new Mana(color.getOneColoredManaSymbol()));
            }
        }
    }
    inManaTypeCalculation = false;
    return types;
}
Also used : Mana(mage.Mana) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ObjectColor(mage.ObjectColor)

Example 99 with Mana

use of mage.Mana in project mage by magefree.

the class AnyColorPermanentTypesManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netManas = new ArrayList<>();
    Mana types = getManaTypes(game, source);
    if (types.getBlack() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.B));
    }
    if (types.getRed() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.R));
    }
    if (types.getBlue() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.U));
    }
    if (types.getGreen() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.G));
    }
    if (types.getWhite() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.W));
    }
    if (!onlyColors && types.getColorless() > 0) {
        netManas.add(Mana.ColorlessMana(1));
    }
    if (types.getAny() > 0) {
        netManas.add(Mana.AnyMana(1));
    }
    return netManas;
}
Also used : Mana(mage.Mana) ArrayList(java.util.ArrayList)

Example 100 with Mana

use of mage.Mana in project mage by magefree.

the class AnyColorPermanentTypesManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Mana types = getManaTypes(game, source);
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a mana color");
    if (types.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (types.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (types.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (types.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (types.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    if (!onlyColors && types.getColorless() > 0) {
        choice.getChoices().add("Colorless");
    }
    if (types.getAny() > 0) {
        choice.getChoices().add("Black");
        choice.getChoices().add("Red");
        choice.getChoices().add("Blue");
        choice.getChoices().add("Green");
        choice.getChoices().add("White");
        if (!onlyColors) {
            choice.getChoices().add("Colorless");
        }
    }
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (choice.getChoices().size() == 1) {
            choice.setChoice(choice.getChoices().iterator().next());
        } else {
            if (!player.choose(outcome, choice, game)) {
                return mana;
            }
        }
        if (choice.getChoice() != null) {
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
                case "Colorless":
                    mana.setColorless(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

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