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 @Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) {
CastSpellYourLastTurnWatcher watcher = (CastSpellYourLastTurnWatcher) game.getState().getWatchers().get(CastSpellYourLastTurnWatcher.class.getSimpleName()); CastSpellYourLastTurnWatcher watcher = (CastSpellYourLastTurnWatcher) game.getState().getWatchers().get(CastSpellYourLastTurnWatcher.class.getSimpleName());
if (watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) { if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) {
return true; return true;
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.watchers.common; package mage.watchers.common;
import mage.MageObjectReference;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; 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> amountOfSpellsCastOnPrevTurn = new HashMap<>();
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>(); private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();
private final Map<UUID, Integer> activePlayer = new HashMap<>(); private UUID lastActivePlayer = null;
public CastSpellYourLastTurnWatcher() { public CastSpellYourLastTurnWatcher() {
super(CastSpellYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME); super(CastSpellYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
@ -61,12 +60,10 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
activePlayer.clear(); lastActivePlayer = game.getActivePlayerId();
activePlayer.putIfAbsent(game.getActivePlayerId(), 0);
if (event.getType() == GameEvent.EventType.SPELL_CAST) { if (event.getType() == GameEvent.EventType.SPELL_CAST) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
UUID activePlayerId = game.getActivePlayerId(); if (playerId != null && lastActivePlayer != null && playerId == lastActivePlayer) {
if (playerId != null && activePlayerId != null && playerId == activePlayerId) {
amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0); amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1); amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
} }
@ -75,16 +72,15 @@ public class CastSpellYourLastTurnWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
for (Entry<UUID, Integer> entry : amountOfSpellsCastOnPrevTurn.entrySet()) { if (amountOfSpellsCastOnPrevTurn != null
for (Entry<UUID, Integer> entry2 : activePlayer.entrySet()) { && lastActivePlayer != null
if (entry2.getKey() == entry.getKey()) { && amountOfSpellsCastOnPrevTurn.get(lastActivePlayer) != null) {
amountOfSpellsCastOnPrevTurn.remove(entry.getKey()); amountOfSpellsCastOnPrevTurn.remove(lastActivePlayer);
}
}
} }
amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn); amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn);
amountOfSpellsCastOnCurrentTurn.clear(); amountOfSpellsCastOnCurrentTurn.clear();
activePlayer.clear(); lastActivePlayer = null;
} }
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) { public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {

View file

@ -8,8 +8,6 @@ package mage.watchers.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.game.Game; 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>> enteringBattlefield = new HashMap<>();
private final HashMap<UUID, List<Permanent>> enteringBattlefieldLastTurn = 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() { public PermanentsEnteredBattlefieldYourLastTurnWatcher() {
super(PermanentsEnteredBattlefieldYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME); super(PermanentsEnteredBattlefieldYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
@ -44,8 +42,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
activePlayer.clear(); lastActivePlayer = game.getActivePlayerId();
activePlayer.putIfAbsent(game.getActivePlayerId(), 0);
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent perm = game.getPermanentEntering(event.getTargetId()); Permanent perm = game.getPermanentEntering(event.getTargetId());
@ -67,16 +64,14 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
for (Entry<UUID, List<Permanent>> entry : enteringBattlefieldLastTurn.entrySet()) { if (enteringBattlefieldLastTurn != null
for (Entry<UUID, Integer> entry2 : activePlayer.entrySet()) { && lastActivePlayer != null
if (entry2.getKey() == entry.getKey()) { && enteringBattlefieldLastTurn.get(lastActivePlayer) != null) {
enteringBattlefieldLastTurn.remove(entry.getKey()); enteringBattlefieldLastTurn.remove(lastActivePlayer);
}
}
} }
enteringBattlefieldLastTurn.putAll(enteringBattlefield); enteringBattlefieldLastTurn.putAll(enteringBattlefield);
enteringBattlefield.clear(); enteringBattlefield.clear();
activePlayer.clear(); lastActivePlayer = null;
} }
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) { public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {