use of mage.target.common.TargetLandPermanent in project mage by magefree.
the class KudzuEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent kudzu = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (kudzu != null) {
Permanent enchantedLand = game.getPermanentOrLKIBattlefield(kudzu.getAttachedTo());
Player controller = game.getPlayer(source.getControllerId());
if (enchantedLand != null && controller != null) {
Player landsController = game.getPlayer(enchantedLand.getControllerId());
if (game.getState().getZone(enchantedLand.getId()) == Zone.BATTLEFIELD) {
// if 2 or more Kudzu's were on a land
enchantedLand.destroy(source, game, false);
}
if (!game.getBattlefield().getAllActivePermanents(CardType.LAND, game).isEmpty()) {
// lands are available on the battlefield
Target target = new TargetLandPermanent();
// not a target, it is chosen
target.setNotTarget(true);
Card kudzuCard = game.getCard(source.getSourceId());
if (kudzuCard != null && landsController != null) {
if (landsController.choose(Outcome.Detriment, target, source.getId(), game)) {
if (target.getFirstTarget() != null) {
Permanent landChosen = game.getPermanent(target.getFirstTarget());
if (landChosen != null) {
for (Target targetTest : kudzuCard.getSpellAbility().getTargets()) {
if (targetTest.getFilter().match(landChosen, game)) {
landChosen.addAttachment(kudzu.getId(), source, game);
}
}
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetLandPermanent in project mage by magefree.
the class OrcishSettlersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int amount = source.getManaCostsToPay().getX();
if (amount == 0) {
return false;
}
TargetLandPermanent target = new TargetLandPermanent(amount);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DestroyPermanent, target, source.getSourceId(), game)) {
List<UUID> targets = target.getTargets();
targets.forEach((landId) -> {
Permanent land = game.getPermanent(landId);
if (land != null) {
land.destroy(source, game, false);
}
});
return true;
}
return false;
}
use of mage.target.common.TargetLandPermanent in project mage by magefree.
the class PlanarOverlayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> lands = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (SubType landName : SubType.getBasicLands()) {
FilterLandPermanent filter = new FilterLandPermanent(landName + " to return to hand");
filter.add(landName.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
Target target = new TargetLandPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(outcome, target, source, game);
lands.add(game.getPermanent(target.getFirstTarget()));
}
}
}
}
controller.moveCards(lands, Zone.HAND, source, game);
return true;
}
return false;
}
use of mage.target.common.TargetLandPermanent in project mage by magefree.
the class CantPlayLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
game.getState().getPlayersInRange(source.getControllerId(), game).forEach((playerId) -> {
Player player = game.getPlayer(playerId);
if (player != null) {
int lands = game.getBattlefield().countAll(new FilterControlledLandPermanent(), playerId, game);
TargetLandPermanent target = new TargetLandPermanent(Integer.min(5, lands));
target.setNotTarget(true);
target.setRequired(true);
player.chooseTarget(outcome.Benefit, target, source, game);
game.getBattlefield().getAllActivePermanents(new FilterControlledLandPermanent(), playerId, game).stream().filter((land) -> (!target.getTargets().contains(land.getId()))).forEachOrdered((land) -> {
land.sacrifice(source, game);
});
}
});
return true;
}
use of mage.target.common.TargetLandPermanent in project mage by magefree.
the class DemonicHordesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent demonicHordes = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && demonicHordes != null) {
StringBuilder sb = new StringBuilder(cost.getText()).append('?');
if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
sb.insert(0, "Pay ");
}
if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
demonicHordes.tap(source, game);
Target choiceOpponent = new TargetOpponent();
choiceOpponent.setNotTarget(true);
FilterLandPermanent filterLand = new FilterLandPermanent();
filterLand.add(new ControllerIdPredicate(source.getControllerId()));
if (controller.choose(Outcome.Neutral, choiceOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(choiceOpponent.getFirstTarget());
if (opponent != null) {
Target chosenLand = new TargetLandPermanent(filterLand);
chosenLand.setNotTarget(true);
if (opponent.chooseTarget(Outcome.Sacrifice, chosenLand, source, game)) {
Permanent land = game.getPermanent(chosenLand.getFirstTarget());
if (land != null) {
land.sacrifice(source, game);
}
}
}
return true;
}
}
return false;
}
Aggregations