Merge pull request #3261 from ingmargoudt/fix_cyclediscardwatcher

fix for shadow of the grave
This commit is contained in:
LevelX2 2017-04-28 11:04:24 +02:00 committed by GitHub
commit 7f1da83783
2 changed files with 9 additions and 11 deletions

View file

@ -86,12 +86,11 @@ class ShadowOfTheGraveEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get("CardsCycledOrDiscardedThisTurnWatcher"); CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get("CardsCycledOrDiscardedThisTurnWatcher");
if (controller != null if (controller != null
&& watcher != null && watcher != null) {
&& watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()) != null) {
for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) { for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) {
if (card != null if (card != null
&& game.getState().getZone(card.getId()) == Zone.GRAVEYARD //must come from their graveyard && game.getState().getZone(card.getId()) == Zone.GRAVEYARD //must come from their graveyard
&& card.getOwnerId() == controller.getId()) { //confirm ownership && card.getOwnerId().equals(controller.getId())) { //confirm ownership
controller.moveCardToHandWithInfo(card, source.getId(), game, true); controller.moveCardToHandWithInfo(card, source.getId(), game, true);
} }
} }

View file

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
@ -41,12 +42,12 @@ import mage.watchers.Watcher;
/** /**
* Stores cards that were cycled or discarded by any player this turn. * Stores cards that were cycled or discarded by any player this turn.
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher { public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
private final Map<UUID, Cards> cycledOrDiscardedCardsThisTurn = new HashMap<>(); private final Map<UUID, Cards> cycledOrDiscardedCardsThisTurn = new HashMap<>();
Cards cards = new CardsImpl();
public CardsCycledOrDiscardedThisTurnWatcher() { public CardsCycledOrDiscardedThisTurnWatcher() {
super("CardsCycledOrDiscardedThisTurnWatcher", WatcherScope.GAME); super("CardsCycledOrDiscardedThisTurnWatcher", WatcherScope.GAME);
@ -67,24 +68,22 @@ public class CardsCycledOrDiscardedThisTurnWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.CYCLED_CARD if (event.getType() == GameEvent.EventType.CYCLED_CARD
|| event.getType() == GameEvent.EventType.DISCARDED_CARD) { || event.getType() == GameEvent.EventType.DISCARDED_CARD) {
UUID playerId = event.getPlayerId(); UUID playerId = event.getPlayerId();
if (playerId != null if (playerId != null
&& game.getCard(event.getTargetId()) != null) { && game.getCard(event.getTargetId()) != null) {
Card card = game.getCard(event.getTargetId()); Card card = game.getCard(event.getTargetId());
cards.add(card); getCardsCycledOrDiscardedThisTurn(playerId).add(card);
cycledOrDiscardedCardsThisTurn.putIfAbsent(playerId, cards);
} }
} }
} }
public Cards getCardsCycledOrDiscardedThisTurn(UUID playerId) { public Cards getCardsCycledOrDiscardedThisTurn(UUID playerId) {
return cycledOrDiscardedCardsThisTurn.get(playerId); return cycledOrDiscardedCardsThisTurn.getOrDefault(playerId, new CardsImpl());
} }
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
cycledOrDiscardedCardsThisTurn.clear(); cycledOrDiscardedCardsThisTurn.clear();
cards.clear();
} }
@Override @Override