Search in sources :

Example 1 with TargetCardInGraveyard

use of mage.target.common.TargetCardInGraveyard in project mage by magefree.

the class DeliverUntoEvilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(source.getTargets().get(0).getTargets());
    if (cards.isEmpty()) {
        return false;
    }
    if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
        return player.moveCards(cards, Zone.HAND, source, game);
    }
    TargetOpponent targetOpponent = new TargetOpponent();
    targetOpponent.setNotTarget(true);
    if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
        return false;
    }
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    TargetCard targetCard = new TargetCardInGraveyard(Math.min(2, cards.size()), filter2);
    if (!opponent.choose(outcome, cards, targetCard, game)) {
        return false;
    }
    cards.removeAll(targetCard.getTargets());
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 2 with TargetCardInGraveyard

use of mage.target.common.TargetCardInGraveyard 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 3 with TargetCardInGraveyard

use of mage.target.common.TargetCardInGraveyard 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 4 with TargetCardInGraveyard

use of mage.target.common.TargetCardInGraveyard in project mage by magefree.

the class KotoseTheSilentSpiderWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller == null || card == null) {
        return false;
    }
    Player opponent = game.getPlayer(card.getOwnerId());
    if (opponent == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source);
    String exileName = CardUtil.getSourceName(game, source);
    controller.moveCardsToExile(card, source, game, true, exileId, exileName);
    Cards cards = new CardsImpl();
    FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
    filter.add(new NamePredicate(card.getName()));
    TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
    cards.addAll(targetCardInGraveyard.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
    TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
    cards.addAll(targetCardInHand.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, opponent.getId());
    target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
    Set<Card> cardSet = cards.getCards(game);
    controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
    opponent.shuffleLibrary(source, game);
    cardSet.add(card);
    if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
        return true;
    }
    KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
    for (Card exiledCard : cardSet) {
        CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) mage.cards(mage.cards) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 5 with TargetCardInGraveyard

use of mage.target.common.TargetCardInGraveyard in project mage by magefree.

the class RescueFromTheUnderworldReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    DelayedTriggeredAbility delayedAbility = ability.copy();
    delayedAbility.getTargets().addAll(source.getTargets());
    for (Effect effect : delayedAbility.getEffects()) {
        effect.getTargetPointer().init(game, source);
    }
    // add the sacrificed creature as target
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
            TargetCardInGraveyard target = new TargetCardInGraveyard();
            for (Permanent permanent : sacCost.getPermanents()) {
                target.add(permanent.getId(), game);
                delayedAbility.getTargets().add(target);
            }
        }
    }
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) Effect(mage.abilities.effects.Effect) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Aggregations

TargetCardInGraveyard (mage.target.common.TargetCardInGraveyard)59 Player (mage.players.Player)54 Card (mage.cards.Card)32 FilterCard (mage.filter.FilterCard)24 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)23 UUID (java.util.UUID)21 FilterCreatureCard (mage.filter.common.FilterCreatureCard)17 Permanent (mage.game.permanent.Permanent)14 Target (mage.target.Target)14 TargetCard (mage.target.TargetCard)12 MageObject (mage.MageObject)8 Ability (mage.abilities.Ability)6 CardsImpl (mage.cards.CardsImpl)6 CardIdPredicate (mage.filter.predicate.mageobject.CardIdPredicate)5 TargetPlayer (mage.target.TargetPlayer)5 HashSet (java.util.HashSet)4 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)4 Cards (mage.cards.Cards)4 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)4 TargetOpponent (mage.target.common.TargetOpponent)4