Search in sources :

Example 61 with Mana

use of mage.Mana in project mage by magefree.

the class TundraFumaroleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int snow = ManaPaidSourceWatcher.getSnowPaid(source.getId(), game);
    if (snow > 0) {
        player.getManaPool().addMana(new Mana(ManaType.COLORLESS, snow), game, source, true);
    }
    return true;
}
Also used : Player(mage.players.Player) Mana(mage.Mana)

Example 62 with Mana

use of mage.Mana in project mage by magefree.

the class YurlokOfScorchThrashManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netMana = new ArrayList<>();
    netMana.add(new Mana(0, 0, 1, 1, 1, 0, 0, 0));
    return netMana;
}
Also used : Mana(mage.Mana) ArrayList(java.util.ArrayList)

Example 63 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method subtractCostAddMana.

/**
 * Performs the simulation of a mana ability with costs
 *
 * @param cost               cost to use the ability
 * @param manaToAdd          one mana variation that can be added by using
 *                           this ability
 * @param onlyManaCosts      flag to know if the costs are mana costs only
 * @param currentMana        the mana available before the usage of the
 *                           ability
 * @param oldManaWasReplaced returns the info if the new complete mana does
 *                           replace the current mana completely
 */
private boolean subtractCostAddMana(Mana cost, Mana manaToAdd, boolean onlyManaCosts, Mana currentMana, ManaAbility manaAbility, Game game) {
    // true if the newly created mana includes all mana possibilities of the old
    boolean oldManaWasReplaced = false;
    boolean repeatable = false;
    if (manaToAdd != null && (manaToAdd.countColored() > 0 || manaToAdd.getAny() > 0) && manaToAdd.count() > 0 && onlyManaCosts) {
        // only replace to any with mana costs only will be repeated if able
        repeatable = true;
    }
    for (Mana payCombination : ManaOptions.getPossiblePayCombinations(cost, currentMana)) {
        // copy start mana because in iteration it will be updated
        Mana currentManaCopy = currentMana.copy();
        while (currentManaCopy.includesMana(payCombination)) {
            // loop for multiple usage if possible
            boolean newCombinations = false;
            if (manaToAdd == null) {
                Mana newMana = currentManaCopy.copy();
                newMana.subtract(payCombination);
                for (Mana mana : manaAbility.getNetMana(game, newMana)) {
                    // get the mana to add from the ability related to the currently generated possible mana pool
                    newMana.add(mana);
                    if (!isExistingManaCombination(newMana)) {
                        // add the new combination
                        this.add(newMana);
                        // repeat the while as long there are new combinations and usage is repeatable
                        newCombinations = true;
                        Mana moreValuable = Mana.getMoreValuableMana(currentManaCopy, newMana);
                        if (newMana.equals(moreValuable)) {
                            // the new mana includes all possibilities of the old one, so no need to add it after return
                            oldManaWasReplaced = true;
                            if (!currentMana.equalManaValue(currentManaCopy)) {
                                this.removeEqualMana(currentManaCopy);
                            }
                        }
                        currentManaCopy = newMana.copy();
                    }
                }
            } else {
                Mana newMana = currentManaCopy.copy();
                newMana.subtract(payCombination);
                newMana.add(manaToAdd);
                if (!isExistingManaCombination(newMana)) {
                    // add the new combination
                    this.add(newMana);
                    // repeat the while as long there are new combinations and usage is repeatable
                    newCombinations = true;
                    Mana moreValuable = Mana.getMoreValuableMana(currentManaCopy, newMana);
                    if (newMana.equals(moreValuable)) {
                        // the new mana includes all possible mana of the old one, so no need to add it after return
                        oldManaWasReplaced = true;
                        if (!currentMana.equalManaValue(currentManaCopy)) {
                            this.removeEqualMana(currentManaCopy);
                        }
                    }
                    currentManaCopy = newMana.copy();
                }
            }
            if (!newCombinations || !repeatable) {
                break;
            }
        }
    }
    forceManaDeduplication();
    return oldManaWasReplaced;
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 64 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method addManaWithCost.

/**
 * This adds the mana the abilities can produce to the possible mana
 * variabtion.
 *
 * @param abilities
 * @param game
 * @return false if the costs could not be paid
 */
public boolean addManaWithCost(List<ActivatedManaAbilityImpl> abilities, Game game) {
    boolean wasUsable = false;
    int replaces = 0;
    if (isEmpty()) {
        // needed if this is the first available mana, otherwise looping over existing options woold not loop
        this.add(new Mana());
    }
    if (!abilities.isEmpty()) {
        if (abilities.size() == 1) {
            List<Mana> netManas = abilities.get(0).getNetMana(game);
            if (netManas.size() > 0) {
                // ability can produce mana
                ActivatedManaAbilityImpl ability = abilities.get(0);
                // The ability has no mana costs
                if (ability.getManaCosts().isEmpty()) {
                    // No mana costs, so no mana to subtract from available
                    if (netManas.size() == 1) {
                        checkManaReplacementAndTriggeredMana(ability, game, netManas.get(0));
                        addMana(netManas.get(0));
                        addTriggeredMana(game, ability);
                    } else {
                        List<Mana> copy = copy();
                        this.clear();
                        for (Mana netMana : netManas) {
                            checkManaReplacementAndTriggeredMana(ability, game, netMana);
                            for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
                                for (Mana mana : copy) {
                                    Mana newMana = new Mana();
                                    newMana.add(mana);
                                    newMana.add(triggeredManaVariation);
                                    this.add(newMana);
                                    wasUsable = true;
                                }
                            }
                        }
                    }
                } else {
                    // The ability has mana costs
                    List<Mana> copy = copy();
                    this.clear();
                    for (Mana netMana : netManas) {
                        checkManaReplacementAndTriggeredMana(ability, game, netMana);
                        for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
                            for (Mana prevMana : copy) {
                                Mana startingMana = prevMana.copy();
                                Mana manaCosts = ability.getManaCosts().getMana();
                                if (startingMana.includesMana(manaCosts)) {
                                    // can pay the mana costs to use the ability
                                    if (!subtractCostAddMana(manaCosts, triggeredManaVariation, 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(prevMana);
                                    }
                                    wasUsable = true;
                                } else {
                                    // mana costs can't be paid so keep starting mana
                                    add(prevMana);
                                }
                            }
                        }
                    }
                }
            }
        } else {
            // perform a union of all existing options and the new options
            List<Mana> copy = copy();
            this.clear();
            for (ActivatedManaAbilityImpl ability : abilities) {
                List<Mana> netManas = ability.getNetMana(game);
                if (ability.getManaCosts().isEmpty()) {
                    for (Mana netMana : netManas) {
                        checkManaReplacementAndTriggeredMana(ability, game, netMana);
                        for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
                            for (Mana mana : copy) {
                                Mana newMana = new Mana();
                                newMana.add(mana);
                                newMana.add(triggeredManaVariation);
                                this.add(newMana);
                                wasUsable = true;
                            }
                        }
                    }
                } else {
                    for (Mana netMana : netManas) {
                        checkManaReplacementAndTriggeredMana(ability, game, netMana);
                        for (Mana triggeredManaVariation : getTriggeredManaVariations(game, ability, netMana)) {
                            for (Mana previousMana : copy) {
                                CombineWithExisting: for (Mana manaOption : ability.getManaCosts().getManaOptions()) {
                                    if (previousMana.includesMana(manaOption)) {
                                        // costs can be paid
                                        wasUsable |= subtractCostAddMana(manaOption, triggeredManaVariation, ability.getCosts().isEmpty(), previousMana, ability, game);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (this.size() > 30 || replaces > 30) {
        logger.trace("ManaOptionsCosts " + this.size() + " Ign:" + replaces + " => " + this.toString());
        logger.trace("Abilities: " + abilities.toString());
    }
    forceManaDeduplication();
    return wasUsable;
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana)

Example 65 with Mana

use of mage.Mana in project mage by magefree.

the class ManaOptions method toString.

@Override
public String toString() {
    Iterator<Mana> it = this.iterator();
    if (!it.hasNext()) {
        return "[]";
    }
    StringBuilder sb = new StringBuilder();
    sb.append('[');
    for (; ; ) {
        Mana mana = it.next();
        sb.append(mana.toString());
        if (mana instanceof ConditionalMana) {
            sb.append(((ConditionalMana) mana).getConditionString());
        }
        if (!it.hasNext()) {
            return sb.append(']').toString();
        }
        sb.append(',').append(' ');
    }
}
Also used : Mana(mage.Mana) ConditionalMana(mage.ConditionalMana) 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