Search in sources :

Example 6 with FilterMana

use of mage.filter.FilterMana in project mage by magefree.

the class ManaUtil method getColorIdentity.

/**
 * Find full card's color identity (from mana cost and rules)
 *
 * @param cardColor       color indicator
 * @param cardManaSymbols mana cost
 * @param cardRules       rules list
 * @param secondSideCard  second side of double faces card
 * @return
 */
public static FilterMana getColorIdentity(ObjectColor cardColor, String cardManaSymbols, List<String> cardRules, Card secondSideCard) {
    // 20210121
    // 903.4
    // The Commander variant uses color identity to determine what cards can be in a deck with a certain
    // commander. The color identity of a card is the color or colors of any mana symbols in that card’s mana
    // cost or rules text, plus any colors defined by its characteristic-defining abilities (see rule 604.3)
    // or color indicator (see rule 204).
    // 903.4d
    // The back face of a double-faced card (see rule 711) is included when determining a card’s color identity.
    // This is an exception to rule 711.4a.
    FilterMana res = new FilterMana();
    // from object (color indicator)
    ObjectColor color = (cardColor != null ? new ObjectColor(cardColor) : new ObjectColor());
    // from mana
    res.setWhite(color.isWhite() || containsManaSymbol(cardManaSymbols, "W"));
    res.setBlue(color.isBlue() || containsManaSymbol(cardManaSymbols, "U"));
    res.setBlack(color.isBlack() || containsManaSymbol(cardManaSymbols, "B"));
    res.setRed(color.isRed() || containsManaSymbol(cardManaSymbols, "R"));
    res.setGreen(color.isGreen() || containsManaSymbol(cardManaSymbols, "G"));
    // from rules
    for (String rule : cardRules) {
        // Ignoring reminder text in italic
        rule = rule.replaceAll("(?i)<i.*?</i>", "");
        if (!res.isWhite() && (rule.matches(regexWhite))) {
            res.setWhite(true);
        }
        if (!res.isBlue() && (rule.matches(regexBlue))) {
            res.setBlue(true);
        }
        if (!res.isBlack() && rule.matches(regexBlack)) {
            res.setBlack(true);
        }
        if (!res.isRed() && (rule.matches(regexRed))) {
            res.setRed(true);
        }
        if (!res.isGreen() && (rule.matches(regexGreen))) {
            res.setGreen(true);
        }
    }
    // SECOND SIDE CARD
    if (secondSideCard != null) {
        // from object (color indicator)
        ObjectColor secondColor = secondSideCard.getColor(null);
        res.setBlack(res.isBlack() || secondColor.isBlack());
        res.setGreen(res.isGreen() || secondColor.isGreen());
        res.setRed(res.isRed() || secondColor.isRed());
        res.setBlue(res.isBlue() || secondColor.isBlue());
        res.setWhite(res.isWhite() || secondColor.isWhite());
        // from mana
        List<String> secondManaSymbols = secondSideCard.getManaCostSymbols();
        res.setWhite(res.isWhite() || containsManaSymbol(secondManaSymbols, "W"));
        res.setBlue(res.isBlue() || containsManaSymbol(secondManaSymbols, "U"));
        res.setBlack(res.isBlack() || containsManaSymbol(secondManaSymbols, "B"));
        res.setRed(res.isRed() || containsManaSymbol(secondManaSymbols, "R"));
        res.setGreen(res.isGreen() || containsManaSymbol(secondManaSymbols, "G"));
        // from rules
        for (String rule : secondSideCard.getRules()) {
            // Ignoring reminder text in italic
            rule = rule.replaceAll("(?i)<i.*?</i>", "");
            if (!res.isWhite() && rule.matches(regexWhite)) {
                res.setWhite(true);
            }
            if (!res.isBlue() && rule.matches(regexBlue)) {
                res.setBlue(true);
            }
            if (!res.isBlack() && rule.matches(regexBlack)) {
                res.setBlack(true);
            }
            if (!res.isRed() && rule.matches(regexRed)) {
                res.setRed(true);
            }
            if (!res.isGreen() && rule.matches(regexGreen)) {
                res.setGreen(true);
            }
        }
    }
    return res;
}
Also used : FilterMana(mage.filter.FilterMana) ObjectColor(mage.ObjectColor)

Example 7 with FilterMana

use of mage.filter.FilterMana 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)

Example 8 with FilterMana

use of mage.filter.FilterMana in project mage by magefree.

the class ManaCostsImpl method handleLikePhyrexianManaCosts.

private void handleLikePhyrexianManaCosts(Player player, Ability source, Game game) {
    if (this.isEmpty()) {
        // nothing to be done without any mana costs. prevents NRE from occurring here
        return;
    }
    FilterMana phyrexianColors = player.getPhyrexianColors();
    if (player.getPhyrexianColors() == null) {
        return;
    }
    Costs<PayLifeCost> tempCosts = new CostsImpl<>();
    Iterator<T> manaCostIterator = this.iterator();
    while (manaCostIterator.hasNext()) {
        ManaCost manaCost = manaCostIterator.next();
        Mana mana = manaCost.getMana();
        /* find which color mana is in the cost and set it in the temp Phyrexian cost */
        if ((!phyrexianColors.isWhite() || mana.getWhite() <= 0) && (!phyrexianColors.isBlue() || mana.getBlue() <= 0) && (!phyrexianColors.isBlack() || mana.getBlack() <= 0) && (!phyrexianColors.isRed() || mana.getRed() <= 0) && (!phyrexianColors.isGreen() || mana.getGreen() <= 0)) {
            continue;
        }
        PayLifeCost payLifeCost = new PayLifeCost(2);
        if (payLifeCost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.LoseLife, "Pay 2 life (using an active ability) instead of " + manaCost.getMana() + '?', source, game)) {
            manaCostIterator.remove();
            tempCosts.add(payLifeCost);
        }
    }
    tempCosts.pay(source, game, source, player.getId(), false, null);
}
Also used : FilterMana(mage.filter.FilterMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) PayLifeCost(mage.abilities.costs.common.PayLifeCost)

Example 9 with FilterMana

use of mage.filter.FilterMana in project mage by magefree.

the class KrrikSonOfYawgmothPhyrexianEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    FilterMana phyrexianBlack = new FilterMana();
    phyrexianBlack.setBlack(true);
    if (controller != null && sourcePermanent != null) {
        controller.addPhyrexianToColors(phyrexianBlack);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterMana(mage.filter.FilterMana) Permanent(mage.game.permanent.Permanent)

Example 10 with FilterMana

use of mage.filter.FilterMana in project mage by magefree.

the class Sets method generateRandomCardPool.

public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, boolean onlyBasicLands, List<String> allowedSets) {
    CardCriteria criteria = new CardCriteria();
    if (onlyBasicLands) {
        // only lands
        criteria.rarities(Rarity.LAND);
        // basic lands is colorless
        criteria.colorless(true);
    } else {
        // any card, but not basic lands
        criteria.notTypes(CardType.LAND);
        // clear colors
        criteria.white(false);
        criteria.blue(false);
        criteria.black(false);
        criteria.red(false);
        criteria.green(false);
        // colorless is not allowed for gen
        criteria.colorless(false);
    }
    if (allowedSets != null && allowedSets.size() > 0) {
        for (String code : allowedSets) {
            criteria.setCodes(code);
        }
    }
    FilterMana manaNeed = new FilterMana();
    for (ColoredManaSymbol color : allowedColors) {
        switch(color) {
            case W:
                manaNeed.setWhite(true);
                criteria.white(true);
                break;
            case U:
                manaNeed.setBlue(true);
                criteria.blue(true);
                break;
            case B:
                manaNeed.setBlack(true);
                criteria.black(true);
                break;
            case R:
                manaNeed.setRed(true);
                criteria.red(true);
                break;
            case G:
                manaNeed.setGreen(true);
                criteria.green(true);
                break;
        }
    }
    List<CardInfo> cards = CardRepository.instance.findCards(criteria);
    if (cards.isEmpty()) {
        throw new IllegalStateException("Can't find cards for chosen colors to generate deck: " + allowedColors);
    }
    int count = 0;
    int tries = 0;
    List<Card> cardPool = new ArrayList<>();
    while (count < cardsCount) {
        CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
        Card card = cardInfo != null ? cardInfo.getCard() : null;
        if (card != null) {
            FilterMana manaCard = card.getColorIdentity();
            boolean cardManaOK = true;
            if (onlyBasicLands) {
                // Assert.assertEquals("only basic lands allow, but found " + card.getName(), 1, card.getMana().size());
                for (Mana manaLand : card.getMana()) {
                    if (manaLand.getWhite() > 0 && !manaNeed.isWhite()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlue() > 0 && !manaNeed.isBlue()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlack() > 0 && !manaNeed.isBlack()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getRed() > 0 && !manaNeed.isRed()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getGreen() > 0 && !manaNeed.isGreen()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getColorless() > 0) {
                        cardManaOK = false;
                    }
                // ignore colorless land (wastes)
                }
            } else {
                // discard any card that have not needed color
                if (manaCard.isWhite() && !manaNeed.isWhite()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlue() && !manaNeed.isBlue()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlack() && !manaNeed.isBlack()) {
                    cardManaOK = false;
                }
                if (manaCard.isRed() && !manaNeed.isRed()) {
                    cardManaOK = false;
                }
                if (manaCard.isGreen() && !manaNeed.isGreen()) {
                    cardManaOK = false;
                }
            }
            if (cardManaOK) {
                cardPool.add(card);
                count++;
            }
        }
        tries++;
        if (tries > 4096) {
            // to avoid infinite loop
            throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
        }
    }
    return cardPool;
}
Also used : FilterMana(mage.filter.FilterMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Aggregations

FilterMana (mage.filter.FilterMana)17 Card (mage.cards.Card)10 Ability (mage.abilities.Ability)6 Mana (mage.Mana)5 CompanionAbility (mage.abilities.keyword.CompanionAbility)5 PartnerAbility (mage.abilities.keyword.PartnerAbility)5 PartnerWithAbility (mage.abilities.keyword.PartnerWithAbility)5 java.util (java.util)4 ObjectColor (mage.ObjectColor)4 CanBeYourCommanderAbility (mage.abilities.common.CanBeYourCommanderAbility)4 Constructed (mage.cards.decks.Constructed)4 Deck (mage.cards.decks.Deck)4 DeckValidatorErrorType (mage.cards.decks.DeckValidatorErrorType)4 CardType (mage.constants.CardType)4 Player (mage.players.Player)4 ManaUtil (mage.util.ManaUtil)4 UUID (java.util.UUID)3 ExpansionSet (mage.cards.ExpansionSet)3 Sets (mage.cards.Sets)3 FriendsForeverAbility (mage.abilities.keyword.FriendsForeverAbility)2