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());
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get("CardsCycledOrDiscardedThisTurnWatcher");
if (controller != null
&& watcher != null
&& watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()) != null) {
&& watcher != null) {
for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) {
if (card != null
&& 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);
}
}

View file

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