use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class DistantMemoriesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary();
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
controller.shuffleLibrary(source, game);
StringBuilder sb = new StringBuilder();
sb.append("Have ").append(controller.getLogName()).append(" put ").append(card.getName());
sb.append(" in their hand? If none of their opponents says yes, they will draw three cards.");
boolean putInHand = false;
Set<UUID> opponents = game.getOpponents(source.getControllerId());
for (UUID opponentUuid : opponents) {
Player opponent = game.getPlayer(opponentUuid);
if (opponent != null) {
if (opponent.chooseUse(Outcome.Detriment, sb.toString(), source, game)) {
putInHand = true;
game.informPlayers(opponent.getLogName() + " decides to put the selected card into the player's hand.");
} else {
game.informPlayers(opponent.getLogName() + " decides to leave the card in exile.");
}
}
}
if (putInHand) {
controller.moveCards(card, Zone.HAND, source, game);
} else {
controller.drawCards(3, source, game);
}
return true;
}
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class EmergentUltimatumTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInLibrary targetCardInLibrary = new EmergentUltimatumTarget();
targetCardInLibrary.setNotTarget(true);
boolean searched = player.searchLibrary(targetCardInLibrary, source, game);
Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
player.moveCards(cards, Zone.EXILED, source, game);
if (cards.isEmpty()) {
if (searched) {
player.shuffleLibrary(source, game);
}
return false;
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
player.choose(outcome, targetOpponent, source.getSourceId(), game);
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
if (searched) {
player.shuffleLibrary(source, game);
}
return false;
}
TargetCardInExile targetCardInExile = new TargetCardInExile(StaticFilters.FILTER_CARD);
targetCardInExile.setNotTarget(true);
opponent.choose(outcome, cards, targetCardInExile, game);
Card toShuffle = game.getCard(targetCardInExile.getFirstTarget());
if (toShuffle != null) {
player.putCardsOnBottomOfLibrary(toShuffle, game, source, false);
player.shuffleLibrary(source, game);
cards.remove(toShuffle);
}
while (!cards.isEmpty()) {
if (!player.chooseUse(Outcome.PlayForFree, "Cast an exiled card without paying its mana cost?", source, game)) {
break;
}
targetCardInExile.clearChosen();
if (!player.choose(Outcome.PlayForFree, cards, targetCardInExile, game)) {
continue;
}
Card card = game.getCard(targetCardInExile.getFirstTarget());
if (card == null) {
continue;
}
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
// remove on non cast too (infinite freeze fix)
cards.remove(card);
if (cardWasCast) {
cards.remove(card);
} else {
game.informPlayer(player, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class EmergentSequenceWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// put land
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND_A);
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
Permanent permanent = null;
if (card != null) {
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
permanent = game.getPermanent(target.getFirstTarget());
}
player.shuffleLibrary(source, game);
if (permanent == null) {
return true;
}
// boost land
game.addEffect(new BecomesCreatureTargetEffect(new FractalToken(), false, true, Duration.Custom).setTargetPointer(new FixedTarget(permanent, game)), source);
// rules
// The last sentence of Emergent Sequence’s ability counts the land it put onto the battlefield.
// (2021-04-16)
// no ETB yet, so add +1 manually
int amount = 1 + EmergentSequenceWatcher.getAmount(source.getControllerId(), game);
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class GhostQuarterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
Player controller = game.getPlayer(permanent.getControllerId());
if (controller != null && controller.chooseUse(Outcome.PutLandInPlay, "Search for a basic land, put it onto the battlefield, and then shuffle?", source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class HibernationsEndEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null && player != null) {
int newConvertedCost = sourcePermanent.getCounters(game).getCount("age");
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
return new SearchLibraryPutInPlayEffect(target).apply(game, source);
}
return false;
}
Aggregations