From fc7cdcdc4e382ed35d68ca22723539133f7ff62e Mon Sep 17 00:00:00 2001 From: igoudt Date: Fri, 12 May 2017 09:24:56 +0200 Subject: [PATCH] small rewrite in the creaturesDiedWatcher --- .../common/CreaturesDiedThisTurnCount.java | 2 +- .../watchers/common/CreaturesDiedWatcher.java | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesDiedThisTurnCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesDiedThisTurnCount.java index 98672401b8..fbeee8f1c4 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesDiedThisTurnCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesDiedThisTurnCount.java @@ -40,7 +40,7 @@ public class CreaturesDiedThisTurnCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - CreaturesDiedWatcher watcher = (CreaturesDiedWatcher)game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); + CreaturesDiedWatcher watcher = (CreaturesDiedWatcher) game.getState().getWatchers().get(CreaturesDiedWatcher.class.getSimpleName()); if (watcher != null) { return watcher.getAmountOfCreaturesDiesThisTurn(); } diff --git a/Mage/src/main/java/mage/watchers/common/CreaturesDiedWatcher.java b/Mage/src/main/java/mage/watchers/common/CreaturesDiedWatcher.java index c3537ac1e7..dfcf40f640 100644 --- a/Mage/src/main/java/mage/watchers/common/CreaturesDiedWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CreaturesDiedWatcher.java @@ -29,6 +29,8 @@ package mage.watchers.common; import java.util.HashMap; import java.util.UUID; +import java.util.stream.Collectors; + import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; @@ -36,12 +38,10 @@ import mage.game.events.ZoneChangeEvent; import mage.watchers.Watcher; /** - * * @author LevelX2 */ public class CreaturesDiedWatcher extends Watcher { - private int amountOfCreaturesThatDied; private final HashMap amountOfCreaturesThatDiedByController = new HashMap<>(); public CreaturesDiedWatcher() { @@ -50,7 +50,6 @@ public class CreaturesDiedWatcher extends Watcher { public CreaturesDiedWatcher(final CreaturesDiedWatcher watcher) { super(watcher); - this.amountOfCreaturesThatDied = watcher.amountOfCreaturesThatDied; this.amountOfCreaturesThatDiedByController.putAll(watcher.amountOfCreaturesThatDiedByController); } @@ -61,11 +60,7 @@ public class CreaturesDiedWatcher extends Watcher { if (zEvent.isDiesEvent() && zEvent.getTarget() != null && zEvent.getTarget().isCreature()) { - amountOfCreaturesThatDied++; - int amount = 0; - if (amountOfCreaturesThatDiedByController.containsKey(zEvent.getTarget().getControllerId())) { - amount = amountOfCreaturesThatDiedByController.get(zEvent.getTarget().getControllerId()); - } + int amount = getAmountOfCreaturesDiesThisTurn(zEvent.getTarget().getControllerId()); amountOfCreaturesThatDiedByController.put(zEvent.getTarget().getControllerId(), amount + 1); } } @@ -73,13 +68,9 @@ public class CreaturesDiedWatcher extends Watcher { @Override public void reset() { - amountOfCreaturesThatDied = 0; amountOfCreaturesThatDiedByController.clear(); } - public int getAmountOfCreaturesDiesThisTurn() { - return amountOfCreaturesThatDied; - } public int getAmountOfCreaturesDiesThisTurn(UUID playerId) { return amountOfCreaturesThatDiedByController.getOrDefault(playerId, 0); @@ -90,4 +81,7 @@ public class CreaturesDiedWatcher extends Watcher { return new CreaturesDiedWatcher(this); } + public int getAmountOfCreaturesDiesThisTurn() { + return amountOfCreaturesThatDiedByController.values().stream().mapToInt(x -> x).sum(); + } }