watcher now saves info for all players. Rule modifying effect does the check

This commit is contained in:
Max Lebedev 2016-09-10 15:23:09 -04:00
parent 7ce878a315
commit c3e8903105

View file

@ -78,17 +78,17 @@ public class LeovoldEmissaryOfTrest extends CardImpl {
class LeovoldEmissaryOfTrestWatcher extends Watcher { class LeovoldEmissaryOfTrestWatcher extends Watcher {
private final HashSet<UUID> opponentsThatDrewCard; private final HashSet<UUID> playersThatDrewCard;
public LeovoldEmissaryOfTrestWatcher() { public LeovoldEmissaryOfTrestWatcher() {
super("DrewCard", WatcherScope.GAME); super("DrewCard", WatcherScope.GAME);
this.opponentsThatDrewCard = new HashSet<>(); this.playersThatDrewCard = new HashSet<>();
} }
public LeovoldEmissaryOfTrestWatcher(final LeovoldEmissaryOfTrestWatcher watcher) { public LeovoldEmissaryOfTrestWatcher(final LeovoldEmissaryOfTrestWatcher watcher) {
super(watcher); super(watcher);
this.opponentsThatDrewCard = new HashSet<>(); this.playersThatDrewCard = new HashSet<>();
opponentsThatDrewCard.addAll(watcher.opponentsThatDrewCard); playersThatDrewCard.addAll(watcher.playersThatDrewCard);
} }
@Override @Override
@ -99,8 +99,8 @@ class LeovoldEmissaryOfTrestWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DREW_CARD ) { if (event.getType() == GameEvent.EventType.DREW_CARD ) {
if (!event.getPlayerId().equals(this.getControllerId()) && !opponentsThatDrewCard.contains(event.getPlayerId())) { if (!playersThatDrewCard.contains(event.getPlayerId())) {
opponentsThatDrewCard.add(event.getPlayerId()); playersThatDrewCard.add(event.getPlayerId());
} }
} }
} }
@ -108,11 +108,11 @@ class LeovoldEmissaryOfTrestWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
opponentsThatDrewCard.clear(); playersThatDrewCard.clear();
} }
public boolean hasPlayerDrewCardThisTurn(UUID playerId) { public boolean hasPlayerDrewCardThisTurn(UUID playerId) {
return opponentsThatDrewCard.contains(playerId); return playersThatDrewCard.contains(playerId);
} }
} }
@ -146,7 +146,10 @@ class LeovoldEmissaryOfTrestEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
LeovoldEmissaryOfTrestWatcher watcher = (LeovoldEmissaryOfTrestWatcher) game.getState().getWatchers().get("DrewCard"); LeovoldEmissaryOfTrestWatcher watcher = (LeovoldEmissaryOfTrestWatcher) game.getState().getWatchers().get("DrewCard");
return watcher != null && watcher.hasPlayerDrewCardThisTurn(event.getPlayerId());
Player controller = game.getPlayer(source.getControllerId());
return watcher != null && controller != null && watcher.hasPlayerDrewCardThisTurn(event.getPlayerId())
&& game.isOpponent(controller, event.getPlayerId());
} }
} }