Add Arboria (LEG)

This commit is contained in:
spjspj 2017-12-21 17:07:08 +11:00
parent 38272a6dde
commit 3055bac004
3 changed files with 17 additions and 26 deletions

View file

@ -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;
}

View file

@ -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<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<>();
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();
private final Map<UUID, Integer> 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<UUID, Integer> entry : amountOfSpellsCastOnPrevTurn.entrySet()) {
for (Entry<UUID, Integer> 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) {

View file

@ -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<UUID, List<Permanent>> enteringBattlefield = new HashMap<>();
private final HashMap<UUID, List<Permanent>> enteringBattlefieldLastTurn = new HashMap<>();
private final Map<UUID, Integer> 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<UUID, List<Permanent>> entry : enteringBattlefieldLastTurn.entrySet()) {
for (Entry<UUID, Integer> 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<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {