use of mage.filter.common.FilterLandCard in project mage by magefree.
the class AnimistsAwakeningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl();
int xValue = source.getManaCostsToPay().getX();
cards.addAll(controller.getLibrary().getTopCards(game, xValue));
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), cards, game);
Set<Card> toBattlefield = new LinkedHashSet<>();
for (Card card : cards.getCards(new FilterLandCard(), source.getSourceId(), source.getControllerId(), game)) {
cards.remove(card);
toBattlefield.add(card);
}
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, true, false, true, null);
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
if (SpellMasteryCondition.instance.apply(game, source)) {
for (Card card : toBattlefield) {
Permanent land = game.getPermanent(card.getId());
if (land != null) {
land.untap(game);
}
}
}
}
return true;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class OblivionSowerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
/*
8/25/2015: Oblivion Sower's ability allows you to put any land cards the player owns from exile onto the battlefield, regardless of how those cards were exiled.
8/25/2015: Cards that are face down in exile have no characteristics. Such cards can't be put onto the battlefield with Oblivion Sower's ability.
*/
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
FilterLandCard filter = new FilterLandCard();
filter.add(new OwnerIdPredicate(targetPlayer.getId()));
filter.add(Predicates.not(FaceDownPredicate.instance));
Cards exiledCards = new CardsImpl();
exiledCards.addAll(game.getExile().getAllCards(game));
Cards exiledLands = new CardsImpl();
exiledLands.addAll(exiledCards.getCards(filter, source.getSourceId(), controller.getId(), game));
if (!exiledLands.isEmpty() && controller.chooseUse(outcome, "Put lands into play?", source, game)) {
FilterCard filterToPlay = new FilterCard("land" + (exiledLands.size() > 1 ? "s" : "") + " from exile owned by " + targetPlayer.getName() + " to put into play under your control");
TargetCard targetCards = new TargetCard(0, exiledLands.size(), Zone.EXILED, filterToPlay);
if (controller.chooseTarget(outcome, exiledLands, targetCards, source, game)) {
controller.moveCards(new CardsImpl(targetCards.getTargets()), Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class TheGreatAuroraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, List<Permanent>> permanentsOwned = new HashMap<>();
Collection<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
for (Permanent permanent : permanents) {
List<Permanent> list = permanentsOwned.computeIfAbsent(permanent.getOwnerId(), k -> new ArrayList<>());
list.add(permanent);
}
// shuffle permanents and hand cards into owner's library
Map<UUID, Integer> permanentsCount = new HashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int handCards = player.getHand().size();
player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
List<Permanent> list = permanentsOwned.remove(player.getId());
permanentsCount.put(playerId, handCards + (list != null ? list.size() : 0));
if (list != null) {
for (Permanent permanent : list) {
player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, true, true);
}
player.shuffleLibrary(source, game);
}
}
}
// so effects from creatures that were on the battlefield won't trigger from draw or put into play
game.getState().processAction(game);
// Draw cards
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = permanentsCount.get(playerId);
if (count > 0) {
player.drawCards(count, source, game);
}
}
}
// put lands onto the battlefield
Cards toBattlefield = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, new FilterLandCard("put any number of land cards from your hand onto the battlefield"));
player.chooseTarget(Outcome.PutLandInPlay, player.getHand(), target, source, game);
toBattlefield.addAll(target.getTargets());
}
}
return controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class GerrardsVerdictEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
controller.gainLife(targetPlayer.discard(2, false, false, source, game).count(new FilterLandCard(), game) * 3, game, source);
return true;
}
return false;
}
use of mage.filter.common.FilterLandCard in project mage by magefree.
the class OreskosExplorerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
int controllerLands = game.getBattlefield().countAll(new FilterLandPermanent(), controller.getId(), game);
int landsToSearch = 0;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!playerId.equals(controller.getId())) {
if (controllerLands < game.getBattlefield().countAll(new FilterLandPermanent(), playerId, game)) {
landsToSearch++;
}
}
}
if (landsToSearch > 0) {
FilterLandCard filterPlains = new FilterLandCard("up to " + landsToSearch + " Plains cards");
filterPlains.add(SubType.PLAINS.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(0, landsToSearch, filterPlains);
if (controller.searchLibrary(target, source, game, controller.getId())) {
Cards cards = new CardsImpl(target.getTargets());
controller.revealCards(sourceObject.getIdName(), cards, game);
controller.moveCards(cards.getCards(game), Zone.HAND, source, game);
}
}
controller.shuffleLibrary(source, game);
return true;
}
Aggregations