use of mage.filter.common.FilterLandPermanent 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;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class PowerSinkCounterUnlessPaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && controller != null && sourceObject != null) {
int amount = source.getManaCostsToPay().getX();
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, true);
if (player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " to prevent?", source, game)) {
if (cost.pay(source, game, source, player.getId(), false)) {
game.informPlayers(sourceObject.getName() + ": additional cost was paid");
return true;
}
}
game.informPlayers(sourceObject.getName() + ": additional cost wasn't paid - countering " + spell.getName());
// Counter target spell unless its controller pays {X}
game.getStack().counter(source.getFirstTarget(), source, game);
// that player taps all lands with mana abilities they control...
List<Permanent> lands = game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game);
for (Permanent land : lands) {
Abilities<Ability> landAbilities = land.getAbilities();
for (Ability ability : landAbilities) {
if (ability instanceof ActivatedManaAbilityImpl) {
land.tap(source, game);
break;
}
}
}
// ...and empties their mana pool
player.getManaPool().emptyPool(game);
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class KeldonFirebombersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> landsToSacrifice = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int amount = game.getBattlefield().getAllActivePermanents(filter, playerId, game).size() - 3;
if (amount > 0) {
FilterLandPermanent playerFilter = filter.copy();
playerFilter.add(new ControllerIdPredicate(playerId));
Target target = new TargetLandPermanent(amount, amount, playerFilter, true);
player.choose(outcome.Sacrifice, target, source.getSourceId(), game);
for (UUID landId : target.getTargets()) {
Permanent land = game.getPermanent(landId);
if (land != null) {
landsToSacrifice.add(land);
}
}
}
}
}
for (Permanent land : landsToSacrifice) {
land.sacrifice(source, game);
}
return true;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class SurveyorsScopeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int numberOfLands = 0;
int ownLands = game.getBattlefield().countAll(new FilterLandPermanent(), controller.getId(), game);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!playerId.equals(controller.getId())) {
if (game.getBattlefield().countAll(new FilterLandPermanent(), playerId, game) > ownLands + 1) {
numberOfLands++;
}
}
}
game.informPlayers("Surveyor's Scope: X = " + numberOfLands);
// 10/17/2013 If no players control at least two more lands than you when the ability resolves, you'll still search and shuffle your library.
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(0, numberOfLands, StaticFilters.FILTER_CARD_BASIC_LAND)).apply(game, source);
}
return false;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class ThoughtsOfRuinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int amount = controller.getHand().size();
if (amount > 0) {
List<Permanent> permanentsToSacrifice = new ArrayList<>();
// select all lands to sacrifice
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int lands = game.getState().getBattlefield().countAll(filter, playerId, game);
if (amount >= lands) {
permanentsToSacrifice.addAll(game.getState().getBattlefield().getAllActivePermanents(filter, playerId, game));
} else {
FilterLandPermanent playerFilter = filter.copy();
playerFilter.add(new ControllerIdPredicate(playerId));
Target target = new TargetLandPermanent(amount, amount, playerFilter, true);
player.choose(outcome, target, source.getSourceId(), game);
for (UUID landId : target.getTargets()) {
Permanent permanent = game.getPermanent(landId);
if (permanent != null) {
permanentsToSacrifice.add(permanent);
}
}
}
}
}
// sacrifice all lands
for (Permanent permanent : permanentsToSacrifice) {
permanent.sacrifice(source, game);
}
}
}
return false;
}
Aggregations