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.EffectResult;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult; 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 { public class ReturnCardsToHandEffect extends AbstractEffect {
private PhysicalCard _source; private PhysicalCard _source;
@@ -40,32 +43,45 @@ public class ReturnCardsToHandEffect extends AbstractEffect {
protected FullEffectResult playEffectReturningResult(LotroGame game) { protected FullEffectResult playEffectReturningResult(LotroGame game) {
Collection<PhysicalCard> cardsToReturnToHand = Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _filter); 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) { for (PhysicalCard card : cardsToReturnToHand) {
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(card);
GameState gameState = game.getGameState(); stoppedAffecting.add(card);
gameState.stopAffecting(card); stoppedAffecting.addAll(attachedCards);
gameState.removeCardsFromZone(Collections.singleton(card));
gameState.addCardToZone(card, Zone.HAND);
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card); discardedFromPlay.addAll(attachedCards);
for (PhysicalCard attachedCard : attachedCards) {
discardedCards.add(attachedCard);
gameState.stopAffecting(attachedCard); removedFromZone.add(card);
gameState.removeCardsFromZone(Collections.singleton(attachedCard)); removedFromZone.addAll(attachedCards);
gameState.addCardToZone(attachedCard, Zone.DISCARD); removedFromZone.addAll(game.getGameState().getStackedCards(card));
}
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
for (PhysicalCard stackedCard : stackedCards) {
gameState.removeCardsFromZone(Collections.singleton(stackedCard));
gameState.addCardToZone(stackedCard, Zone.DISCARD);
}
} }
if (discardedCards.size() > 0) discardedFromPlay.removeAll(cardsToReturnToHand);
return new FullEffectResult(new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)}, true, true);
// 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); return new FullEffectResult(null, true, true);
} }