From c2fba3099b925d8f84c45d4a50e05ba010b7c9a5 Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Mon, 24 Dec 2012 12:20:06 -0600 Subject: [PATCH] - Fixed Whiplash Trap for multiplayer using Lavaball Trap tech. I never play multiplayer, so didn't worry about it. --- .../src/mage/sets/zendikar/WhiplashTrap.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Mage.Sets/src/mage/sets/zendikar/WhiplashTrap.java b/Mage.Sets/src/mage/sets/zendikar/WhiplashTrap.java index 7a70db3d7e..0ccf2ecc95 100644 --- a/Mage.Sets/src/mage/sets/zendikar/WhiplashTrap.java +++ b/Mage.Sets/src/mage/sets/zendikar/WhiplashTrap.java @@ -27,6 +27,8 @@ */ package mage.sets.zendikar; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import mage.Constants; import mage.Constants.CardType; @@ -78,7 +80,7 @@ public class WhiplashTrap extends CardImpl { class WhiplashTrapWatcher extends WatcherImpl { - int creatureCount; + private Map amountOfCreaturesPlayedThisTurn = new HashMap(); public WhiplashTrapWatcher() { super("WhiplashTrapWatcher", Constants.WatcherScope.GAME); @@ -86,6 +88,9 @@ class WhiplashTrapWatcher extends WatcherImpl { public WhiplashTrapWatcher(final WhiplashTrapWatcher watcher) { super(watcher); + for (Map.Entry entry : watcher.amountOfCreaturesPlayedThisTurn.entrySet()) { + amountOfCreaturesPlayedThisTurn.put(entry.getKey(), entry.getValue()); + } } @Override @@ -95,25 +100,35 @@ class WhiplashTrapWatcher extends WatcherImpl { @Override public void watch(GameEvent event, Game game) { - if (condition == true) { // no need to check - condition has already occured - return; - } if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getToZone() == Constants.Zone.BATTLEFIELD) { Permanent perm = game.getPermanent(event.getTargetId()); - if (perm.getCardType().contains(CardType.CREATURE) && !perm.getControllerId().equals(controllerId)) { - creatureCount += 1; - if (creatureCount >= 2) { - condition = true; + if (perm.getCardType().contains(CardType.CREATURE)) { + Integer amount = amountOfCreaturesPlayedThisTurn.get(perm.getControllerId()); + if (amount == null) { + amount = Integer.valueOf(1); + } else { + ++amount; } + amountOfCreaturesPlayedThisTurn.put(perm.getControllerId(), amount); } } } + + public int maxCreaturesAnOpponentPlayedThisTurn(UUID playerId, Game game) { + int maxCreatures = 0; + for (UUID opponentId : game.getOpponents(playerId)) { + Integer amount = amountOfCreaturesPlayedThisTurn.get(opponentId); + if (amount != null && amount.intValue() > maxCreatures) { + maxCreatures = amount.intValue(); + } + } + return maxCreatures; + } @Override public void reset() { super.reset(); - condition = false; - creatureCount = 0; + amountOfCreaturesPlayedThisTurn.clear(); } } @@ -136,7 +151,7 @@ class WhiplashAlternativeCost extends AlternativeCostImpl= 2) { return true; } return false;