use of mage.filter.FilterPermanent in project mage by magefree.
the class LilianaOfTheVeilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
TargetPermanent target = new TargetPermanent(0, count, new FilterPermanent("permanents to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
target.setRequired(false);
if (player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(targetPlayer.getId())) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to sacrifice.", pile1, pile2, game);
if (choice) {
sacrificePermanents(pile1, game, source);
} else {
sacrificePermanents(pile2, game, source);
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class MistOfStagnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(game.getActivePlayerId());
if (activePlayer != null) {
int cardsInGrave = activePlayer.getGraveyard().size();
if (cardsInGrave > 0) {
TargetPermanent target = new TargetPermanent(cardsInGrave, cardsInGrave, new FilterPermanent("permanents to untap"), true);
activePlayer.chooseTarget(outcome, target, source, game);
for (UUID oneTarget : target.getTargets()) {
Permanent p = game.getPermanent(oneTarget);
if (p != null) {
p.untap(game);
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class MythosOfSnapdaxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean conditionMet = condition.apply(game, source);
List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
Set<UUID> toKeep = new HashSet();
for (Player player : playerList) {
for (CardType cardType : cardTypes) {
String message = cardType.toString().equals("Artifact") ? "an " : "a ";
message += cardType.toString().toLowerCase(Locale.ENGLISH);
message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
FilterPermanent filter = new FilterNonlandPermanent(message);
filter.add(cardType.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (conditionMet) {
controller.choose(outcome, target, source.getSourceId(), game);
} else {
player.choose(outcome, target, source.getSourceId(), game);
}
toKeep.add(target.getFirstTarget());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
if (permanent == null || toKeep.contains(permanent.getId())) {
continue;
}
permanent.sacrifice(source, game);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SharedAnimosityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent == null) {
return false;
}
FilterPermanent filter = new FilterAttackingCreature();
filter.add(new SharesCreatureTypePredicate(permanent));
filter.add(AnotherPredicate.instance);
int count = game.getBattlefield().count(filter, permanent.getId(), source.getControllerId(), game);
if (count > 0) {
game.addEffect(new BoostTargetEffect(count, 0, Duration.EndOfTurn).setTargetPointer(new FixedTarget(permanent, game)), source);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SwayOfTheStarsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
player.moveCards(player.getGraveyard(), Zone.LIBRARY, source, game);
FilterPermanent filter = new FilterPermanent();
filter.add(new OwnerIdPredicate(playerId));
Cards toLib = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), source.getSourceId(), game)) {
toLib.add(permanent);
}
player.shuffleCardsToLibrary(toLib, game, source);
}
}
}
return true;
}
Aggregations