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;
}
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;
}
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();
}
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;
}
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;
}
Aggregations