Discarding and shuffling.

This commit is contained in:
marcins78@gmail.com
2011-10-14 09:33:32 +00:00
parent 9564bdcfea
commit b4a34882e9
7 changed files with 139 additions and 50 deletions

View File

@@ -42,9 +42,8 @@ public class DiscardStackedCardsEffect extends AbstractEffect {
GameState gameState = game.getGameState();
gameState.sendMessage(getAppendedNames(_cards) + " is/are discarded from being stacked");
gameState.removeCardsFromZone(_cards);
for (PhysicalCard card : _cards) {
for (PhysicalCard card : _cards)
gameState.addCardToZone(card, Zone.DISCARD);
}
return new FullEffectResult(null, true, true);
}

View File

@@ -53,9 +53,8 @@ public class LiberateASiteEffect extends AbstractEffect {
List<PhysicalCard> stackedCards = game.getGameState().getStackedCards(siteToLiberate);
game.getGameState().removeCardsFromZone(stackedCards);
for (PhysicalCard stackedCard : stackedCards) {
for (PhysicalCard stackedCard : stackedCards)
game.getGameState().addCardToZone(stackedCard, Zone.DISCARD);
}
game.getGameState().loseControlOfCard(siteToLiberate, Zone.ADVENTURE_PATH);

View File

@@ -0,0 +1,69 @@
package com.gempukku.lotro.cards.effects;
import com.gempukku.lotro.common.Zone;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.timing.AbstractEffect;
import com.gempukku.lotro.logic.timing.EffectResult;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class ShuffleCardsFromPlayOrStackedIntoDeckEffect extends AbstractEffect {
private PhysicalCard _source;
private String _playerDeck;
private Collection<PhysicalCard> _cards;
public ShuffleCardsFromPlayOrStackedIntoDeckEffect(PhysicalCard source, String playerDeck, Collection<PhysicalCard> cards) {
_source = source;
_playerDeck = playerDeck;
_cards = cards;
}
@Override
public String getText(LotroGame game) {
return null;
}
@Override
public EffectResult.Type getType() {
return null;
}
@Override
public boolean isPlayableInFull(LotroGame game) {
for (PhysicalCard card : _cards) {
if (card.getZone() != Zone.STACKED && !card.getZone().isInPlay())
return false;
}
return true;
}
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
Set<PhysicalCard> stacked = new HashSet<PhysicalCard>();
Set<PhysicalCard> inPlay = new HashSet<PhysicalCard>();
for (PhysicalCard card : _cards) {
if (card.getZone() == Zone.STACKED)
stacked.add(card);
else if (card.getZone().isInPlay())
inPlay.add(card);
}
for (PhysicalCard physicalCard : inPlay)
game.getGameState().stopAffecting(physicalCard);
Set<PhysicalCard> shuffleIn = new HashSet<PhysicalCard>(stacked);
shuffleIn.addAll(inPlay);
game.getGameState().removeCardsFromZone(shuffleIn);
game.getGameState().shuffleCardsIntoDeck(shuffleIn, _playerDeck);
game.getGameState().sendMessage(getAppendedNames(shuffleIn) + " is/are shuffled into " + _playerDeck + " deck");
return new FullEffectResult(null, shuffleIn.size() == _cards.size(), shuffleIn.size() == _cards.size());
}
}

View File

@@ -7,9 +7,11 @@ import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.GameUtils;
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.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class StackCardFromPlayEffect extends AbstractEffect {
private PhysicalCard _card;
@@ -38,28 +40,42 @@ public class StackCardFromPlayEffect extends AbstractEffect {
@Override
protected FullEffectResult playEffectReturningResult(LotroGame game) {
if (isPlayableInFull(game)) {
game.getGameState().stopAffecting(_card);
game.getGameState().removeCardsFromZone(Collections.singleton(_card));
GameState gameState = game.getGameState();
List<PhysicalCard> attachedCards = gameState.getAttachedCards(_card);
for (PhysicalCard attachedCard : 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);
}
game.getGameState().sendMessage(_card.getOwner() + " stacks " + GameUtils.getCardLink(_card) + " from play on " + GameUtils.getCardLink(_stackOn));
// First stop affecting (card and all attached to it)
game.getGameState().stopAffecting(_card);
for (PhysicalCard attachedCard : attachedCards)
gameState.stopAffecting(attachedCard);
// 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);
gameState.removeCardsFromZone(cardsToRemove);
// And put them in new zones (attached and stacked to discard, the card gets stacked on)
for (PhysicalCard attachedCard : attachedCards)
gameState.addCardToZone(attachedCard, Zone.DISCARD);
for (PhysicalCard stackedCard : stackedCards)
gameState.addCardToZone(stackedCard, Zone.DISCARD);
game.getGameState().sendMessage(GameUtils.getCardLink(_card) + " is stacked on " + GameUtils.getCardLink(_stackOn));
game.getGameState().stackCard(_card, _stackOn);
return new FullEffectResult(null, true, true);
// Send the result (attached cards get discarded)
if (discardedCards.size() > 0)
return new FullEffectResult(new EffectResult[]{new DiscardCardsFromPlayResult(discardedCards)}, true, true);
else
return new FullEffectResult(null, true, true);
}
return new FullEffectResult(null, false, false);
}

View File

@@ -2,7 +2,7 @@ package com.gempukku.lotro.cards.set4.dwarven;
import com.gempukku.lotro.cards.AbstractEvent;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ShuffleDeckEffect;
import com.gempukku.lotro.cards.effects.ShuffleCardsFromPlayOrStackedIntoDeckEffect;
import com.gempukku.lotro.common.CardType;
import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Phase;
@@ -13,7 +13,8 @@ import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.effects.ChooseActiveCardsEffect;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Set: The Two Towers
@@ -34,22 +35,20 @@ public class Card4_054 extends AbstractEvent {
}
@Override
public PlayEventAction getPlayCardAction(final String playerId, LotroGame game, PhysicalCard self, int twilightModifier) {
public PlayEventAction getPlayCardAction(final String playerId, LotroGame game, final PhysicalCard self, int twilightModifier) {
final PlayEventAction action = new PlayEventAction(self);
action.appendEffect(
new ChooseActiveCardsEffect(self, playerId, "Choose DWARVEN conditions", 0, Integer.MAX_VALUE, Filters.culture(Culture.DWARVEN), Filters.type(CardType.CONDITION)) {
@Override
protected void cardsSelected(LotroGame game, Collection<PhysicalCard> cards) {
Set<PhysicalCard> toShuffle = new HashSet<PhysicalCard>();
for (PhysicalCard card : cards) {
game.getGameState().removeCardsFromZone(game.getGameState().getStackedCards(card));
for (PhysicalCard stackedCard : game.getGameState().getStackedCards(card)) {
game.getGameState().putCardOnBottomOfDeck(stackedCard);
}
game.getGameState().removeCardsFromZone(Collections.singleton(card));
game.getGameState().putCardOnBottomOfDeck(card);
toShuffle.add(card);
toShuffle.addAll(game.getGameState().getStackedCards(card));
}
action.appendEffect(
new ShuffleDeckEffect(playerId));
action.insertEffect(
new ShuffleCardsFromPlayOrStackedIntoDeckEffect(self, playerId, toShuffle));
}
});
return action;

View File

@@ -4,14 +4,15 @@ import com.gempukku.lotro.cards.AbstractEvent;
import com.gempukku.lotro.cards.PlayConditions;
import com.gempukku.lotro.cards.actions.PlayEventAction;
import com.gempukku.lotro.cards.effects.ChooseAndExertCharactersEffect;
import com.gempukku.lotro.cards.effects.ShuffleDeckEffect;
import com.gempukku.lotro.cards.effects.ShuffleCardsFromPlayOrStackedIntoDeckEffect;
import com.gempukku.lotro.common.*;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.effects.ChooseActiveCardEffect;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Set: The Two Towers
@@ -39,7 +40,7 @@ public class Card4_055 extends AbstractEvent {
}
@Override
public PlayEventAction getPlayCardAction(final String playerId, final LotroGame game, PhysicalCard self, int twilightModifier) {
public PlayEventAction getPlayCardAction(final String playerId, final LotroGame game, final PhysicalCard self, int twilightModifier) {
final PlayEventAction action = new PlayEventAction(self);
action.appendCost(
new ChooseAndExertCharactersEffect(action, playerId, 1, 1, Filters.race(Race.DWARF)));
@@ -47,20 +48,15 @@ public class Card4_055 extends AbstractEvent {
new ChooseActiveCardEffect(self, playerId, "Choose a DWARVEN condition", Filters.culture(Culture.DWARVEN), Filters.type(CardType.CONDITION)) {
@Override
protected void cardSelected(PhysicalCard card) {
int count = 0;
game.getGameState().removeCardsFromZone(game.getGameState().getStackedCards(card));
for (PhysicalCard stackedCard : game.getGameState().getStackedCards(card)) {
game.getGameState().putCardOnBottomOfDeck(stackedCard);
count++;
}
game.getGameState().removeCardsFromZone(Collections.singleton(card));
game.getGameState().putCardOnBottomOfDeck(card);
count++;
Set<PhysicalCard> toShuffle = new HashSet<PhysicalCard>();
toShuffle.add(card);
toShuffle.addAll(game.getGameState().getStackedCards(card));
action.insertEffect(
new ShuffleCardsFromPlayOrStackedIntoDeckEffect(self, playerId, toShuffle));
action.appendEffect(
new ShuffleDeckEffect(playerId));
action.appendEffect(
new ChooseAndExertCharactersEffect(action, playerId, count, count, Filters.type(CardType.MINION)));
new ChooseAndExertCharactersEffect(action, playerId, toShuffle.size(), toShuffle.size(), Filters.type(CardType.MINION)));
}
});
return action;

View File

@@ -360,6 +360,21 @@ public class GameState {
}
}
public void shuffleCardsIntoDeck(Collection<PhysicalCard> cards, String playerId) {
List<PhysicalCardImpl> zoneCards = _decks.get(playerId);
for (PhysicalCard card : cards) {
zoneCards.add((PhysicalCardImpl) card);
((PhysicalCardImpl) card).setZone(Zone.DECK);
}
for (GameStateListener listener : getAllGameStateListeners())
listener.setZoneSize(playerId, Zone.DECK, zoneCards.size());
shuffleDeck(playerId);
}
public void putCardOnBottomOfDeck(PhysicalCard card) {
addCardToZone(card, Zone.DECK);
}
@@ -716,10 +731,6 @@ public class GameState {
listener.finishSkirmish();
}
public void playerShufflesDeck(String player) {
Collections.shuffle(_decks.get(player));
}
public PhysicalCard removeTopDeckCard(String player) {
List<PhysicalCardImpl> deck = _decks.get(player);
if (deck.size() > 0) {