Trying to fix the damned cards attached to cards.

This commit is contained in:
marcins78@gmail.com
2012-07-31 08:57:52 +00:00
parent 69e5aa92a1
commit bcbf1b5204
10 changed files with 98 additions and 118 deletions

View File

@@ -5,11 +5,12 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.effects.DiscardUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class PutCardFromPlayOnBottomOfDeckEffect extends AbstractEffect {
@@ -27,27 +28,25 @@ public class PutCardFromPlayOnBottomOfDeckEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(_physicalCard);
final List<PhysicalCard> stackedCards = game.getGameState().getStackedCards(_physicalCard);
Set<PhysicalCard> discardedCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> toGoToDiscardCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> removedFromZone = new HashSet<PhysicalCard>();
removedFromZone.add(_physicalCard);
removedFromZone.addAll(attachedCards);
removedFromZone.addAll(stackedCards);
DiscardUtils.cardsToChangeZones(game.getGameState(), Collections.singleton(_physicalCard), discardedCards, toGoToDiscardCards);
GameState gameState = game.getGameState();
gameState.removeCardsFromZone(_physicalCard.getOwner(), removedFromZone);
Set<PhysicalCard> removeFromPlay = new HashSet<PhysicalCard>(toGoToDiscardCards);
removeFromPlay.add(_physicalCard);
gameState.removeCardsFromZone(_physicalCard.getOwner(), removeFromPlay);
gameState.putCardOnBottomOfDeck(_physicalCard);
for (PhysicalCard attachedCard : attachedCards) {
gameState.addCardToZone(game, attachedCard, Zone.DISCARD);
for (PhysicalCard discardedCard : discardedCards) {
game.getActionsEnvironment().emitEffectResult(
new DiscardCardsFromPlayResult(attachedCard));
new DiscardCardsFromPlayResult(discardedCard));
}
for (PhysicalCard stackedCard : stackedCards)
gameState.addCardToZone(game, stackedCard, Zone.DISCARD);
for (PhysicalCard toGoToDiscardCard : toGoToDiscardCards)
gameState.addCardToZone(game, toGoToDiscardCard, Zone.DISCARD);
gameState.sendMessage(_physicalCard.getOwner() + " puts " + GameUtils.getCardLink(_physicalCard) + " from play on the bottom of deck");

View File

@@ -5,11 +5,12 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.effects.DiscardUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class PutCardFromPlayOnTopOfDeckEffect extends AbstractEffect {
@@ -27,27 +28,25 @@ public class PutCardFromPlayOnTopOfDeckEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(_physicalCard);
final List<PhysicalCard> stackedCards = game.getGameState().getStackedCards(_physicalCard);
Set<PhysicalCard> discardedCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> toGoToDiscardCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> removedFromZone = new HashSet<PhysicalCard>();
removedFromZone.add(_physicalCard);
removedFromZone.addAll(attachedCards);
removedFromZone.addAll(stackedCards);
DiscardUtils.cardsToChangeZones(game.getGameState(), Collections.singleton(_physicalCard), discardedCards, toGoToDiscardCards);
GameState gameState = game.getGameState();
gameState.removeCardsFromZone(_physicalCard.getOwner(), removedFromZone);
Set<PhysicalCard> removeFromPlay = new HashSet<PhysicalCard>(toGoToDiscardCards);
removeFromPlay.add(_physicalCard);
gameState.removeCardsFromZone(_physicalCard.getOwner(), removeFromPlay);
gameState.putCardOnTopOfDeck(_physicalCard);
for (PhysicalCard attachedCard : attachedCards) {
gameState.addCardToZone(game, attachedCard, Zone.DISCARD);
for (PhysicalCard discardedCard : discardedCards) {
game.getActionsEnvironment().emitEffectResult(
new DiscardCardsFromPlayResult(attachedCard));
new DiscardCardsFromPlayResult(discardedCard));
}
for (PhysicalCard stackedCard : stackedCards)
gameState.addCardToZone(game, stackedCard, Zone.DISCARD);
for (PhysicalCard toGoToDiscardCard : toGoToDiscardCards)
gameState.addCardToZone(game, toGoToDiscardCard, Zone.DISCARD);
gameState.sendMessage(_physicalCard.getOwner() + " puts " + GameUtils.getCardLink(_physicalCard) + " from play on the top of deck");

View File

@@ -8,6 +8,7 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.effects.DiscardUtils;
import com.gempukku.lotro.logic.modifiers.ModifiersQuerying;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.Effect;
@@ -16,7 +17,6 @@ import com.gempukku.lotro.logic.timing.results.ReturnCardsToHandResult;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ReturnCardsToHandEffect extends AbstractEffect {
@@ -52,40 +52,31 @@ public class ReturnCardsToHandEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
Collection<PhysicalCard> cardsToReturnToHand = Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _filter);
GameState gameState = game.getGameState();
Collection<PhysicalCard> cardsToReturnToHand = Filters.filterActive(gameState, game.getModifiersQuerying(), _filter);
// Preparation, figure out, what's going where...
Set<PhysicalCard> discardedFromPlay = new HashSet<PhysicalCard>();
Set<PhysicalCard> removedFromZone = new HashSet<PhysicalCard>();
Set<PhysicalCard> toGoToDiscardCards = new HashSet<PhysicalCard>();
for (PhysicalCard card : cardsToReturnToHand) {
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(card);
DiscardUtils.cardsToChangeZones(gameState, cardsToReturnToHand, discardedFromPlay, toGoToDiscardCards);
discardedFromPlay.addAll(attachedCards);
removedFromZone.add(card);
removedFromZone.addAll(attachedCards);
removedFromZone.addAll(game.getGameState().getStackedCards(card));
}
discardedFromPlay.removeAll(cardsToReturnToHand);
// Now do the actual things
GameState gameState = game.getGameState();
Set<PhysicalCard> cardsToRemoveFromZones = new HashSet<PhysicalCard>(toGoToDiscardCards);
cardsToRemoveFromZones.addAll(cardsToReturnToHand);
// Remove from their zone
gameState.removeCardsFromZone(_source.getOwner(), removedFromZone);
gameState.removeCardsFromZone(_source.getOwner(), cardsToRemoveFromZones);
// Add cards to hand
for (PhysicalCard card : cardsToReturnToHand)
gameState.addCardToZone(game, card, Zone.HAND);
// Add discarded to discard
for (PhysicalCard card : discardedFromPlay)
for (PhysicalCard card : toGoToDiscardCards)
gameState.addCardToZone(game, card, Zone.DISCARD);
if (_source != null && cardsToReturnToHand.size() > 0)
game.getGameState().sendMessage(GameUtils.getCardLink(_source) + " returns " + getAppendedNames(cardsToReturnToHand) + " to hand");
gameState.sendMessage(GameUtils.getCardLink(_source) + " returns " + getAppendedNames(cardsToReturnToHand) + " to hand");
for (PhysicalCard discardedCard : discardedFromPlay)
game.getActionsEnvironment().emitEffectResult(new DiscardCardsFromPlayResult(discardedCard));

View File

@@ -4,6 +4,7 @@ import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.effects.DiscardUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
@@ -51,19 +52,15 @@ public class ShuffleCardsFromPlayIntoDeckEffect extends AbstractEffect {
for (PhysicalCard card : _cards) {
if (card.getZone().isInPlay()) {
toShuffleIn.add(card);
goingToDiscard.addAll(game.getGameState().getStackedCards(card));
goingToDiscard.addAll(game.getGameState().getAttachedCards(card));
discardedFromPlay.addAll(game.getGameState().getAttachedCards(card));
}
}
Set<PhysicalCard> removeFromPlay = new HashSet<PhysicalCard>();
removeFromPlay.addAll(toShuffleIn);
removeFromPlay.addAll(goingToDiscard);
if (toShuffleIn.size() > 0) {
DiscardUtils.cardsToChangeZones(game.getGameState(), toShuffleIn, discardedFromPlay, goingToDiscard);
Set<PhysicalCard> removeFromPlay = new HashSet<PhysicalCard>(goingToDiscard);
removeFromPlay.addAll(toShuffleIn);
game.getGameState().removeCardsFromZone(_source.getOwner(), removeFromPlay);
game.getGameState().shuffleCardsIntoDeck(toShuffleIn, _playerDeck);

View File

@@ -5,12 +5,13 @@ import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
import com.gempukku.lotro.logic.effects.DiscardUtils;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class StackCardFromPlayEffect extends AbstractEffect {
@@ -42,31 +43,25 @@ public class StackCardFromPlayEffect extends AbstractEffect {
if (isPlayableInFull(game)) {
GameState gameState = game.getGameState();
List<PhysicalCard> attachedCards = gameState.getAttachedCards(_card);
List<PhysicalCard> stackedCards = gameState.getStackedCards(_card);
Set<PhysicalCard> discardedFromPlayCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> toMoveToDiscardCards = new HashSet<PhysicalCard>();
// Then remove from zones (card, attached and stacked on it)
Set<PhysicalCard> discardedCards = new HashSet<PhysicalCard>();
Set<PhysicalCard> cardsToRemove = new HashSet<PhysicalCard>();
cardsToRemove.add(_card);
cardsToRemove.addAll(attachedCards);
discardedCards.addAll(attachedCards);
cardsToRemove.addAll(stackedCards);
DiscardUtils.cardsToChangeZones(gameState, Collections.singleton(_card), discardedFromPlayCards, toMoveToDiscardCards);
gameState.removeCardsFromZone(_card.getOwner(), cardsToRemove);
Set<PhysicalCard> removeFromPlay = new HashSet<PhysicalCard>(toMoveToDiscardCards);
removeFromPlay.add(_card);
gameState.removeCardsFromZone(_card.getOwner(), removeFromPlay);
// And put them in new zones (attached and stacked to discard, the card gets stacked on)
for (PhysicalCard attachedCard : attachedCards)
for (PhysicalCard attachedCard : toMoveToDiscardCards)
gameState.addCardToZone(game, attachedCard, Zone.DISCARD);
for (PhysicalCard stackedCard : stackedCards)
gameState.addCardToZone(game, stackedCard, Zone.DISCARD);
game.getGameState().sendMessage(GameUtils.getCardLink(_card) + " is stacked on " + GameUtils.getCardLink(_stackOn));
game.getGameState().stackCard(game, _card, _stackOn);
// Send the result (attached cards get discarded)
for (PhysicalCard discardedCard : discardedCards)
for (PhysicalCard discardedCard : discardedFromPlayCards)
game.getActionsEnvironment().emitEffectResult(new DiscardCardsFromPlayResult(discardedCard));
return new FullEffectResult(true, true);

View File

@@ -40,6 +40,7 @@ public class TransferToSupportEffect extends AbstractEffect {
Set<PhysicalCard> transferredCards = new HashSet<PhysicalCard>();
transferredCards.add(_card);
final List<PhysicalCard> attachedCards = game.getGameState().getAttachedCards(_card);
transferredCards.addAll(attachedCards);

View File

@@ -10,8 +10,6 @@ import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import java.util.List;
/**
* Set: Mines of Moria
* Side: Free
@@ -29,16 +27,9 @@ public class Card2_027 extends AbstractOldEvent {
@Override
public boolean checkPlayRequirements(String playerId, LotroGame game, PhysicalCard self, int withTwilightRemoved, int twilightModifier, boolean ignoreRoamingPenalty, boolean ignoreCheckingDeadPile) {
if (!super.checkPlayRequirements(playerId, game, self, withTwilightRemoved, twilightModifier, ignoreRoamingPenalty, ignoreCheckingDeadPile))
return false;
PhysicalCard gandalf = Filters.findFirstActive(game.getGameState(), game.getModifiersQuerying(), Filters.gandalf);
List<PhysicalCard> attachedToGandalf = game.getGameState().getAttachedCards(gandalf);
if (gandalf != null
&& PlayConditions.canExert(self, game, 2, Filters.sameCard(gandalf))
&& Filters.filter(attachedToGandalf, game.getGameState(), game.getModifiersQuerying(), PossessionClass.STAFF).size() > 0)
return true;
return false;
return super.checkPlayRequirements(playerId, game, self, withTwilightRemoved, twilightModifier, ignoreRoamingPenalty, ignoreCheckingDeadPile)
&& PlayConditions.canDiscardFromPlay(self, game, PossessionClass.STAFF, Filters.attachedTo(Filters.gandalf))
&& PlayConditions.canExert(self, game, 2, Filters.gandalf);
}
@Override

View File

@@ -13,7 +13,6 @@ import com.gempukku.lotro.logic.timing.results.DiscardCardsFromPlayResult;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class DiscardCardsFromPlayEffect extends AbstractPreventableCardEffect {
@@ -74,17 +73,10 @@ public class DiscardCardsFromPlayEffect extends AbstractPreventableCardEffect {
GameState gameState = game.getGameState();
for (PhysicalCard card : cards) {
discardedCards.add(card);
toMoveFromZoneToDiscard.add(card);
DiscardUtils.cardsToChangeZones(gameState, cards, discardedCards, toMoveFromZoneToDiscard);
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card);
discardedCards.addAll(attachedCards);
toMoveFromZoneToDiscard.addAll(attachedCards);
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
toMoveFromZoneToDiscard.addAll(stackedCards);
}
discardedCards.addAll(cards);
toMoveFromZoneToDiscard.addAll(cards);
String sourcePlayer = null;
if (_source != null)

View File

@@ -0,0 +1,30 @@
package com.gempukku.lotro.logic.effects;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.GameState;
import java.util.Collection;
import java.util.List;
public class DiscardUtils {
public static void cardsToChangeZones(GameState gameState, Collection<PhysicalCard> movingCards, Collection<PhysicalCard> discardedCards, Collection<PhysicalCard> toMoveToDiscard) {
for (PhysicalCard card : movingCards) {
cardsToChangeZones(gameState, movingCards, card, discardedCards, toMoveToDiscard);
}
}
private static void cardsToChangeZones(GameState gameState, Collection<PhysicalCard> movingCards, PhysicalCard card, Collection<PhysicalCard> discardedCards, Collection<PhysicalCard> toMoveToDiscard) {
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card);
for (PhysicalCard attachedCard : attachedCards) {
if (!movingCards.contains(attachedCard)) {
discardedCards.add(attachedCard);
toMoveToDiscard.add(attachedCard);
cardsToChangeZones(gameState, movingCards, attachedCard, discardedCards, toMoveToDiscard);
}
}
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
for (PhysicalCard stackedCard : stackedCards)
toMoveToDiscard.add(stackedCard);
}
}

View File

@@ -85,17 +85,11 @@ public class KillEffect extends AbstractSuccessfulEffect {
discardedCards.add(card);
toAddToDiscard.add(card);
}
List<PhysicalCard> attachedCards = gameState.getAttachedCards(card);
discardedCards.addAll(attachedCards);
toRemoveFromZone.addAll(attachedCards);
toAddToDiscard.addAll(attachedCards);
List<PhysicalCard> stackedCards = gameState.getStackedCards(card);
toRemoveFromZone.addAll(stackedCards);
toAddToDiscard.addAll(stackedCards);
}
DiscardUtils.cardsToChangeZones(gameState, toBeKilled, discardedCards, toAddToDiscard);
toRemoveFromZone.addAll(toAddToDiscard);
gameState.removeCardsFromZone(null, toRemoveFromZone);
for (PhysicalCard deadCard : toAddToDeadPile)
@@ -104,21 +98,12 @@ public class KillEffect extends AbstractSuccessfulEffect {
for (PhysicalCard discardedCard : toAddToDiscard)
gameState.addCardToZone(game, discardedCard, Zone.DISCARD);
if (killedCards.size() > 0 && discardedCards.size() > 0) {
if (killedCards.size() > 0)
game.getActionsEnvironment().emitEffectResult(new KilledResult(killedCards, _cause));
for (PhysicalCard killedCard : killedCards)
game.getActionsEnvironment().emitEffectResult(new ForEachKilledResult(killedCard, _cause));
for (PhysicalCard discardedCard : discardedCards)
game.getActionsEnvironment().emitEffectResult(new DiscardCardsFromPlayResult(discardedCard));
for (PhysicalCard killedCard : killedCards)
game.getActionsEnvironment().emitEffectResult(new ForEachKilledResult(killedCard, _cause));
for (PhysicalCard discardedCard : discardedCards)
game.getActionsEnvironment().emitEffectResult(new DiscardCardsFromPlayResult(discardedCard));
} else if (killedCards.size() > 0) {
game.getActionsEnvironment().emitEffectResult(new KilledResult(killedCards, _cause));
for (PhysicalCard killedCard : killedCards)
game.getActionsEnvironment().emitEffectResult(new ForEachKilledResult(killedCard, _cause));
} else if (discardedCards.size() > 0) {
for (PhysicalCard discardedCard : discardedCards)
game.getActionsEnvironment().emitEffectResult(new DiscardCardsFromPlayResult(discardedCard));
}
}
}