Search in sources :

Example 1 with DamageDoneWatcher

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;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) DamageDoneWatcher(mage.watchers.common.DamageDoneWatcher) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Aggregations

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 DamageDoneWatcher (mage.watchers.common.DamageDoneWatcher)1