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 8eb3c09da..47c1ad159 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 @@ -8,6 +8,7 @@ import com.gempukku.lotro.game.PhysicalCard; import com.gempukku.lotro.game.PhysicalCardVisitor; import com.gempukku.lotro.game.state.GameState; import com.gempukku.lotro.game.state.LotroGame; +import com.gempukku.lotro.logic.effects.DiscardCardsFromPlayEffect; import com.gempukku.lotro.logic.effects.PlayCardEffect; import com.gempukku.lotro.logic.effects.WoundCharactersEffect; import com.gempukku.lotro.logic.modifiers.ModifiersQuerying; @@ -267,6 +268,14 @@ public class PlayConditions { return false; } + public static boolean isGettingDiscarded(Effect effect, LotroGame game, Filterable... filters) { + if (effect.getType() == EffectResult.Type.DISCARD_FROM_PLAY) { + DiscardCardsFromPlayEffect discardEffect = (DiscardCardsFromPlayEffect) effect; + return Filters.filter(discardEffect.getAffectedCardsMinusPrevented(game), game.getGameState(), game.getModifiersQuerying(), filters).size() > 0; + } + return false; + } + public static boolean played(GameState gameState, ModifiersQuerying modifiersQuerying, EffectResult effectResult, Filter filter) { if (effectResult.getType() == EffectResult.Type.PLAY) { PhysicalCard playedCard = ((PlayCardResult) effectResult).getPlayedCard(); diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set5/isengard/Card5_060.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set5/isengard/Card5_060.java new file mode 100644 index 000000000..d52ec1edf --- /dev/null +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set5/isengard/Card5_060.java @@ -0,0 +1,77 @@ +package com.gempukku.lotro.cards.set5.isengard; + +import com.gempukku.lotro.cards.AbstractPermanent; +import com.gempukku.lotro.cards.PlayConditions; +import com.gempukku.lotro.cards.effects.AddTokenEffect; +import com.gempukku.lotro.cards.effects.PreventCardEffect; +import com.gempukku.lotro.cards.effects.choose.ChooseAndPlayCardFromHandEffect; +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.actions.ActivateCardAction; +import com.gempukku.lotro.logic.effects.ChooseActiveCardEffect; +import com.gempukku.lotro.logic.effects.DiscardCardsFromPlayEffect; +import com.gempukku.lotro.logic.timing.Action; +import com.gempukku.lotro.logic.timing.Effect; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Set: Battle of Helm's Deep + * Side: Shadow + * Culture: Isengard + * Twilight Cost: 0 + * Type: Condition + * Game Text: Machine. Plays to your support area. Shadow: Play an Uruk-hai to place an [ISENGARD] token on a machine. + * Response: If one or more machines are about to be discarded by an opponent, discard this condition to prevent that. + */ +public class Card5_060 extends AbstractPermanent { + public Card5_060() { + super(Side.SHADOW, 0, CardType.CONDITION, Culture.ISENGARD, Zone.SUPPORT, "Siege Engine"); + addKeyword(Keyword.MACHINE); + } + + @Override + protected List getExtraPhaseActions(String playerId, LotroGame game, final PhysicalCard self) { + if (PlayConditions.canUseShadowCardDuringPhase(game.getGameState(), Phase.SHADOW, self, 0) + && PlayConditions.canPlayFromHand(playerId, game, Race.URUK_HAI)) { + final ActivateCardAction action = new ActivateCardAction(self); + action.appendCost( + new ChooseAndPlayCardFromHandEffect(playerId, game.getGameState().getHand(playerId), Race.URUK_HAI)); + action.appendEffect( + new ChooseActiveCardEffect(self, playerId, "Choose a machine", Keyword.MACHINE) { + @Override + protected void cardSelected(LotroGame game, PhysicalCard card) { + action.insertEffect( + new AddTokenEffect(self, card, Token.ISENGARD)); + } + }); + return Collections.singletonList(action); + } + return null; + } + + @Override + public List getOptionalInPlayBeforeActions(String playerId, LotroGame game, Effect effect, PhysicalCard self) { + if (PlayConditions.isGettingDiscarded(effect, game, Keyword.MACHINE)) { + DiscardCardsFromPlayEffect discardEffect = (DiscardCardsFromPlayEffect) effect; + if (discardEffect.getSource() != null + && discardEffect.getSource().getOwner().equals(game.getGameState().getCurrentPlayerId())) { + ActivateCardAction action = new ActivateCardAction(self); + action.appendCost( + new DiscardCardsFromPlayEffect(self, self)); + + Collection machines = Filters.filter(discardEffect.getAffectedCardsMinusPrevented(game), game.getGameState(), game.getModifiersQuerying(), Keyword.MACHINE); + for (PhysicalCard machine : machines) + action.appendEffect( + new PreventCardEffect(discardEffect, machine)); + + return Collections.singletonList(action); + } + } + return null; + } +}