use of mage.filter.common.FilterLandCard in project mage by magefree.
the class ElvishRejuvenatorEffect 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();
cards.addAll(controller.getLibrary().getTopCards(game, 5));
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(0, 1, Zone.LIBRARY, new FilterLandCard("land card to put on the battlefield"));
if (controller.choose(Outcome.PutCardInPlay, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
}
}
if (!cards.isEmpty()) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
}
}
return true;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class HiredGiantEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Player> playersThatSearched = new HashSet<>(1);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!playerId.equals(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null && player.chooseUse(Outcome.PutCreatureInPlay, "Search your library for a land card and put it onto the battlefield?", source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
if (player.searchLibrary(target, source, game)) {
Card targetCard = player.getLibrary().getCard(target.getFirstTarget(), game);
if (targetCard != null) {
player.moveCards(targetCard, Zone.BATTLEFIELD, source, game);
playersThatSearched.add(player);
}
}
}
}
}
for (Player player : playersThatSearched) {
player.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class RoilingTerrainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetedLand = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetedLand != null) {
targetedLand.destroy(source, game, true);
Player targetController = game.getPlayer(targetedLand.getControllerId());
if (targetController != null) {
int landsInGraveyard = targetController.getGraveyard().count(new FilterLandCard(), game);
targetController.damage(landsInGraveyard, source.getSourceId(), source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class TemptWithDiscoveryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<UUID> playersShuffle = new LinkedHashSet<>();
playersShuffle.add(controller.getId());
TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
if (controller.searchLibrary(target, source, game)) {
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
int opponentsUsedSearch = 0;
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
if (opponent.chooseUse(outcome, "Search your library for a land card and put it onto the battlefield?", source, game)) {
target.clearChosen();
opponentsUsedSearch++;
playersShuffle.add(playerId);
if (opponent.searchLibrary(target, source, game)) {
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
opponent.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
}
}
}
if (opponentsUsedSearch > 0) {
target = new TargetCardInLibrary(0, opponentsUsedSearch, new FilterLandCard());
if (controller.searchLibrary(target, source, game)) {
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
}
for (UUID playerId : playersShuffle) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class MoxDiamondReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetCardInHand target = new TargetCardInHand(new FilterLandCard());
Cost cost = new DiscardTargetCost(target);
if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(outcome, "Discard land? (Otherwise Mox Diamond goes to graveyard)", source, game) && player.chooseTarget(Outcome.Discard, target, source, game)) {
player.discard(game.getCard(target.getFirstTarget()), false, source, game);
return false;
} else {
Permanent permanent = game.getPermanentEntering(event.getTargetId());
if (permanent != null) {
player.moveCards(permanent, Zone.GRAVEYARD, source, game);
}
return true;
}
}
return false;
}
Aggregations