use of mage.watchers.common.DamageDoneWatcher in project mage by magefree.
the class PetrifiedWoodKinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
DamageDoneWatcher watcher = game.getState().getWatcher(DamageDoneWatcher.class);
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (player == null || watcher == null || permanent == null) {
return false;
}
// the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
int amount = 0;
for (UUID opponentId : game.getOpponents(player.getId())) {
MageObjectReference mor = new MageObjectReference(opponentId, game);
amount += watcher.getDamagedObjects().getOrDefault(mor, 0);
}
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
return true;
}
Aggregations