use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class RegnasSanctionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (!choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
FilterPermanent filterToTap = new FilterCreaturePermanent();
for (Player player : choice.getFoes()) {
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (game.getBattlefield().contains(filter, source, game, 1) && player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
filterToTap.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
}
}
choice.getFriends().stream().map(MageItem::getId).map(ControllerIdPredicate::new).map(Predicates::not).forEach(filterToTap::add);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (choice.getFriends().stream().map(MageItem::getId).anyMatch(permanent::isControlledBy)) {
permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
}
}
return new TapAllEffect(filterToTap).apply(game, source);
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class PreventAllDamageToAllEffect method createFilter.
private static FilterPermanentOrPlayer createFilter(FilterPermanent filterPermanent, FilterPlayer filterPlayer) {
String mes1 = filterPermanent != null ? filterPermanent.getMessage() : "";
String mes2 = filterPlayer != null ? filterPlayer.getMessage() : "";
String message;
if (!mes1.isEmpty() && !mes2.isEmpty()) {
message = mes1 + " and " + mes2;
} else {
message = mes1 + mes2;
}
FilterPermanent filter1 = filterPermanent;
if (filter1 == null) {
filter1 = new FilterPermanent();
// disable filter
filter1.add(new PermanentIdPredicate(UUID.randomUUID()));
}
FilterPlayer filter2 = filterPlayer;
if (filter2 == null) {
filter2 = new FilterPlayer();
// disable filter
filter2.add(new PlayerIdPredicate(UUID.randomUUID()));
}
return new FilterPermanentOrPlayer(message, filter1, filter2);
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class EchoingCourageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (targetPermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
ContinuousEffect effect = new BoostAllEffect(2, 2, Duration.EndOfTurn, filter, false);
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class ReturnToHandAllNamedPermanentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (controller != null && permanent != null) {
FilterPermanent filter = new FilterPermanent();
if (CardUtil.haveEmptyName(permanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(permanent.getId()));
} else {
filter.add(new NamePredicate(permanent.getName()));
}
Cards cardsToHand = new CardsImpl();
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
cardsToHand.add(perm);
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class FortunateFewEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<Permanent, Integer> chosenCards = new HashMap<>(2);
int maxCount = 0;
// Players each choose a legal permanent
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterNonlandPermanent filter = new FilterNonlandPermanent("a nonland permanent you don't control");
filter.add(Predicates.not(new ControllerIdPredicate(player.getId())));
for (Permanent chosenPerm : chosenCards.keySet()) {
filter.add(Predicates.not(new PermanentIdPredicate(chosenPerm.getId())));
}
Target target = new TargetNonlandPermanent(filter);
target.setNotTarget(true);
if (player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosenCards.put(permanent, 1);
game.informPlayers(player.getLogName() + " has chosen: " + permanent.getName());
}
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
if (!chosenCards.containsKey(permanent)) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
Aggregations