Search in sources :

Example 11 with SubType

use of mage.constants.SubType in project mage by magefree.

the class EquippedHasSubtypeCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
    if (permanent == null || permanent.getAttachedTo() == null) {
        return false;
    }
    Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
    if (attachedTo == null) {
        attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
    }
    if (attachedTo == null) {
        return false;
    }
    for (SubType s : subTypes) {
        if (attachedTo.hasSubtype(s, game)) {
            return true;
        }
    }
    return false;
}
Also used : SubType(mage.constants.SubType) Permanent(mage.game.permanent.Permanent)

Example 12 with SubType

use of mage.constants.SubType 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 13 with SubType

use of mage.constants.SubType in project mage by magefree.

the class HauntingVoyageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    SubType chosenSubType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
    if (controller != null && chosenSubType != null) {
        Set<Card> cardsToBattlefield = new LinkedHashSet<>();
        if (!ForetoldCondition.instance.apply(game, source)) {
            TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, 2, new FilterBySubtypeCard(chosenSubType), true);
            controller.chooseTarget(outcome, target, source, game);
            for (UUID cardId : target.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    cardsToBattlefield.add(card);
                }
            }
        } else {
            for (UUID cardId : controller.getGraveyard()) {
                Card card = game.getCard(cardId);
                if (card != null && card.hasSubtype(chosenSubType, game)) {
                    cardsToBattlefield.add(card);
                }
            }
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
            return true;
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) SubType(mage.constants.SubType) FilterBySubtypeCard(mage.filter.common.FilterBySubtypeCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) FilterBySubtypeCard(mage.filter.common.FilterBySubtypeCard) Card(mage.cards.Card)

Example 14 with SubType

use of mage.constants.SubType in project mage by magefree.

the class TargetCardInLibrarySharingLandType method canTarget.

@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Cards cards, Game game) {
    if (!super.canTarget(playerId, id, source, cards, game)) {
        return false;
    }
    if (getTargets().isEmpty()) {
        // first target
        return true;
    }
    Card card1 = game.getCard(getTargets().get(0));
    Card card2 = game.getCard(id);
    return card1 != null && card2 != null && card1.getSubtype(game).stream().filter(SubType.getLandTypes()::contains).anyMatch(subType -> card2.hasSubtype(subType, game));
}
Also used : FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) SacrificeSourceCost(mage.abilities.costs.common.SacrificeSourceCost) Cards(mage.cards.Cards) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) SubType(mage.constants.SubType) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Effect(mage.abilities.effects.Effect) ColorlessManaAbility(mage.abilities.mana.ColorlessManaAbility) CardImpl(mage.cards.CardImpl) EntersBattlefieldTappedAbility(mage.abilities.common.EntersBattlefieldTappedAbility) CardType(mage.constants.CardType) Card(mage.cards.Card) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 15 with SubType

use of mage.constants.SubType in project mage by magefree.

the class VolrathsLaboratoryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
    SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
    Token token = new VolrathsLaboratoryToken(color, subType);
    return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : SubType(mage.constants.SubType) ObjectColor(mage.ObjectColor) VolrathsLaboratoryToken(mage.game.permanent.token.VolrathsLaboratoryToken) Token(mage.game.permanent.token.Token) VolrathsLaboratoryToken(mage.game.permanent.token.VolrathsLaboratoryToken)

Aggregations

SubType (mage.constants.SubType)24 Player (mage.players.Player)11 MageObject (mage.MageObject)8 CardType (mage.constants.CardType)6 Permanent (mage.game.permanent.Permanent)6 UUID (java.util.UUID)5 SuperType (mage.constants.SuperType)5 Collectors (java.util.stream.Collectors)4 Ability (mage.abilities.Ability)4 Card (mage.cards.Card)4 ObjectColor (mage.ObjectColor)3 Effect (mage.abilities.effects.Effect)3 OneShotEffect (mage.abilities.effects.OneShotEffect)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 Choice (mage.choices.Choice)2 Rarity (mage.constants.Rarity)2