forked from External/mage
52 lines
1.4 KiB
Java
52 lines
1.4 KiB
Java
package mage.watchers.common;
|
|
|
|
import mage.constants.WatcherScope;
|
|
import mage.game.Game;
|
|
import mage.game.events.GameEvent;
|
|
import mage.watchers.Watcher;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
/*
|
|
* Counts the number of times the planar die has been rolled per player per turn
|
|
* This watcher is automatically started in gameImpl.init for each game
|
|
*
|
|
* @author spjspj
|
|
*/
|
|
public class PlanarRollWatcher extends Watcher {
|
|
|
|
private final Map<UUID, Integer> numberTimesPlanarDieRolled = new HashMap<>();
|
|
|
|
public PlanarRollWatcher() {
|
|
super(WatcherScope.GAME);
|
|
}
|
|
|
|
@Override
|
|
public void watch(GameEvent event, Game game) {
|
|
if (event.getType() == GameEvent.EventType.PLANAR_DIE_ROLLED) {
|
|
UUID playerId = event.getPlayerId();
|
|
if (playerId != null) {
|
|
Integer amount = numberTimesPlanarDieRolled.get(playerId);
|
|
if (amount == null) {
|
|
amount = 1;
|
|
} else {
|
|
amount++;
|
|
}
|
|
numberTimesPlanarDieRolled.put(playerId, amount);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int getNumberTimesPlanarDieRolled(UUID playerId) {
|
|
return numberTimesPlanarDieRolled.getOrDefault(playerId, 0);
|
|
}
|
|
|
|
@Override
|
|
public void reset() {
|
|
super.reset();
|
|
numberTimesPlanarDieRolled.clear();
|
|
}
|
|
|
|
}
|