Search in sources :

Example 1 with TargetCardInOpponentsGraveyard

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

the class DiluvianPrimordialReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (Target target : source.getTargets()) {
            if (target instanceof TargetCardInOpponentsGraveyard) {
                Card targetCard = game.getCard(target.getFirstTarget());
                if (targetCard != null) {
                    if (controller.chooseUse(Outcome.PlayForFree, "Cast " + targetCard.getLogName() + '?', source, game)) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + targetCard.getId(), Boolean.TRUE);
                        Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(targetCard, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + targetCard.getId(), null);
                        if (cardWasCast) {
                            ContinuousEffect effect = new DiluvianPrimordialReplacementEffect();
                            effect.setTargetPointer(new FixedTarget(targetCard.getId(), game.getState().getZoneChangeCounter(targetCard.getId())));
                            game.addEffect(effect, source);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) ApprovingObject(mage.ApprovingObject) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with TargetCardInOpponentsGraveyard

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

the class SufferThePastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCard filter = new FilterCard("card in target player's graveyard");
    int numberExiled = 0;
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer != null) {
        int numberToTarget = Math.min(targetPlayer.getGraveyard().size(), source.getManaCostsToPay().getX());
        TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(numberToTarget, numberToTarget, filter);
        if (you != null) {
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                if (!target.getTargets().isEmpty()) {
                    List<UUID> targets = target.getTargets();
                    for (UUID targetId : targets) {
                        Card card = game.getCard(targetId);
                        if (card != null) {
                            card.moveToExile(id, "Suffer the Past", source, game);
                            numberExiled++;
                        }
                    }
                    you.gainLife(numberExiled, game, source);
                    targetPlayer.loseLife(numberExiled, game, source, false);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 3 with TargetCardInOpponentsGraveyard

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

the class ConditionalAsThoughTest method test_PlayFromNotOwnHandZoneTargetEffect.

@Test
public void test_PlayFromNotOwnHandZoneTargetEffect() {
    Ability ability = new SimpleActivatedAbility(Zone.ALL, new ConditionalAsThoughEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.GRAVEYARD, TargetController.ANY, Duration.EndOfTurn), new PermanentsOnTheBattlefieldCondition(StaticFilters.FILTER_PERMANENT_CREATURE, ComparisonType.MORE_THAN, 0)).setText("allow target cast"), new ManaCostsImpl("{R}"));
    ability.addTarget(new TargetCardInOpponentsGraveyard(StaticFilters.FILTER_CARD));
    addCustomCardWithAbility("play any opponent hand", playerA, ability);
    addCard(Zone.HAND, playerA, "Grizzly Bears");
    addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion");
    addCard(Zone.GRAVEYARD, playerB, "Lightning Bolt");
    addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5);
    // can't play grave before
    checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Grizzly Bears", true);
    checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Silvercoat Lion", false);
    checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", false);
    // activate target effect
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{R}: Allow");
    addTarget(playerA, "Lightning Bolt");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    // can't play grave after but without good condition
    checkPlayableAbility("after bad", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Grizzly Bears", true);
    checkPlayableAbility("after bad", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Silvercoat Lion", false);
    checkPlayableAbility("after bad", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", false);
    // make good condition - now we can play opponent's grave
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Grizzly Bears");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
    checkPlayableAbility("after good", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Grizzly Bears", false);
    checkPlayableAbility("after good", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Silvercoat Lion", false);
    checkPlayableAbility("after good", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Lightning Bolt", true);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
    execute();
    assertAllCommandsUsed();
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) ConditionalAsThoughEffect(mage.abilities.decorator.ConditionalAsThoughEffect) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) PermanentsOnTheBattlefieldCondition(mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Test(org.junit.Test)

Example 4 with TargetCardInOpponentsGraveyard

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

the class SkullsnatcherTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
        FilterCard filter = new FilterCard("up to two target cards from that player's graveyard");
        filter.add(new OwnerIdPredicate(event.getPlayerId()));
        filter.setMessage("up to two cards in " + game.getPlayer(event.getTargetId()).getLogName() + "'s graveyard");
        this.getTargets().clear();
        this.addTarget(new TargetCardInOpponentsGraveyard(0, 2, filter));
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard)

Example 5 with TargetCardInOpponentsGraveyard

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

the class KingNarfisBetrayalSecondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID controllerId = source.getControllerId();
    Player controller = game.getPlayer(controllerId);
    if (controller == null) {
        return false;
    }
    millEffect.apply(game, source);
    // Controller graveyard
    if (controller.getGraveyard().count(filter, game) != 0) {
        if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from your graveyard?", source, game)) {
            TargetCard target = new TargetCardInYourGraveyard(filter);
            target.setNotTarget(true);
            if (controller.chooseTarget(outcome, controller.getGraveyard(), target, source, game)) {
                controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
            }
        }
    }
    // Each opponent's graveyard
    for (UUID opponentId : game.getOpponents(controllerId)) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        if (opponent.getGraveyard().count(filter, game) != 0) {
            if (controller.chooseUse(outcome, "Exile a creature or planeswalker card from " + opponent.getName() + "'s graveyard?", source, game)) {
                TargetCard target = new TargetCardInOpponentsGraveyard(1, 1, filter, true);
                target.setNotTarget(true);
                if (controller.chooseTarget(outcome, opponent.getGraveyard(), target, source, game)) {
                    controller.moveCardsToExile(game.getCard(target.getFirstTarget()), source, game, true, CardUtil.getCardExileZoneId(game, source), CardUtil.createObjectRealtedWindowTitle(source, game, null));
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID)

Aggregations

TargetCardInOpponentsGraveyard (mage.target.common.TargetCardInOpponentsGraveyard)6 FilterCard (mage.filter.FilterCard)4 Player (mage.players.Player)4 Card (mage.cards.Card)3 UUID (java.util.UUID)2 ApprovingObject (mage.ApprovingObject)1 Ability (mage.abilities.Ability)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 PermanentsOnTheBattlefieldCondition (mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition)1 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)1 ConditionalAsThoughEffect (mage.abilities.decorator.ConditionalAsThoughEffect)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 PlayFromNotOwnHandZoneTargetEffect (mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect)1 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 Target (mage.target.Target)1 TargetCard (mage.target.TargetCard)1 TargetPlayer (mage.target.TargetPlayer)1 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)1