From 3055bac004a802518d65405f8495c58ee9e99e19 Mon Sep 17 00:00:00 2001 From: spjspj Date: Thu, 21 Dec 2017 17:07:08 +1100 Subject: [PATCH] Add Arboria (LEG) --- Mage.Sets/src/mage/cards/a/Arboria.java | 2 +- .../common/CastSpellYourLastTurnWatcher.java | 22 ++++++++----------- ...EnteredBattlefieldYourLastTurnWatcher.java | 19 ++++++---------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/Arboria.java b/Mage.Sets/src/mage/cards/a/Arboria.java index bfe5a2b154..31111aa155 100644 --- a/Mage.Sets/src/mage/cards/a/Arboria.java +++ b/Mage.Sets/src/mage/cards/a/Arboria.java @@ -87,7 +87,7 @@ class ArboriaEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { CastSpellYourLastTurnWatcher watcher = (CastSpellYourLastTurnWatcher) game.getState().getWatchers().get(CastSpellYourLastTurnWatcher.class.getSimpleName()); - if (watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) { + if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) { return true; } diff --git a/Mage/src/main/java/mage/watchers/common/CastSpellYourLastTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/CastSpellYourLastTurnWatcher.java index a9188dd13d..1a3ae1a5ca 100644 --- a/Mage/src/main/java/mage/watchers/common/CastSpellYourLastTurnWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CastSpellYourLastTurnWatcher.java @@ -27,7 +27,6 @@ */ package mage.watchers.common; -import mage.MageObjectReference; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; @@ -43,7 +42,7 @@ public class CastSpellYourLastTurnWatcher extends Watcher { private final Map amountOfSpellsCastOnPrevTurn = new HashMap<>(); private final Map amountOfSpellsCastOnCurrentTurn = new HashMap<>(); - private final Map activePlayer = new HashMap<>(); + private UUID lastActivePlayer = null; public CastSpellYourLastTurnWatcher() { super(CastSpellYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME); @@ -61,12 +60,10 @@ public class CastSpellYourLastTurnWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - activePlayer.clear(); - activePlayer.putIfAbsent(game.getActivePlayerId(), 0); + lastActivePlayer = game.getActivePlayerId(); if (event.getType() == GameEvent.EventType.SPELL_CAST) { UUID playerId = event.getPlayerId(); - UUID activePlayerId = game.getActivePlayerId(); - if (playerId != null && activePlayerId != null && playerId == activePlayerId) { + if (playerId != null && lastActivePlayer != null && playerId == lastActivePlayer) { amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0); amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1); } @@ -75,16 +72,15 @@ public class CastSpellYourLastTurnWatcher extends Watcher { @Override public void reset() { - for (Entry entry : amountOfSpellsCastOnPrevTurn.entrySet()) { - for (Entry entry2 : activePlayer.entrySet()) { - if (entry2.getKey() == entry.getKey()) { - amountOfSpellsCastOnPrevTurn.remove(entry.getKey()); - } - } + if (amountOfSpellsCastOnPrevTurn != null + && lastActivePlayer != null + && amountOfSpellsCastOnPrevTurn.get(lastActivePlayer) != null) { + amountOfSpellsCastOnPrevTurn.remove(lastActivePlayer); } + amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn); amountOfSpellsCastOnCurrentTurn.clear(); - activePlayer.clear(); + lastActivePlayer = null; } public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) { diff --git a/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldYourLastTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldYourLastTurnWatcher.java index d2718d52a7..857bdd81ed 100644 --- a/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldYourLastTurnWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/PermanentsEnteredBattlefieldYourLastTurnWatcher.java @@ -8,8 +8,6 @@ package mage.watchers.common; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.UUID; import mage.constants.WatcherScope; import mage.game.Game; @@ -25,7 +23,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher { private final HashMap> enteringBattlefield = new HashMap<>(); private final HashMap> enteringBattlefieldLastTurn = new HashMap<>(); - private final Map activePlayer = new HashMap<>(); + private UUID lastActivePlayer = null; public PermanentsEnteredBattlefieldYourLastTurnWatcher() { super(PermanentsEnteredBattlefieldYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME); @@ -44,8 +42,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - activePlayer.clear(); - activePlayer.putIfAbsent(game.getActivePlayerId(), 0); + lastActivePlayer = game.getActivePlayerId(); if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { Permanent perm = game.getPermanentEntering(event.getTargetId()); @@ -67,16 +64,14 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher { @Override public void reset() { - for (Entry> entry : enteringBattlefieldLastTurn.entrySet()) { - for (Entry entry2 : activePlayer.entrySet()) { - if (entry2.getKey() == entry.getKey()) { - enteringBattlefieldLastTurn.remove(entry.getKey()); - } - } + if (enteringBattlefieldLastTurn != null + && lastActivePlayer != null + && enteringBattlefieldLastTurn.get(lastActivePlayer) != null) { + enteringBattlefieldLastTurn.remove(lastActivePlayer); } enteringBattlefieldLastTurn.putAll(enteringBattlefield); enteringBattlefield.clear(); - activePlayer.clear(); + lastActivePlayer = null; } public List getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {