use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.
the class GlobalRuinDestroyLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<UUID> lands = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (SubType landName : Arrays.stream(SubType.values()).filter(p -> p.getSubTypeSet() == SubTypeSet.BasicLandType).collect(Collectors.toSet())) {
FilterControlledLandPermanent filter = new FilterControlledLandPermanent(landName + " you control");
filter.add(landName.getPredicate());
Target target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(outcome, target, source, game);
lands.add(target.getFirstTarget());
}
}
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_LAND, game)) {
if (!lands.contains(permanent.getId())) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.
the class ShivanWumpusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
super.apply(game, source);
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.
the class JalumGrifterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getTargets().get(0).getFirstTarget());
if (controller != null && opponent != null) {
List<Card> shellGamePile = new ArrayList<>();
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
sourceCard = sourceCard.copy();
sourceCard.setFaceDown(true, game);
shellGamePile.add(sourceCard);
game.informPlayers(controller.getLogName() + " turns " + sourceCard.getLogName() + " face down");
}
Target target = new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent(), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
}
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
card = card.copy();
card.setFaceDown(true, game);
shellGamePile.add(card);
game.informPlayers(controller.getLogName() + " turns " + card.getLogName() + " face down");
}
}
if (shellGamePile.isEmpty()) {
return true;
}
Collections.shuffle(shellGamePile);
game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
CardsImpl cards = new CardsImpl();
cards.addAll(shellGamePile);
if (opponent.choose(Outcome.Sacrifice, cards, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
card.setFaceDown(false, game);
game.informPlayers(opponent.getLogName() + " reveals " + card.getLogName());
if (card.getId().equals(sourceCard.getId())) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
sourcePermanent.sacrifice(source, game);
}
} else {
Permanent permanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (permanent != null) {
permanent.destroy(source, game, false);
}
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.
the class CantBlockUnlessControllerControlsMoreLandsEffect method canAttack.
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
if (defenderId == null) {
return true;
}
UUID defendingPlayerId;
Player defender = game.getPlayer(defenderId);
if (defender == null) {
Permanent permanent = game.getPermanent(defenderId);
if (permanent != null) {
defendingPlayerId = permanent.getControllerId();
} else {
return false;
}
} else {
defendingPlayerId = defenderId;
}
if (defendingPlayerId != null) {
return game.getBattlefield().countAll(new FilterControlledLandPermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledLandPermanent(), defendingPlayerId, game);
} else {
return true;
}
}
use of mage.filter.common.FilterControlledLandPermanent in project mage by magefree.
the class SweepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterPermanent filter = new FilterControlledLandPermanent("any number of " + sweepSubtype + "s you control");
filter.add(sweepSubtype.getPredicate());
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
game.getState().setValue(CardUtil.getCardZoneString("sweep", source.getSourceId(), game), target.getTargets().size());
controller.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
}
return true;
}
return false;
}
Aggregations