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