Search in sources :

Example 71 with Mana

use of mage.Mana in project mage by magefree.

the class ManaChoice method chooseAnyColor.

public static Mana chooseAnyColor(Player player, Game game, int amount) {
    if (player == null) {
        return null;
    }
    Mana mana = new Mana();
    for (int i = 0; i < amount; i++) {
        ChoiceColor choiceColor = new ChoiceColor();
        if (amount > 1) {
            choiceColor.setMessage("Choose color " + (i + 1));
        }
        if (!player.choose(Outcome.Benefit, choiceColor, game)) {
            return null;
        }
        choiceColor.increaseMana(mana);
    }
    return mana;
}
Also used : Mana(mage.Mana)

Example 72 with Mana

use of mage.Mana in project mage by magefree.

the class ManaUtil method getManaAbilitiesUsingMana.

/**
 * This is old method that uses unpaid mana to filter out some abilities.
 * The only disadvantage is that it can't handle hybrid mana correctly.
 *
 * @param unpaid
 * @param useableAbilities
 * @return
 */
private static LinkedHashMap<UUID, ActivatedManaAbilityImpl> getManaAbilitiesUsingMana(ManaCost unpaid, LinkedHashMap<UUID, ActivatedManaAbilityImpl> useableAbilities) {
    Mana mana = unpaid.getMana();
    int countColorfull = 0;
    int countColorless = 0;
    ActivatedManaAbilityImpl chosenManaAbility = null;
    for (ActivatedManaAbilityImpl ability : useableAbilities.values()) {
        if (ability instanceof RedManaAbility && mana.contains(Mana.RedMana(1))) {
            chosenManaAbility = ability;
            countColorfull++;
        }
        if (ability instanceof BlackManaAbility && mana.contains(Mana.BlackMana(1))) {
            chosenManaAbility = ability;
            countColorfull++;
        }
        if (ability instanceof BlueManaAbility && mana.contains(Mana.BlueMana(1))) {
            chosenManaAbility = ability;
            countColorfull++;
        }
        if (ability instanceof WhiteManaAbility && mana.contains(Mana.WhiteMana(1))) {
            chosenManaAbility = ability;
            countColorfull++;
        }
        if (ability instanceof GreenManaAbility && mana.contains(Mana.GreenMana(1))) {
            chosenManaAbility = ability;
            countColorfull++;
        }
    }
    if (countColorfull == 0) {
        // try to pay {1}
        if (mana.getGeneric() > 0) {
            // choose first without addional costs if all have addional costs take the first
            for (ActivatedManaAbilityImpl manaAbility : useableAbilities.values()) {
                if (manaAbility.getCosts().size() == 1 && manaAbility.getCosts().get(0).getClass().equals(TapSourceCost.class)) {
                    return replace(useableAbilities, manaAbility);
                }
            }
            return replace(useableAbilities, useableAbilities.values().iterator().next());
        }
        // return map as-is without any modification
        return useableAbilities;
    }
    if (countColorfull > 1) {
        // return map as-is without any modification
        return useableAbilities;
    }
    return replace(useableAbilities, chosenManaAbility);
}
Also used : Mana(mage.Mana) FilterMana(mage.filter.FilterMana) TapSourceCost(mage.abilities.costs.common.TapSourceCost)

Example 73 with Mana

use of mage.Mana in project mage by magefree.

the class CardUtil method adjustCost.

private static ManaCosts<ManaCost> adjustCost(ManaCosts<ManaCost> manaCosts, int reduceCount) {
    ManaCosts<ManaCost> newCost = new ManaCostsImpl<>();
    // nothing to change
    if (reduceCount == 0) {
        for (ManaCost manaCost : manaCosts) {
            newCost.add(manaCost.copy());
        }
        return newCost;
    }
    // keep same order for costs
    // must be ordered
    Map<ManaCost, ManaCost> changedCost = new LinkedHashMap<>();
    List<ManaCost> addedCost = new ArrayList<>();
    manaCosts.forEach(manaCost -> {
        changedCost.put(manaCost, manaCost);
    });
    // remove or save cost
    if (reduceCount > 0) {
        int restToReduce = reduceCount;
        // first run - priority for single option costs (generic)
        for (ManaCost manaCost : manaCosts) {
            // ignore snow mana
            if (manaCost instanceof SnowManaCost) {
                continue;
            }
            // ignore unknown mana
            if (manaCost.getOptions().size() == 0) {
                continue;
            }
            // ignore monohybrid and other multi-option mana (for potential support)
            if (manaCost.getOptions().size() > 1) {
                continue;
            }
            // generic mana reduce
            Mana mana = manaCost.getOptions().get(0);
            int colorless = mana != null ? mana.getGeneric() : 0;
            if (restToReduce != 0 && colorless > 0) {
                if ((colorless - restToReduce) > 0) {
                    // partly reduce
                    int newColorless = colorless - restToReduce;
                    changedCost.put(manaCost, new GenericManaCost(newColorless));
                    restToReduce = 0;
                } else {
                    // full reduce - ignore cost
                    changedCost.put(manaCost, null);
                    restToReduce -= colorless;
                }
            } else {
            // nothing to reduce
            }
        }
        // TODO: xmage don't use announce for hybrid mana (instead it uses auto-pay), so that's workaround uses first hybrid to reduce (see https://github.com/magefree/mage/issues/6130 )
        for (ManaCost manaCost : manaCosts) {
            if (manaCost.getOptions().size() <= 1) {
                continue;
            }
            if (manaCost instanceof MonoHybridManaCost) {
                // current implemention supports reduce from left to right hybrid cost without cost parts announce
                MonoHybridManaCost mono = (MonoHybridManaCost) manaCost;
                int colorless = mono.getOptions().get(1).getGeneric();
                if (restToReduce != 0 && colorless > 0) {
                    if ((colorless - restToReduce) > 0) {
                        // partly reduce
                        int newColorless = colorless - restToReduce;
                        changedCost.put(manaCost, new MonoHybridManaCost(mono.getManaColor(), newColorless));
                        restToReduce = 0;
                    } else {
                        // full reduce
                        changedCost.put(manaCost, new MonoHybridManaCost(mono.getManaColor(), 0));
                        restToReduce -= colorless;
                    }
                } else {
                // nothing to reduce
                }
                continue;
            }
        // unsupported multi-option mana types for reduce (like HybridManaCost)
        // nothing to do
        }
    }
    // increase cost (add to first generic or add new)
    if (reduceCount < 0) {
        boolean added = false;
        for (ManaCost manaCost : manaCosts) {
            // ignore already reduced cost (add new cost to the start)
            if (changedCost.get(manaCost) == null) {
                continue;
            }
            // add to existing cost
            if (reduceCount != 0 && manaCost instanceof GenericManaCost) {
                GenericManaCost gen = (GenericManaCost) manaCost;
                changedCost.put(manaCost, new GenericManaCost(gen.getOptions().get(0).getGeneric() + -reduceCount));
                reduceCount = 0;
                added = true;
            } else {
            // non-generic mana
            }
        }
        // add as new cost
        if (!added) {
            addedCost.add(new GenericManaCost(-reduceCount));
        }
    }
    // collect final result
    addedCost.forEach(cost -> {
        newCost.add(cost.copy());
    });
    changedCost.forEach((key, value) -> {
        // ignore fully reduced and add changed
        if (value != null) {
            newCost.add(value.copy());
        }
    });
    // cost modifying effects requiring snow mana unnecessarily (fixes #6000)
    Filter filter = manaCosts.stream().filter(manaCost -> !(manaCost instanceof SnowManaCost)).map(ManaCost::getSourceFilter).filter(Objects::nonNull).findFirst().orElse(null);
    if (filter != null) {
        newCost.setSourceFilter(filter);
    }
    return newCost;
}
Also used : Mana(mage.Mana) Hint(mage.abilities.hint.Hint) Filter(mage.filter.Filter)

Example 74 with Mana

use of mage.Mana in project mage by magefree.

the class ManaPool method addMana.

public void addMana(Mana manaToAdd, Game game, Ability source, boolean dontLoseUntilEOT) {
    if (manaToAdd != null) {
        Mana mana = manaToAdd.copy();
        if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source, playerId, mana))) {
            if (mana instanceof ConditionalMana) {
                ConditionalMana conditionalMana = (ConditionalMana) mana;
                ManaPoolItem item = new ManaPoolItem(conditionalMana, source.getSourceObject(game), conditionalMana.getManaProducerOriginalId() != null ? conditionalMana.getManaProducerOriginalId() : source.getOriginalId());
                if (dontLoseUntilEOT) {
                    item.setDuration(Duration.EndOfTurn);
                }
                this.manaItems.add(item);
            } else {
                ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
                if (dontLoseUntilEOT) {
                    item.setDuration(Duration.EndOfTurn);
                }
                this.manaItems.add(item);
            }
            ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source, playerId, mana);
            manaEvent.setData(mana.toString());
            game.fireEvent(manaEvent);
        }
    }
}
Also used : ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) ConditionalMana(mage.ConditionalMana) ManaEvent(mage.game.events.ManaEvent)

Example 75 with Mana

use of mage.Mana in project mage by magefree.

the class CommanderIdentityManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netMana = new ArrayList<>();
    if (game == null) {
        return netMana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) {
            Card commander = game.getCard(commanderId);
            if (commander != null) {
                FilterMana commanderMana = commander.getColorIdentity();
                if (commanderMana.isBlack()) {
                    netMana.add(new Mana(ColoredManaSymbol.B));
                }
                if (commanderMana.isBlue()) {
                    netMana.add(new Mana(ColoredManaSymbol.U));
                }
                if (commanderMana.isGreen()) {
                    netMana.add(new Mana(ColoredManaSymbol.G));
                }
                if (commanderMana.isRed()) {
                    netMana.add(new Mana(ColoredManaSymbol.R));
                }
                if (commanderMana.isWhite()) {
                    netMana.add(new Mana(ColoredManaSymbol.W));
                }
            }
        }
    }
    return netMana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) FilterMana(mage.filter.FilterMana) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Card(mage.cards.Card)

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