Search in sources :

Example 21 with OwnerIdPredicate

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

the class ScionOfDarknessTriggeredAbility method checkTrigger.

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

Example 22 with OwnerIdPredicate

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

the class ZombieCannibalTriggeredAbility method checkTrigger.

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

Example 23 with OwnerIdPredicate

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

the class GravestormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null && you != null) {
        FilterCard filter = new FilterCard("card from your graveyard");
        filter.add(new OwnerIdPredicate(targetPlayer.getId()));
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        boolean opponentChoosesExile = targetPlayer.chooseUse(Outcome.Exile, "Exile a card from your graveyard?", source, game);
        boolean opponentExilesACard = false;
        if (opponentChoosesExile && targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                opponentExilesACard = targetPlayer.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
            }
        }
        if (!opponentExilesACard) {
            if (you.chooseUse(Outcome.DrawCard, "Draw a card?", source, game)) {
                you.drawCards(1, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 24 with OwnerIdPredicate

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

the class GuardianProjectEffect method checkCondition.

// This is needed as checkInterveningIfClause can't access trigger event information
static boolean checkCondition(Permanent permanent, UUID controllerId, Game game) {
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    if (!permanent.getName().isEmpty()) {
        FilterCard filterCard = new FilterCard();
        filterCard.add(new NamePredicate(permanent.getName()));
        filterCard.add(new OwnerIdPredicate(controllerId));
        if (player.getGraveyard().count(filterCard, game) > 0) {
            return false;
        }
    }
    FilterPermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(new NamePredicate(permanent.getName()));
    filterPermanent.add(Predicates.not(new CardIdPredicate(permanent.getId())));
    filterPermanent.add(new ControllerIdPredicate(controllerId));
    if (!game.getBattlefield().getActivePermanents(filterPermanent, controllerId, game).isEmpty()) {
        return false;
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 25 with OwnerIdPredicate

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

the class MausoleumTurnkeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterCreatureCard filter = new FilterCreatureCard("creature card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

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