Search in sources :

Example 1 with Mana

use of mage.Mana in project mage by magefree.

the class ComputerPlayer method buildDeckWithNormalCards.

public static Deck buildDeckWithNormalCards(int deckMinSize, List<Card> cardPool, final List<ColoredManaSymbol> colors) {
    // top 23 cards plus basic lands until 40 deck size
    Deck deck = new Deck();
    final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
    // 23 from 40
    final int DECK_CARDS_COUNT = Math.floorDiv(deckMinSize * 23, 40);
    final int DECK_LANDS_COUNT = DECK_SIZE - DECK_CARDS_COUNT;
    // sort card pool by top score
    List<Card> sortedCards = new ArrayList<>(cardPool);
    Collections.sort(sortedCards, new Comparator<Card>() {

        @Override
        public int compare(Card o1, Card o2) {
            Integer score1 = RateCard.rateCard(o1, colors);
            Integer score2 = RateCard.rateCard(o2, colors);
            return score2.compareTo(score1);
        }
    });
    // get top cards
    int cardNum = 0;
    while (deck.getCards().size() < DECK_CARDS_COUNT && sortedCards.size() > cardNum) {
        Card card = sortedCards.get(cardNum);
        if (!card.isBasic()) {
            deck.getCards().add(card);
            deck.getSideboard().remove(card);
        }
        cardNum++;
    }
    // add basic lands by color percent
    // TODO:  compensate for non basic lands
    Mana mana = new Mana();
    for (Card card : deck.getCards()) {
        mana.add(card.getManaCost().getMana());
    }
    double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
    // most frequent land is forest by default
    int mostLand = 0;
    String mostLandName = "Forest";
    if (mana.getGreen() > 0) {
        int number = (int) Math.round(mana.getGreen() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Forest", number);
        mostLand = number;
    }
    if (mana.getBlack() > 0) {
        int number = (int) Math.round(mana.getBlack() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Swamp", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Swamp";
        }
    }
    if (mana.getBlue() > 0) {
        int number = (int) Math.round(mana.getBlue() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Island", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Island";
        }
    }
    if (mana.getWhite() > 0) {
        int number = (int) Math.round(mana.getWhite() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Plains", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Plains";
        }
    }
    if (mana.getRed() > 0) {
        int number = (int) Math.round(mana.getRed() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Mountain", number);
        if (number > mostLand) {
            mostLandName = "Plains";
        }
    }
    // adds remaining lands (most popular name)
    addBasicLands(deck, mostLandName, DECK_SIZE - deck.getCards().size());
    return deck;
}
Also used : ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) Deck(mage.cards.decks.Deck) RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 2 with Mana

use of mage.Mana in project mage by magefree.

the class CorruptedGrafstoneManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Mana types = getManaTypesInGraveyard(game, source);
    Choice choice = new ChoiceColor(true);
    choice.getChoices().clear();
    choice.setMessage("Pick a mana color");
    if (types.getBlack() > 0) {
        choice.getChoices().add("Black");
    }
    if (types.getRed() > 0) {
        choice.getChoices().add("Red");
    }
    if (types.getBlue() > 0) {
        choice.getChoices().add("Blue");
    }
    if (types.getGreen() > 0) {
        choice.getChoices().add("Green");
    }
    if (types.getWhite() > 0) {
        choice.getChoices().add("White");
    }
    if (!choice.getChoices().isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            if (choice.getChoices().size() == 1) {
                choice.setChoice(choice.getChoices().iterator().next());
            } else {
                if (!player.choose(outcome, choice, game)) {
                    return mana;
                }
            }
            switch(choice.getChoice()) {
                case "Black":
                    mana.setBlack(1);
                    break;
                case "Blue":
                    mana.setBlue(1);
                    break;
                case "Red":
                    mana.setRed(1);
                    break;
                case "Green":
                    mana.setGreen(1);
                    break;
                case "White":
                    mana.setWhite(1);
                    break;
            }
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) Choice(mage.choices.Choice) ChoiceColor(mage.choices.ChoiceColor)

Example 3 with Mana

use of mage.Mana in project mage by magefree.

the class CorruptedGrafstoneManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netManas = new ArrayList<>();
    Mana types = getManaTypesInGraveyard(game, source);
    if (types == null) {
        return null;
    }
    if (types.getBlack() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.B));
    }
    if (types.getRed() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.R));
    }
    if (types.getBlue() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.U));
    }
    if (types.getGreen() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.G));
    }
    if (types.getWhite() > 0) {
        netManas.add(new Mana(ColoredManaSymbol.W));
    }
    return netManas;
}
Also used : Mana(mage.Mana) ArrayList(java.util.ArrayList)

Example 4 with Mana

use of mage.Mana in project mage by magefree.

the class ElementalResonanceEffect method getManaFromString.

private static Mana getManaFromString(String manaString) {
    Mana out = new Mana(0, 0, 0, 0, 0, 0, 0, 0);
    Integer generic = 0;
    for (String str : Arrays.asList(manaString.replaceAll("[^-?0-9]+", " ").trim().split(" "))) {
        if (!str.equals("")) {
            generic += Integer.valueOf(str);
        }
    }
    out.setColorless(generic);
    for (char c : manaString.toCharArray()) {
        switch(c) {
            case 'W':
                out.increaseWhite();
                break;
            case 'U':
                out.increaseBlue();
                break;
            case 'B':
                out.increaseBlack();
                break;
            case 'R':
                out.increaseRed();
                break;
            case 'G':
                out.increaseGreen();
                break;
            case 'C':
                out.increaseColorless();
                break;
        }
    }
    return out;
}
Also used : Mana(mage.Mana)

Example 5 with Mana

use of mage.Mana in project mage by magefree.

the class HarvestMageReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    ManaEvent manaEvent = (ManaEvent) event;
    Mana mana = manaEvent.getMana();
    if (game != null && game.inCheckPlayableState()) {
        mana.setToMana(new Mana(0, 0, 0, 0, 0, 0, 1, 0));
        return false;
    }
    new AddManaOfAnyColorEffect().apply(game, source);
    mana.setToMana(new Mana(0, 0, 0, 0, 0, 0, 0, 0));
    return true;
}
Also used : AddManaOfAnyColorEffect(mage.abilities.effects.mana.AddManaOfAnyColorEffect) Mana(mage.Mana) ManaEvent(mage.game.events.ManaEvent) TappedForManaEvent(mage.game.events.TappedForManaEvent)

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