Search in sources :

Example 66 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method addMana.

public void addMana(List<ActivatedManaAbilityImpl> abilities, Game game) {
    if (isEmpty()) {
        this.add(new Mana());
    }
    if (!abilities.isEmpty()) {
        if (abilities.size() == 1) {
            // if there is only one mana option available add it to all the existing options
            List<Mana> netManas = abilities.get(0).getNetMana(game);
            if (netManas.size() == 1) {
                checkManaReplacementAndTriggeredMana(abilities.get(0), game, netManas.get(0));
                addMana(netManas.get(0));
                addTriggeredMana(game, abilities.get(0));
            } else if (netManas.size() > 1) {
                addManaVariation(netManas, abilities.get(0), game);
            }
        } else {
            // mana source has more than 1 ability
            // perform a union of all existing options and the new options
            List<Mana> copy = copy();
            this.clear();
            for (ActivatedManaAbilityImpl ability : abilities) {
                for (Mana netMana : ability.getNetMana(game)) {
                    checkManaReplacementAndTriggeredMana(ability, game, netMana);
                    for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
                        SkipAddMana: for (Mana mana : copy) {
                            Mana newMana = new Mana();
                            newMana.add(mana);
                            newMana.add(triggeredManaVariation);
                            for (Mana existingMana : this) {
                                if (existingMana.equalManaValue(newMana)) {
                                    continue SkipAddMana;
                                }
                                Mana moreValuable = Mana.getMoreValuableMana(newMana, existingMana);
                                if (moreValuable != null) {
                                    // only keep the more valuable mana
                                    existingMana.setToMana(moreValuable);
                                    continue SkipAddMana;
                                }
                            }
                            this.add(newMana);
                        }
                    }
                }
            }
        }
    }
    forceManaDeduplication();
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 67 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method addManaCombination.

public static void addManaCombination(Mana mana, Mana existingMana, List<Mana> payCombinations, List<String> payCombinationsStrings) {
    Mana newMana = existingMana.copy();
    newMana.add(mana);
    payCombinations.add(newMana);
    payCombinationsStrings.add(newMana.toString());
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 68 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method getTriggeredManaVariations.

public static List<Mana> getTriggeredManaVariations(Game game, Ability ability, Mana baseMana) {
    List<Mana> baseManaPlusTriggeredMana = new ArrayList<>();
    baseManaPlusTriggeredMana.add(baseMana);
    List<List<Mana>> availableTriggeredManaList = ManaOptions.getSimulatedTriggeredManaFromPlayer(game, ability);
    for (List<Mana> availableTriggeredMana : availableTriggeredManaList) {
        if (availableTriggeredMana.size() == 1) {
            for (Mana prevMana : baseManaPlusTriggeredMana) {
                prevMana.add(availableTriggeredMana.get(0));
            }
        } else if (availableTriggeredMana.size() > 1) {
            List<Mana> copy = new ArrayList<>(baseManaPlusTriggeredMana);
            baseManaPlusTriggeredMana.clear();
            for (Mana triggeredMana : availableTriggeredMana) {
                for (Mana prevMana : copy) {
                    Mana newMana = new Mana();
                    newMana.add(prevMana);
                    newMana.add(triggeredMana);
                    baseManaPlusTriggeredMana.add(newMana);
                }
            }
        }
    }
    return baseManaPlusTriggeredMana;
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 69 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method removeEqualMana.

public boolean removeEqualMana(Mana manaToRemove) {
    boolean result = false;
    for (Iterator<Mana> iterator = this.iterator(); iterator.hasNext(); ) {
        Mana next = iterator.next();
        if (next.equalManaValue(manaToRemove)) {
            iterator.remove();
            result = true;
        }
    }
    return result;
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 70 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method addManaPoolDependant.

public boolean addManaPoolDependant(List<ActivatedManaAbilityImpl> abilities, Game game) {
    boolean wasUsable = false;
    if (!abilities.isEmpty()) {
        if (abilities.size() == 1) {
            ActivatedManaAbilityImpl ability = (ActivatedManaAbilityImpl) abilities.get(0);
            List<Mana> copy = copy();
            this.clear();
            for (Mana previousMana : copy) {
                Mana startingMana = previousMana.copy();
                Mana manaCosts = ability.getManaCosts().getMana();
                if (startingMana.includesMana(manaCosts)) {
                    // can pay the mana costs to use the ability
                    for (Mana manaOption : ability.getManaCosts().getManaOptions()) {
                        if (!subtractCostAddMana(manaOption, null, ability.getCosts().isEmpty(), startingMana, ability, game)) {
                            // the starting mana includes mana parts that the increased mana does not include, so add starting mana also as an option
                            add(previousMana);
                        }
                    }
                    wasUsable = true;
                } else {
                    // mana costs can't be paid so keep starting mana
                    add(previousMana);
                }
            }
        }
    }
    return wasUsable;
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

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