int amount = count.calculate(game, source, this);
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
amount = Math.min(amount, realCount);
Target target = new TargetControlledPermanent(amount, amount, filter, true);
//A spell or ability could have removed the only legal target this player
//had, if thats the case this ability should fizzle.
if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
boolean abilityApplied = false;
while (!target.isChosen() && target.canChoose(player.getId(), game) && player.isInGame()) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
for ( int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent((UUID)target.getTargets().get(idx));
if ( permanent != null ) {
abilityApplied |= permanent.sacrifice(source.getSourceId(), game);
}
}