From 624fa236c37c2eb752f7847068754ab085201e2d Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Thu, 10 Jan 2013 20:17:36 +0000 Subject: [PATCH] Sites can now be prevented from being liberated (fixed some issues). --- .../gempukku/lotro/cards/PlayConditions.java | 30 ++++++++++++++++--- .../cards/effects/LiberateASiteEffect.java | 4 +-- .../cards/set17/uruk_hai/Card17_125.java | 2 +- .../cards/set17/uruk_hai/Card17_138.java | 2 +- .../lotro/cards/set18/men/Card18_075.java | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) 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 d959da639..7766715ce 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 @@ -38,14 +38,36 @@ public class PlayConditions { return true; } - public static boolean canLiberateASite(LotroGame game) { - return Filters.countActive(game.getGameState(), game.getModifiersQuerying(), Filters.siteControlledByShadowPlayer(game.getGameState().getCurrentPlayerId())) > 0; + public static boolean canLiberateASite(LotroGame game, String performingPlayer, PhysicalCard source) { + return canLiberateASite(game, performingPlayer, source, null); } - public static boolean canLiberateASite(LotroGame game, String playerId) { - return Filters.countActive(game.getGameState(), game.getModifiersQuerying(), Filters.siteControlled(playerId)) > 0; + public static boolean canLiberateASite(LotroGame game, String performingPlayer, PhysicalCard source, String controlledByPlayerId) { + PhysicalCard siteToLiberate = getSiteToLiberate(game, controlledByPlayerId); + return siteToLiberate != null && game.getModifiersQuerying().canBeLiberated(game.getGameState(), performingPlayer, siteToLiberate, source); } + private static PhysicalCard getSiteToLiberate(LotroGame game, String controlledByPlayerId) { + int maxUnoccupiedSite = Integer.MAX_VALUE; + for (String playerId : game.getGameState().getPlayerOrder().getAllPlayers()) + maxUnoccupiedSite = Math.min(maxUnoccupiedSite, game.getGameState().getPlayerPosition(playerId) - 1); + + for (int i = maxUnoccupiedSite; i >= 1; i--) { + PhysicalCard site = game.getGameState().getSite(i); + if (controlledByPlayerId == null) { + if (site != null && site.getCardController() != null + && !site.getCardController().equals(game.getGameState().getCurrentPlayerId())) + return site; + } else { + if (site != null && site.getCardController() != null && site.getCardController().equals(controlledByPlayerId)) + return site; + } + } + + return null; + } + + public static boolean canDiscardFromHand(LotroGame game, String playerId, int count, Filterable... cardFilter) { return hasCardInHand(game, playerId, count, cardFilter); } diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/LiberateASiteEffect.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/LiberateASiteEffect.java index 957c6c1a2..a0a1591b2 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/LiberateASiteEffect.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/effects/LiberateASiteEffect.java @@ -1,7 +1,7 @@ package com.gempukku.lotro.cards.effects; +import com.gempukku.lotro.cards.PlayConditions; import com.gempukku.lotro.common.Zone; -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.AbstractEffect; @@ -27,7 +27,7 @@ public class LiberateASiteEffect extends AbstractEffect { @Override public boolean isPlayableInFull(LotroGame game) { - return Filters.countActive(game.getGameState(), game.getModifiersQuerying(), Filters.siteControlledByShadowPlayer(game.getGameState().getCurrentPlayerId())) > 0; + return PlayConditions.canLiberateASite(game, _source.getOwner(), _source, _playerId); } @Override diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_125.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_125.java index 0485fd0a8..1f9dab5ab 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_125.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_125.java @@ -37,7 +37,7 @@ public class Card17_125 extends AbstractMinion { @Override public List getOptionalAfterTriggers(String playerId, final LotroGame game, EffectResult effectResult, final PhysicalCard self) { if (TriggerConditions.played(game, effectResult, self) - && PlayConditions.canLiberateASite(game)) { + && PlayConditions.canLiberateASite(game, playerId, self)) { final OptionalTriggerAction action = new OptionalTriggerAction(self); action.appendCost( new LiberateASiteEffect(self) { diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_138.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_138.java index 84ea91825..49b803339 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_138.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set17/uruk_hai/Card17_138.java @@ -49,7 +49,7 @@ public class Card17_138 extends AbstractPermanent { @Override protected List getExtraPhaseActions(String playerId, LotroGame game, final PhysicalCard self) { if (PlayConditions.canUseShadowCardDuringPhase(game, Phase.SKIRMISH, self, 0) - && PlayConditions.canLiberateASite(game)) { + && PlayConditions.canLiberateASite(game, playerId, self)) { final ActivateCardAction action = new ActivateCardAction(self); action.appendCost( new LiberateASiteEffect(self)); diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set18/men/Card18_075.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set18/men/Card18_075.java index accc54b6d..74bf80cd9 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set18/men/Card18_075.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set18/men/Card18_075.java @@ -41,7 +41,7 @@ public class Card18_075 extends AbstractMinion { @Override protected List getExtraPhaseActions(final String playerId, LotroGame game, final PhysicalCard self) { if (PlayConditions.canUseShadowCardDuringPhase(game, Phase.MANEUVER, self, 0) - && PlayConditions.canLiberateASite(game, playerId)) { + && PlayConditions.canLiberateASite(game, playerId, self, playerId)) { ActivateCardAction action = new ActivateCardAction(self); action.appendCost( new LiberateASiteEffect(self, playerId));