@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
if (controller != null || !choice.chooseFriendOrFoe(controller, source, game)) {
return false;
}
FilterCreaturePermanent filterToTap = new FilterCreaturePermanent();
for (Player player : choice.getFoes()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("untapped creature you control");
filter.add(Predicates.not(TappedPredicate.instance));
filter.add(new ControllerIdPredicate(player.getId()));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
filterToTap.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
}
}
for (Player player : choice.getFriends()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(player.getId()));
new AddCountersAllEffect(CounterType.P1P1.createInstance(), filter).apply(game, source);
filterToTap.add(Predicates.not(new ControllerIdPredicate(player.getId())));
}
return new TapAllEffect(filterToTap).apply(game, source);
}
}