use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class SunderingTitanDestroyLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Set<UUID> lands = new HashSet<>();
if (controller != null && sourcePermanent != null) {
for (SubType landName : SubType.getBasicLands()) {
FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
filter.add(landName.getPredicate());
Target target = new TargetLandPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.chooseTarget(outcome, target, source, game);
lands.add(target.getFirstTarget());
}
}
if (!lands.isEmpty()) {
int destroyedLands = 0;
for (UUID landId : lands) {
Permanent land = game.getPermanent(landId);
if (land != null) {
if (land.destroy(source, game, false)) {
destroyedLands++;
}
}
}
game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
}
return true;
}
return false;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class TraverseTheOutlandsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterLandPermanent filter = new FilterLandPermanent();
filter.add(TargetController.YOU.getControllerPredicate());
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game);
int amount = 0;
for (Permanent creature : creatures) {
int power = creature.getPower().getValue();
if (amount < power) {
amount = power;
}
}
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class JolraelEmpressOfBeastsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
FilterPermanent filter = new FilterLandPermanent();
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
game.addEffect(new BecomesCreatureAllEffect(new CreatureToken(3, 3), "lands", filter, Duration.EndOfTurn, false), source);
return true;
}
return false;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class DefendersForestCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for (CombatGroup group : game.getCombat().getGroups()) {
if (group.getAttackers().contains(sourceAbility.getSourceId())) {
UUID defenderId = group.getDefenderId();
if (group.isDefenderIsPlaneswalker()) {
Permanent permanent = game.getPermanent(defenderId);
if (permanent != null) {
defenderId = permanent.getControllerId();
}
}
FilterLandPermanent filter = new FilterLandPermanent("forest");
filter.add(SubType.FOREST.getPredicate());
return game.getBattlefield().countAll(filter, defenderId, game);
}
}
return 0;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class SasayasEssenceManaEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
Mana producedMana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && producedMana != null && permanent != null) {
FilterPermanent filter = new FilterLandPermanent();
filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
filter.add(new NamePredicate(permanent.getName()));
int count = game.getBattlefield().countAll(filter, controller.getId(), game);
if (count > 0) {
if (producedMana.getBlack() > 0) {
netMana.add(Mana.BlackMana(count));
}
if (producedMana.getRed() > 0) {
netMana.add(Mana.RedMana(count));
}
if (producedMana.getBlue() > 0) {
netMana.add(Mana.BlueMana(count));
}
if (producedMana.getGreen() > 0) {
netMana.add(Mana.GreenMana(count));
}
if (producedMana.getWhite() > 0) {
netMana.add(Mana.WhiteMana(count));
}
if (producedMana.getColorless() > 0) {
netMana.add(Mana.ColorlessMana(count));
}
}
}
return netMana;
}
Aggregations