use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class HomingLightningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
if (targetPermanent == null) {
return false;
}
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()));
}
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
if (creature != null) {
creature.damage(4, source.getSourceId(), source, game, false, true);
}
}
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class MasterOfTheVeilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
}
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(pred);
game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class SlipperyBogbonderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent creature = game.getPermanent(source.getFirstTarget());
FilterPermanent filterPermanent = filter.copy();
filterPermanent.add(Predicates.not(new PermanentIdPredicate(source.getFirstTarget())));
if (player == null || creature == null || game.getBattlefield().count(filterPermanent, source.getSourceId(), source.getControllerId(), game) < 1) {
return false;
}
TargetPermanent target = new TargetPermanent(0, Integer.MAX_VALUE, filterPermanent, true);
player.choose(outcome, target, source.getSourceId(), game);
List<Permanent> permanents = target.getTargets().stream().filter(uuid -> !creature.getId().equals(uuid)).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
if (permanents.isEmpty()) {
return false;
}
Map<UUID, Map<String, Integer>> counterMap = new HashMap<>();
for (Permanent permanent : permanents) {
permanent.getCounters(game).entrySet().stream().forEach(entry -> {
int num = player.getAmount(0, entry.getValue().getCount(), "Choose how many " + entry.getKey() + " counters to remove from " + permanent.getLogName(), game);
counterMap.computeIfAbsent(permanent.getId(), x -> new HashMap<>()).put(entry.getKey(), num);
});
}
for (Permanent permanent : permanents) {
counterMap.get(permanent.getId()).entrySet().stream().filter(entry -> entry.getValue() > 0).map(entry -> CounterType.findByName(entry.getKey()).createInstance(entry.getValue())).filter(counter -> creature.addCounters(counter, source.getControllerId(), source, game)).forEach(counter -> permanent.removeCounters(counter, source, game));
}
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class WeaverOfLiesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
}
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(pred);
game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
return true;
}
use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.
the class InquisitorsSnareEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(source.getFirstTarget());
if (targetCreature != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new PermanentIdPredicate(targetCreature.getId()));
game.addEffect(new PreventAllDamageByAllPermanentsEffect(filter, Duration.EndOfTurn, false), source);
if (targetCreature.getColor(game).isBlack() || targetCreature.getColor(game).isRed()) {
return targetCreature.destroy(source, game, false);
}
}
return false;
}
Aggregations