Search in sources :

Example 6 with ConditionalMana

use of mage.ConditionalMana in project mage by magefree.

the class ManaOptions method addMana.

/**
 * Adds the given mana value to all existing options
 *
 * @param addMana Mana to add to the existing options
 */
public void addMana(Mana addMana) {
    if (isEmpty()) {
        this.add(new Mana());
    }
    if (addMana instanceof ConditionalMana) {
        ManaOptions copy = this.copy();
        this.clear();
        for (Mana mana : copy) {
            ConditionalMana condMana = ((ConditionalMana) addMana).copy();
            condMana.add(mana);
            // Add mana as option with condition
            add(condMana);
            // Add old mana without the condition
            add(mana);
        }
    } else {
        for (Mana mana : this) {
            mana.add(addMana);
        }
    }
    forceManaDeduplication();
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ConditionalMana(mage.ConditionalMana)

Example 7 with ConditionalMana

use of mage.ConditionalMana in project mage by magefree.

the class ManaOptions method removeDuplicated.

public void removeDuplicated() {
    Set<String> list = new HashSet<>();
    for (int i = this.size() - 1; i >= 0; i--) {
        String s;
        if (this.get(i) instanceof ConditionalMana) {
            s = this.get(i).toString() + ((ConditionalMana) this.get(i)).getConditionString();
        } else {
            s = this.get(i).toString();
        }
        if (s.isEmpty()) {
            this.remove(i);
        } else if (list.contains(s)) {
            // remove duplicated
            this.remove(i);
        } else {
            list.add(s);
        }
    }
    // battlefield:Human:Cascading Cataracts:1
    for (int i = this.size() - 1; i >= 0; i--) {
        for (int ii = 0; ii < i; ii++) {
            Mana moreValuable = Mana.getMoreValuableMana(this.get(i), this.get(ii));
            if (moreValuable != null) {
                this.get(ii).setToMana(moreValuable);
                this.remove(i);
                break;
            }
        }
    }
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ConditionalMana(mage.ConditionalMana)

Example 8 with ConditionalMana

use of mage.ConditionalMana in project mage by magefree.

the class DoublingCubeEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    if (game != null) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            ManaPool pool = controller.getManaPool();
            int blackMana = pool.getBlack();
            int whiteMana = pool.getWhite();
            int blueMana = pool.getBlue();
            int greenMana = pool.getGreen();
            int redMana = pool.getRed();
            int colorlessMana = pool.getColorless();
            for (ConditionalMana conditionalMana : pool.getConditionalMana()) {
                blackMana += conditionalMana.getBlack();
                whiteMana += conditionalMana.getWhite();
                blueMana += conditionalMana.getBlue();
                greenMana += conditionalMana.getGreen();
                redMana += conditionalMana.getRed();
                colorlessMana += conditionalMana.getColorless();
            }
            return new Mana(whiteMana, blueMana, blackMana, redMana, greenMana, 0, 0, colorlessMana);
        }
    }
    return new Mana();
}
Also used : Player(mage.players.Player) ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ManaPool(mage.players.ManaPool)

Example 9 with ConditionalMana

use of mage.ConditionalMana in project mage by magefree.

the class AddConditionalManaOfAnyColorEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    if (game != null) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int value = amount.calculate(game, source, this);
            if (value > 0) {
                if (oneChoice || value == 1) {
                    ChoiceColor choice = new ChoiceColor(true);
                    controller.choose(outcome, choice, game);
                    if (choice.getChoice() == null) {
                        return null;
                    }
                    return new ConditionalMana(manaBuilder.setMana(choice.getMana(value), source, game).build());
                }
                List<String> manaStrings = new ArrayList<>(5);
                manaStrings.add("W");
                manaStrings.add("U");
                manaStrings.add("B");
                manaStrings.add("R");
                manaStrings.add("G");
                List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, value, MultiAmountType.MANA, game);
                Mana mana = new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0);
                return new ConditionalMana(manaBuilder.setMana(mana, source, game).build());
            }
        }
    }
    return new Mana();
}
Also used : Player(mage.players.Player) ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ArrayList(java.util.ArrayList) ChoiceColor(mage.choices.ChoiceColor)

Example 10 with ConditionalMana

use of mage.ConditionalMana in project mage by magefree.

the class AddConditionalManaOfTwoDifferentColorsEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    if (game != null) {
        Player player = getPlayer(game, source);
        Mana mana = new ConditionalMana(manaBuilder.setMana(ManaChoice.chooseTwoDifferentColors(player, game), source, game).build());
        return mana;
    }
    return new Mana();
}
Also used : Player(mage.players.Player) Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) ConditionalMana(mage.ConditionalMana)

Aggregations

ConditionalMana (mage.ConditionalMana)14 Mana (mage.Mana)9 Player (mage.players.Player)6 ChoiceColor (mage.choices.ChoiceColor)2 ArrayList (java.util.ArrayList)1 ApprovingObject (mage.ApprovingObject)1 MageObject (mage.MageObject)1 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)1 ManaOptions (mage.abilities.mana.ManaOptions)1 ManaType (mage.constants.ManaType)1 FilterMana (mage.filter.FilterMana)1 GameEvent (mage.game.events.GameEvent)1 ManaEvent (mage.game.events.ManaEvent)1 ManaPaidEvent (mage.game.events.ManaPaidEvent)1 ManaPool (mage.players.ManaPool)1 ManaPoolItem (mage.players.ManaPoolItem)1