}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
int affectedTargets = 0;
for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
if (counter != null) {
Counter newCounter = counter.copy();
newCounter.add(amount.calculate(game, source, this));
int before = permanent.getCounters().getCount(counter.getName());
permanent.addCounters(newCounter, game);
int numberAdded = permanent.getCounters().getCount(counter.getName()) - before;
affectedTargets ++;
game.informPlayers(sourceObject.getLogName() +": "+ controller.getName()+ " puts " +
numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
}
} else {
Player player = game.getPlayer(uuid);
if (player != null) {
Counter newCounter = counter.copy();
newCounter.add(amount.calculate(game, source, this));
player.addCounters(newCounter, game);
affectedTargets ++;
game.informPlayers(new StringBuilder(sourceObject.getLogName()).append(": ")
.append(controller.getName()).append(" puts ")
.append(counter.getCount()).append(" ").append(counter.getName().toLowerCase())
.append(" counter on ").append(player.getName()).toString());
}
}