Search in sources :

Example 1 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class FroghemothEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        FilterCard filter = new FilterCard("cards from defender's graveyard");
        filter.add(new OwnerIdPredicate(event.getPlayerId()));
        this.getTargets().clear();
        this.addTarget(new TargetCardInGraveyard(0, event.getAmount(), filter));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 2 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class GlyphOfReincarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && targetWall != null) {
        BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
        if (watcher != null) {
            Map<UUID, Player> destroyed = new HashMap<>();
            for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (!creature.getId().equals(targetWall.getId())) {
                    if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
                        if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
                            // If a commander is replaced to command zone, the creature does not die
                            Player permController = game.getPlayer(creature.getControllerId());
                            if (permController != null) {
                                destroyed.put(creature.getId(), permController);
                            }
                        }
                    }
                }
            }
            // onto the battlefield under its owner’s control
            for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
                Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
                Player player = entry.getValue();
                if (permanent != null && player != null) {
                    FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
                    filter.add(new OwnerIdPredicate(player.getId()));
                    Target targetCreature = new TargetCardInGraveyard(filter);
                    targetCreature.setNotTarget(true);
                    if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
                        Card card = game.getCard(targetCreature.getFirstTarget());
                        if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) BlockedAttackerWatcher(mage.watchers.common.BlockedAttackerWatcher) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) MageObjectReference(mage.MageObjectReference)

Example 3 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class ZarethSanTheTricksterTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterCard filter = new FilterPermanentCard("permanent card in " + opponent.getLogName() + "'s graveyard");
    filter.add(new OwnerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCardInGraveyard(filter));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) DamagedEvent(mage.game.events.DamagedEvent)

Example 4 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate 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 5 with OwnerIdPredicate

use of mage.filter.predicate.card.OwnerIdPredicate in project mage by magefree.

the class OathOfGhoulsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    if (sourceObject == null || firstPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card");
    filter.add(new OwnerIdPredicate(firstPlayer.getId()));
    Target target = new TargetCardInGraveyard(filter);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), firstPlayer.getId(), game) && firstPlayer.chooseUse(outcome, "Return a creature card from your graveyard to your hand?", source, game) && firstPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            firstPlayer.moveCards(card, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Aggregations

OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)34 Player (mage.players.Player)29 TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)23 FilterCard (mage.filter.FilterCard)19 Card (mage.cards.Card)15 UUID (java.util.UUID)11 FilterCreatureCard (mage.filter.common.FilterCreatureCard)10 Permanent (mage.game.permanent.Permanent)9 Target (mage.target.Target)8 Cards (mage.cards.Cards)5 CardsImpl (mage.cards.CardsImpl)5 HashSet (java.util.HashSet)4 FilterPermanent (mage.filter.FilterPermanent)4 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)4 MageObject (mage.MageObject)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)3 TargetCard (mage.target.TargetCard)3 TargetPlayer (mage.target.TargetPlayer)3 TargetOpponent (mage.target.common.TargetOpponent)3