merge MorbidWatcher with CreaturesDiedWatcher

This commit is contained in:
xenohedron 2023-11-30 00:11:10 -05:00
parent 1ac4fe4e4a
commit 1f764515f6
4 changed files with 6 additions and 38 deletions

View file

@ -3,7 +3,7 @@ package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.watchers.common.MorbidWatcher;
import mage.watchers.common.CreaturesDiedWatcher;
/**
* @author nantuko
@ -13,7 +13,7 @@ public enum MorbidCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
MorbidWatcher watcher = game.getState().getWatcher(MorbidWatcher.class);
CreaturesDiedWatcher watcher = game.getState().getWatcher(CreaturesDiedWatcher.class);
return watcher != null && watcher.conditionMet();
}

View file

@ -1336,7 +1336,6 @@ public abstract class GameImpl implements Game {
public void initGameDefaultWatchers() {
List<Watcher> newWatchers = new ArrayList<>();
newWatchers.add(new MorbidWatcher());
newWatchers.add(new CastSpellLastTurnWatcher());
newWatchers.add(new PlayerLostLifeWatcher());
newWatchers.add(new BlockedAttackerWatcher());

View file

@ -19,6 +19,9 @@ public class CreaturesDiedWatcher extends Watcher {
private final Map<UUID, Integer> amountOfCreaturesThatDiedByController = new HashMap<>();
private final Map<UUID, Integer> amountOfCreaturesThatDiedByOwner = new HashMap<>();
/**
* Game default watcher
*/
public CreaturesDiedWatcher() {
super(WatcherScope.GAME);
}
@ -34,6 +37,7 @@ public class CreaturesDiedWatcher extends Watcher {
|| !zEvent.getTarget().isCreature(game)) {
return;
}
condition = true;
amountOfCreaturesThatDiedByController.compute(zEvent.getTarget().getControllerId(), CardUtil::setOrIncrementValue);
amountOfCreaturesThatDiedByOwner.compute(zEvent.getTarget().getOwnerId(), CardUtil::setOrIncrementValue);
}

View file

@ -1,35 +0,0 @@
package mage.watchers.common;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.watchers.Watcher;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MorbidWatcher extends Watcher {
/**
* Game default watcher
* TODO: Merge with CreaturesDiedWatcher
*/
public MorbidWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (condition) {
return;
}
if (event.getType() == GameEvent.EventType.ZONE_CHANGE
&& ((ZoneChangeEvent) event).isDiesEvent()
&& ((ZoneChangeEvent) event).getTarget().isCreature(game)) {
condition = true;
}
}
}