From ca70685d8c8ac91da804c3c29dcbb73f1488563a Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Mon, 7 Nov 2011 16:20:02 +0000 Subject: [PATCH] "Above the Battlement" --- .../gempukku/lotro/cards/PlayConditions.java | 11 +++ .../ChooseAndPlayCardFromStackedEffect.java | 95 +++++++++++++++++++ .../lotro/cards/set7/sauron/Card7_262.java | 84 ++++++++++++++++ .../com/gempukku/lotro/common/Keyword.java | 2 +- 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/choose/ChooseAndPlayCardFromStackedEffect.java create mode 100644 gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set7/sauron/Card7_262.java diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/PlayConditions.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/PlayConditions.java index 597a1dc4f..120e5b596 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/PlayConditions.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/PlayConditions.java @@ -18,6 +18,7 @@ import com.gempukku.lotro.logic.timing.Effect; import com.gempukku.lotro.logic.timing.EffectResult; import com.gempukku.lotro.logic.timing.results.*; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -213,6 +214,16 @@ public class PlayConditions { return Filters.filter(game.getGameState().getDeadPile(playerId), game.getGameState(), game.getModifiersQuerying(), Filters.and(filters, Filters.playable(game))).size() > 0; } + public static boolean canPlayFromStacked(String playerId, LotroGame game, Filterable stackedOn, Filterable... filters) { + final Collection matchingStackedOn = Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), stackedOn); + for (PhysicalCard stackedOnCard : matchingStackedOn) { + if (Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), Filters.and(filters, Filters.playable(game))).size() > 0) + return true; + } + + return false; + } + public static boolean canPlayFromDiscard(String playerId, LotroGame game, Filterable... filters) { if (game.getModifiersQuerying().hasFlagActive(game.getGameState(), ModifierFlag.CANT_PLAY_FROM_DISCARD_OR_DECK)) return false; diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/choose/ChooseAndPlayCardFromStackedEffect.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/choose/ChooseAndPlayCardFromStackedEffect.java new file mode 100644 index 000000000..0693b47cc --- /dev/null +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/choose/ChooseAndPlayCardFromStackedEffect.java @@ -0,0 +1,95 @@ +package com.gempukku.lotro.cards.effects.choose; + +import com.gempukku.lotro.cards.actions.PlayPermanentAction; +import com.gempukku.lotro.common.Filterable; +import com.gempukku.lotro.filters.Filter; +import com.gempukku.lotro.filters.Filters; +import com.gempukku.lotro.game.PhysicalCard; +import com.gempukku.lotro.game.state.LotroGame; +import com.gempukku.lotro.logic.decisions.ArbitraryCardsSelectionDecision; +import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; +import com.gempukku.lotro.logic.timing.Action; +import com.gempukku.lotro.logic.timing.Effect; +import com.gempukku.lotro.logic.timing.EffectResult; + +import java.util.*; + +public class ChooseAndPlayCardFromStackedEffect implements Effect { + private String _playerId; + private Filterable _stackedOn; + private Filter _filter; + private int _twilightModifier; + private Action _playCardAction; + + public ChooseAndPlayCardFromStackedEffect(String playerId, Filterable stackedOn, Filterable... filter) { + this(playerId, stackedOn, 0, filter); + } + + public ChooseAndPlayCardFromStackedEffect(String playerId, Filterable stackedOn, int twilightModifier, Filterable... filter) { + _playerId = playerId; + _stackedOn = stackedOn; + _filter = Filters.and(filter); + _twilightModifier = twilightModifier; + } + + @Override + public String getText(LotroGame game) { + return "Play card from stacked"; + } + + @Override + public boolean isPlayableInFull(LotroGame game) { + return getPlayableFromStacked(game).size() > 0; + } + + @Override + public Type getType() { + return null; + } + + private Collection getPlayableFromStacked(LotroGame game) { + Set possibleCards = new HashSet(); + for (PhysicalCard stackedOnCard : Filters.filterActive(game.getGameState(), game.getModifiersQuerying(), _stackedOn)) + possibleCards.addAll(Filters.filter(game.getGameState().getStackedCards(stackedOnCard), game.getGameState(), game.getModifiersQuerying(), _filter, Filters.playable(game, _twilightModifier))); + + return possibleCards; + } + + @Override + public Collection playEffect(final LotroGame game) { + Collection playableFromStacked = getPlayableFromStacked(game); + if (playableFromStacked.size() > 0) { + game.getUserFeedback().sendAwaitingDecision(_playerId, + new ArbitraryCardsSelectionDecision(1, "Choose a card to play", new LinkedList(playableFromStacked), 1, 1) { + @Override + public void decisionMade(String result) throws DecisionResultInvalidException { + List selectedCards = getSelectedCardsByResponse(result); + if (selectedCards.size() > 0) { + PhysicalCard selectedCard = selectedCards.get(0); + _playCardAction = selectedCard.getBlueprint().getPlayCardAction(_playerId, game, selectedCard, _twilightModifier); + game.getActionsEnvironment().addActionToStack(_playCardAction); + } + } + }); + } + return null; + } + + @Override + public boolean wasSuccessful() { + if (_playCardAction == null) + return false; + if (_playCardAction instanceof PlayPermanentAction) + return ((PlayPermanentAction) _playCardAction).wasSuccessful(); + return true; + } + + @Override + public boolean wasCarriedOut() { + if (_playCardAction == null) + return false; + if (_playCardAction instanceof PlayPermanentAction) + return ((PlayPermanentAction) _playCardAction).wasCarriedOut(); + return true; + } +} \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set7/sauron/Card7_262.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set7/sauron/Card7_262.java new file mode 100644 index 000000000..6fdc93125 --- /dev/null +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set7/sauron/Card7_262.java @@ -0,0 +1,84 @@ +package com.gempukku.lotro.cards.set7.sauron; + +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.ChoiceEffect; +import com.gempukku.lotro.cards.effects.RemoveBurdenEffect; +import com.gempukku.lotro.cards.effects.choose.ChooseAndPlayCardFromDiscardEffect; +import com.gempukku.lotro.cards.effects.choose.ChooseAndPlayCardFromStackedEffect; +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.timing.Effect; +import com.gempukku.lotro.logic.timing.UnrespondableEffect; + +import java.util.LinkedList; +import java.util.List; + +/** + * Set: The Return of the King + * Side: Shadow + * Culture: Sauron + * Twilight Cost: 0 + * Type: Event • Shadow + * Game Text: Play a bieseger stacked on a site you control or remove a burden to play a [SAURON] Orc from your discard + * pile. + */ +public class Card7_262 extends AbstractEvent { + public Card7_262() { + super(Side.SHADOW, 0, Culture.SAURON, "Above the Battlement", Phase.SHADOW); + } + + @Override + public boolean checkPlayRequirements(String playerId, LotroGame game, PhysicalCard self, int twilightModifier) { + return super.checkPlayRequirements(playerId, game, self, twilightModifier) + && ( + (PlayConditions.canRemoveBurdens(game, self, 1) + && PlayConditions.canPlayFromDiscard(playerId, game, Culture.SAURON, Race.ORC) + ) + || PlayConditions.canPlayFromStacked(playerId, game, Filters.siteControlled(playerId), Keyword.BESIEGER)); + } + + @Override + public PlayEventAction getPlayCardAction(final String playerId, LotroGame game, final PhysicalCard self, int twilightModifier) { + final PlayEventAction action = new PlayEventAction(self); + List possibleCosts = new LinkedList(); + if (PlayConditions.canPlayFromStacked(playerId, game, Filters.siteControlled(playerId), Keyword.BESIEGER)) + possibleCosts.add( + new UnrespondableEffect() { + @Override + public String getText(LotroGame game) { + return "Play a besieger stacked on a site you control"; + } + + @Override + protected void doPlayEffect(LotroGame game) { + action.appendEffect( + new ChooseAndPlayCardFromStackedEffect(playerId, Filters.siteControlled(playerId), Keyword.BESIEGER)); + } + }); + if (PlayConditions.canRemoveBurdens(game, self, 1) + && PlayConditions.canPlayFromDiscard(playerId, game, Culture.SAURON, Race.ORC)) + possibleCosts.add( + new UnrespondableEffect() { + @Override + public String getText(LotroGame game) { + return "Remove a burden to play a SAURON Orc from your discard pile"; + } + + @Override + protected void doPlayEffect(LotroGame game) { + action.insertCost( + new RemoveBurdenEffect(self)); + action.appendEffect( + new ChooseAndPlayCardFromDiscardEffect(playerId, game.getGameState().getDiscard(playerId), Culture.SAURON, Race.ORC)); + } + }); + + action.appendCost( + new ChoiceEffect(action, playerId, possibleCosts)); + return action; + } +} diff --git a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/Keyword.java b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/Keyword.java index c9cec33a3..2f4684cfb 100644 --- a/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/Keyword.java +++ b/gemp-lotr/gemp-lotr-common/src/main/java/com/gempukku/lotro/common/Keyword.java @@ -19,7 +19,7 @@ public enum Keyword implements Filterable { DAMAGE("Damage", true, true), DEFENDER("Defender", true, true), AMBUSH("Ambush", true, true), FIERCE("Fierce", true), ARCHER("Archer", true), UNHASTY("Unhasty", true), RANGER("Ranger", true), TRACKER("Tracker", true), VILLAGER("Villager", true), MACHINE("Machine", true), ENGINE("Engine", true), SOUTHRON("Southron", true), EASTERLING("Easterling", true), VALIANT("Valiant", true), KNIGHT("Knight", true), FORTIFICATION("Fortification", true), - WARG_RIDER("Warg-rider", true); + WARG_RIDER("Warg-rider", true), BESIEGER("Besieger", true); private String _humanReadable; private boolean _infoDisplayable;