Returning cards to hand fixing.

This commit is contained in:
marcins78@gmail.com
2011-10-14 13:23:54 +00:00
parent 8b016bbe6b
commit 2a345430fb

View File

@@ -10,7 +10,10 @@ import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.EffectResult;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ReturnCardsToHandEffect extends AbstractEffect {
private PhysicalCard _source;
@@ -40,32 +43,45 @@ public class ReturnCardsToHandEffect extends AbstractEffect {
protected FullEffectResult playEffectReturningResult(LotroGame game) {
Collection<PhysicalCard> cardsToReturnToHand = Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _filter);
Set<PhysicalCard> discardedCards = new HashSet<PhysicalCard>();
// Preparation, figure out, what's going where...
Set<PhysicalCard> stoppedAffecting = new HashSet<PhysicalCard>();
Set<PhysicalCard> discardedFromPlay = new HashSet<PhysicalCard>();
Set<PhysicalCard> removedFromZone = new HashSet<PhysicalCard>();
for (PhysicalCard card : cardsToReturnToHand) {
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(card);
GameState gameState = game.getGameState();
gameState.stopAffecting(card);
gameState.removeCardsFromZone(Collections.singleton(card));
gameState.addCardToZone(card, Zone.HAND);
stoppedAffecting.add(card);
stoppedAffecting.addAll(attachedCards);
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card);
for (PhysicalCard attachedCard : attachedCards) {
discardedCards.add(attachedCard);
discardedFromPlay.addAll(attachedCards);
gameState.stopAffecting(attachedCard);
gameState.removeCardsFromZone(Collections.singleton(attachedCard));
gameState.addCardToZone(attachedCard, Zone.DISCARD);
}
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
for (PhysicalCard stackedCard : stackedCards) {
gameState.removeCardsFromZone(Collections.singleton(stackedCard));
gameState.addCardToZone(stackedCard, Zone.DISCARD);
}
removedFromZone.add(card);
removedFromZone.addAll(attachedCards);
removedFromZone.addAll(game.getGameState().getStackedCards(card));
}
if (discardedCards.size() > 0)
return new FullEffectResult(new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)}, true, true);
discardedFromPlay.removeAll(cardsToReturnToHand);
// Now do the actual things
GameState gameState = game.getGameState();
// Stop affecting
for (PhysicalCard card : stoppedAffecting)
gameState.stopAffecting(card);
// Remove from their zone
gameState.removeCardsFromZone(removedFromZone);
// Add cards to hand
for (PhysicalCard card : cardsToReturnToHand)
gameState.addCardToZone(card, Zone.HAND);
// Add discarded to discard
for (PhysicalCard card : discardedFromPlay)
gameState.addCardToZone(card, Zone.DISCARD);
if (discardedFromPlay.size() > 0)
return new FullEffectResult(new EffectResult[]{new DiscardCardsFromPlayResult(discardedFromPlay)}, true, true);
return new FullEffectResult(null, true, true);
}