Search in sources :

Example 6 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class ZzzyxassAbyssEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<String> permanentNames = new ArrayList<>();
        FilterPermanent filter = new FilterNonlandPermanent();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
            permanentNames.add(permanent.getName());
        }
        if (permanentNames.isEmpty()) {
            return true;
        }
        Collections.sort(permanentNames);
        filter.add(new NamePredicate(permanentNames.get(0)));
        return new DestroyAllEffect(filter).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 7 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class MeldCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceMageObject = source.getSourceObjectIfItStillExists(game);
    if (sourceMageObject instanceof Permanent) {
        Permanent sourcePermanent = (Permanent) sourceMageObject;
        if (sourcePermanent.isControlledBy(source.getControllerId()) && sourcePermanent.isOwnedBy(source.getControllerId())) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
            filter.add(new NamePredicate(this.meldWithName));
            filter.add(new OwnerIdPredicate(source.getControllerId()));
            return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0;
        }
    }
    return false;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 8 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class MeldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Find the two permanents to meld.
        UUID sourceId = source.getSourceId();
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
        filter.add(new NamePredicate(meldWithName));
        TargetPermanent target = new TargetControlledCreaturePermanent(filter);
        Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
        if (meldWithList.isEmpty()) {
            // possible permanent has left the battlefield meanwhile
            return false;
        }
        UUID meldWithId = null;
        if (meldWithList.size() == 1) {
            meldWithId = meldWithList.iterator().next();
        } else {
            if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
                meldWithId = target.getFirstTarget();
            }
        }
        // Exile the two permanents to meld.
        Permanent sourcePermanent = game.getPermanent(sourceId);
        Permanent meldWithPermanent = game.getPermanent(meldWithId);
        if (sourcePermanent != null && meldWithPermanent != null) {
            Set<Card> toExile = new HashSet<>();
            toExile.add(sourcePermanent);
            toExile.add(meldWithPermanent);
            controller.moveCards(toExile, Zone.EXILED, source, game);
            // Create the meld card and move it to the battlefield.
            Card sourceCard = game.getExile().getCard(sourceId, game);
            Card meldWithCard = game.getExile().getCard(meldWithId, game);
            if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
                meldCard.setOwnerId(controller.getId());
                meldCard.setTopHalfCard(meldWithCard, game);
                meldCard.setBottomHalfCard(sourceCard, game);
                meldCard.setMelded(true, game);
                game.addMeldCard(meldCard.getId(), meldCard);
                game.getState().addCard(meldCard);
                meldCard.setZone(Zone.EXILED, game);
                controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 9 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class AchHansRunEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
    game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
    FilterCard nameFilter = new FilterCard();
    nameFilter.add(new NamePredicate(cardName));
    TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
    if (!controller.searchLibrary(target, source, game)) {
        return false;
    }
    Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
    if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
        return false;
    }
    Permanent creature = game.getPermanent(card.getId());
    if (creature == null) {
        return false;
    }
    // gains haste
    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
    effect.setTargetPointer(new FixedTarget(creature, game));
    game.addEffect(effect, source);
    // Exile at begin of next end step
    ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
    exileEffect.setTargetPointer(new FixedTarget(creature, game));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 10 with NamePredicate

use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.

the class AlpineMoonEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (cardName == null) {
        return false;
    }
    FilterPermanent filter2 = filter.copy();
    filter2.add(new NamePredicate(cardName));
    for (Permanent land : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), game)) {
        switch(layer) {
            case TypeChangingEffects_4:
                // 305.7 Note that this doesn't remove any abilities that were granted to the land by other effects
                // So the ability removing has to be done before Layer 6
                land.removeAllAbilities(source.getSourceId(), game);
                land.removeAllSubTypes(game, SubTypeSet.NonBasicLandType);
                break;
            case AbilityAddingRemovingEffects_6:
                land.addAbility(new AnyColorManaAbility(), source.getSourceId(), game);
                break;
        }
    }
    return true;
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) AnyColorManaAbility(mage.abilities.mana.AnyColorManaAbility)

Aggregations

NamePredicate (mage.filter.predicate.mageobject.NamePredicate)78 FilterCard (mage.filter.FilterCard)55 Player (mage.players.Player)55 Permanent (mage.game.permanent.Permanent)31 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)30 Card (mage.cards.Card)24 MageObject (mage.MageObject)22 UUID (java.util.UUID)19 FilterPermanent (mage.filter.FilterPermanent)16 TargetCard (mage.target.TargetCard)14 Spell (mage.game.stack.Spell)12 CardsImpl (mage.cards.CardsImpl)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)9 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 TargetPlayer (mage.target.TargetPlayer)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6