Search in sources :

Example 31 with Mana

use of mage.Mana in project mage by magefree.

the class AddManaInAnyCombinationEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int size = manaSymbols.size();
        Mana mana = new Mana();
        List<String> manaStrings = new ArrayList<>(size);
        for (ColoredManaSymbol coloredManaSymbol : manaSymbols) {
            manaStrings.add(coloredManaSymbol.toString());
        }
        List<Integer> manaList = player.getMultiAmount(this.outcome, manaStrings, 0, amount.calculate(game, source, this), MultiAmountType.MANA, game);
        for (int i = 0; i < size; i++) {
            ColoredManaSymbol coloredManaSymbol = manaSymbols.get(i);
            int amount = manaList.get(i);
            for (int j = 0; j < amount; j++) {
                mana.add(new Mana(coloredManaSymbol));
            }
        }
        return mana;
    }
    return null;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Example 32 with Mana

use of mage.Mana in project mage by magefree.

the class AddManaOfAnyTypeProducedEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana newMana = new Mana();
    if (game == null) {
        return newMana;
    }
    Permanent permanent = (Permanent) this.getValue("tappedPermanent");
    Mana types = (Mana) this.getValue("mana");
    if (permanent == null || types == null) {
        return newMana;
    }
    Player targetController = game.getPlayer(permanent.getControllerId());
    if (targetController == null) {
        return newMana;
    }
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick the type of mana to produce");
    if (types.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    if (types.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (types.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (types.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (types.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (types.getColorless() > 0) {
        choice.getChoices().add("Colorless");
    }
    if (choice.getChoices().isEmpty()) {
        return newMana;
    }
    if (choice.getChoices().size() != 1 && !targetController.choose(outcome, choice, game)) {
        return newMana;
    }
    choice.setChoice(choice.getChoices().iterator().next());
    switch(choice.getChoice()) {
        case "White":
            newMana.setWhite(1);
            break;
        case "Blue":
            newMana.setBlue(1);
            break;
        case "Black":
            newMana.setBlack(1);
            break;
        case "Red":
            newMana.setRed(1);
            break;
        case "Green":
            newMana.setGreen(1);
            break;
        case "Colorless":
            newMana.setColorless(1);
            break;
    }
    return newMana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) ChoiceColor(mage.choices.ChoiceColor)

Example 33 with Mana

use of mage.Mana in project mage by magefree.

the class AddManaOfAnyTypeProducedEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netMana = new ArrayList<>();
    Mana types = (Mana) this.getValue("mana");
    if (types == null) {
        return netMana;
    }
    if (types.getBlack() > 0) {
        netMana.add(Mana.BlackMana(1));
    }
    if (types.getRed() > 0) {
        netMana.add(Mana.RedMana(1));
    }
    if (types.getBlue() > 0) {
        netMana.add(Mana.BlueMana(1));
    }
    if (types.getGreen() > 0) {
        netMana.add(Mana.GreenMana(1));
    }
    if (types.getWhite() > 0) {
        netMana.add(Mana.WhiteMana(1));
    }
    if (types.getColorless() > 0) {
        netMana.add(Mana.ColorlessMana(1));
    }
    return netMana;
}
Also used : Mana(mage.Mana) ArrayList(java.util.ArrayList)

Example 34 with Mana

use of mage.Mana in project mage by magefree.

the class AddManaOfAnyColorEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    if (game != null) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            String mes = String.format("Select a color of mana to add %d of it", this.amount);
            if (mes != null) {
                ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId()));
                if (controller.choose(outcome, choice, game)) {
                    if (choice.getColor() != null) {
                        Mana mana = choice.getMana(amount);
                        mana.setFlag(setFlag);
                        return mana;
                    }
                }
            }
        }
    }
    return new Mana();
}
Also used : Player(mage.players.Player) Mana(mage.Mana) ChoiceColor(mage.choices.ChoiceColor)

Example 35 with Mana

use of mage.Mana in project mage by magefree.

the class ManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = getPlayer(game, source);
    if (player == null) {
        return false;
    }
    if (game.inCheckPlayableState()) {
        // So it's important if ManaEffects overwrite the apply method to take care for this.
        if (source instanceof TriggeredAbility) {
            player.addAvailableTriggeredMana(getNetMana(game, source));
        }
        // No need to add mana to pool during checkPlayable
        return true;
    }
    Mana manaToAdd = produceMana(game, source);
    if (manaToAdd != null && manaToAdd.count() > 0) {
        checkToFirePossibleEvents(manaToAdd, game, source);
        addManaToPool(player, manaToAdd, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) TriggeredAbility(mage.abilities.TriggeredAbility)

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