use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ExtractFromDarknessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseTarget(outcome, target, source, game)) {
return controller.moveCards(game.getCard(target.getFirstTarget()), Zone.BATTLEFIELD, source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ReapIntellectEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (targetPlayer != null && sourceObject != null && controller != null) {
// reveal hand of target player
targetPlayer.revealCards(sourceObject.getName(), targetPlayer.getHand(), game);
// Chose cards to exile from hand
Cards exiledCards = new CardsImpl();
int xCost = Math.min(source.getManaCostsToPay().getX(), targetPlayer.getHand().size());
TargetCard target = new TargetCard(0, xCost, Zone.HAND, filterNonLands);
target.setNotTarget(true);
controller.chooseTarget(Outcome.Benefit, targetPlayer.getHand(), target, source, game);
for (UUID cardId : target.getTargets()) {
Card chosenCard = game.getCard(cardId);
if (chosenCard != null) {
controller.moveCardToExileWithInfo(chosenCard, null, "", source, game, Zone.HAND, true);
exiledCards.add(chosenCard);
}
}
// 4/15/2013 If you don't exile any cards from the player's hand, you don't search that player's library
if (!exiledCards.isEmpty()) {
// Building a card filter with all names
List<NamePredicate> names = new ArrayList<>();
FilterCard filterNamedCards = new FilterCard();
for (Card card : exiledCards.getCards(game)) {
String nameToSearch = CardUtil.getCardNameForSameNameSearch(card);
if (exiledCards.size() == 1) {
filterNamedCards.add(new NamePredicate(nameToSearch));
} else {
names.add(new NamePredicate(nameToSearch));
}
}
if (exiledCards.size() > 1) {
filterNamedCards.add(Predicates.or(names));
}
// search cards in graveyard
TargetCardInGraveyard targetCardsGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filterNamedCards);
controller.chooseTarget(outcome, targetPlayer.getGraveyard(), targetCardsGraveyard, source, game);
for (UUID cardId : targetCardsGraveyard.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
}
}
// search cards in hand
TargetCard targetCardsHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
controller.chooseTarget(Outcome.Benefit, targetPlayer.getGraveyard(), targetCardsHand, source, game);
for (UUID cardId : targetCardsHand.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.HAND, true);
}
}
// search cards in Library
TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
for (UUID cardId : targetCardsLibrary.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard 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;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ShadowKinApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
cards.addAll(player.millCards(3, source, game));
}
}
if (cards.isEmpty()) {
return false;
}
TargetCardInGraveyard target = new TargetCardInGraveyard(0, 1, StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
controller.choose(outcome, cards, target, game);
Card card = game.getCard(target.getFirstTarget());
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
if (card == null || sourcePermanent == null) {
return true;
}
controller.moveCards(card, Zone.EXILED, source, game);
Permanent blueprint = new PermanentCard(card, source.getControllerId(), game);
blueprint.assignNewId();
CopyApplier applier = new ShadowKinApplier();
applier.apply(game, blueprint, source, sourcePermanent.getId());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, blueprint, sourcePermanent.getId());
copyEffect.newId();
copyEffect.setApplier(applier);
Ability newAbility = source.copy();
copyEffect.init(newAbility, game);
game.addEffect(copyEffect, newAbility);
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class SpellweaverVoluteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && sourcePermanent.getAttachedTo() != null) {
Card enchantedCard = game.getCard(sourcePermanent.getAttachedTo());
if (enchantedCard != null && game.getState().getZone(enchantedCard.getId()) == Zone.GRAVEYARD) {
Player ownerEnchanted = game.getPlayer(enchantedCard.getOwnerId());
if (ownerEnchanted != null && controller.chooseUse(Outcome.Copy, "Create a copy of " + enchantedCard.getName() + '?', source, game)) {
Card copiedCard = game.copyCard(enchantedCard, source, source.getControllerId());
if (copiedCard != null) {
controller.getGraveyard().add(copiedCard);
game.getState().setZone(copiedCard.getId(), Zone.GRAVEYARD);
if (controller.chooseUse(Outcome.PlayForFree, "Cast the copied card without paying mana cost?", source, game)) {
if (copiedCard.getSpellAbility() != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
}
if (controller.moveCards(enchantedCard, Zone.EXILED, source, game)) {
FilterCard filter = new FilterCard("instant card in a graveyard");
filter.add(CardType.INSTANT.getPredicate());
TargetCardInGraveyard auraTarget = new TargetCardInGraveyard(filter);
if (auraTarget.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Benefit, auraTarget, source.getSourceId(), game);
Card newAuraTarget = game.getCard(auraTarget.getFirstTarget());
if (newAuraTarget != null) {
if (enchantedCard.getId().equals(newAuraTarget.getId())) {
} else if (newAuraTarget.addAttachment(sourcePermanent.getId(), source, game)) {
game.informPlayers(sourcePermanent.getLogName() + " was attached to " + newAuraTarget.getLogName());
}
}
}
}
}
}
}
}
}
return true;
}
return false;
}
Aggregations