Search in sources :

Example 1 with MockCard

use of mage.cards.mock.MockCard in project mage by magefree.

the class CardTextPredicate method apply.

@Override
public boolean apply(Card input, Game game) {
    if (text.isEmpty() && !isUnique) {
        return true;
    }
    if (text.isEmpty() && isUnique) {
        boolean found = !seenCards.containsKey(input.getName());
        seenCards.put(input.getName(), true);
        return found;
    }
    // first check in card name
    if (inNames) {
        String fullName = input.getName();
        if (input instanceof MockCard) {
            fullName = ((MockCard) input).getFullName(true);
        } else if (input instanceof ModalDoubleFacesCard) {
            fullName = input.getName() + MockCard.MODAL_DOUBLE_FACES_NAME_SEPARATOR + ((ModalDoubleFacesCard) input).getRightHalfCard().getName();
        } else if (input instanceof AdventureCard) {
            fullName = input.getName() + MockCard.ADVENTURE_NAME_SEPARATOR + ((AdventureCard) input).getSpellCard().getName();
        }
        if (fullName.toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH))) {
            if (isUnique && seenCards.containsKey(input.getName())) {
                return false;
            }
            if (isUnique) {
                seenCards.put(input.getName(), true);
            }
            return true;
        }
    }
    // separate by spaces
    String[] tokens = text.toLowerCase(Locale.ENGLISH).split(" ");
    for (String token : tokens) {
        boolean found = false;
        if (!token.isEmpty()) {
            // then try to find in rules
            if (inRules) {
                if (input instanceof SplitCard) {
                    for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                    for (String rule : ((SplitCard) input).getRightHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                if (input instanceof ModalDoubleFacesCard) {
                    for (String rule : ((ModalDoubleFacesCard) input).getLeftHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                    for (String rule : ((ModalDoubleFacesCard) input).getRightHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                if (input instanceof AdventureCard) {
                    for (String rule : ((AdventureCard) input).getSpellCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                for (String rule : input.getRules(game)) {
                    if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                        found = true;
                        break;
                    }
                }
            }
            if (inTypes) {
                for (SubType subType : input.getSubtype(game)) {
                    if (subType.toString().equalsIgnoreCase(token)) {
                        found = true;
                        break;
                    }
                }
                for (SuperType superType : input.getSuperType()) {
                    if (superType.toString().equalsIgnoreCase(token)) {
                        found = true;
                        break;
                    }
                }
            }
        }
        if (found && isUnique && seenCards.containsKey(input.getName())) {
            found = false;
        }
        if (!found) {
            return false;
        }
    }
    if (isUnique) {
        seenCards.put(input.getName(), true);
    }
    return true;
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SubType(mage.constants.SubType) MockCard(mage.cards.mock.MockCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) SuperType(mage.constants.SuperType)

Example 2 with MockCard

use of mage.cards.mock.MockCard in project mage by magefree.

the class MageObjectImpl method getFrameColor.

@Override
public ObjectColor getFrameColor(Game game) {
    // its frame colors while game is active to represent ability changes during the game.
    if (this.isLand(game) && !(this instanceof MockCard)) {
        ObjectColor cl = frameColor.copy();
        Set<ManaType> manaTypes = EnumSet.noneOf(ManaType.class);
        for (Ability ab : getAbilities()) {
            if (ab instanceof ActivatedManaAbilityImpl) {
                manaTypes.addAll(((ActivatedManaAbilityImpl) ab).getProducableManaTypes(game));
            }
        }
        cl.setWhite(manaTypes.contains(ManaType.WHITE));
        cl.setBlue(manaTypes.contains(ManaType.BLUE));
        cl.setBlack(manaTypes.contains(ManaType.BLACK));
        cl.setRed(manaTypes.contains(ManaType.RED));
        cl.setGreen(manaTypes.contains(ManaType.GREEN));
        return cl;
    } else {
        // For everything else, just return the frame colors
        return frameColor;
    }
}
Also used : Ability(mage.abilities.Ability) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) MockCard(mage.cards.mock.MockCard)

Aggregations

MockCard (mage.cards.mock.MockCard)2 Ability (mage.abilities.Ability)1 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)1 AdventureCard (mage.cards.AdventureCard)1 ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)1 SplitCard (mage.cards.SplitCard)1 SubType (mage.constants.SubType)1 SuperType (mage.constants.SuperType)1