From 14307937a37d6e84a609aba003632d3a0ede5484 Mon Sep 17 00:00:00 2001 From: "marcin.sciesinski" Date: Mon, 19 Aug 2019 08:58:33 -0700 Subject: [PATCH] Actions that have phase limits should be working correctly now --- .../lotro/cards/set40/shire/Card40_250.java | 21 +++++---- .../ForEachBurdenYouSpotDecision.java | 11 +---- .../ForEachTwilightTokenYouSpotDecision.java | 11 +---- .../decisions/ForEachYouSpotDecision.java | 28 +----------- .../effects/IncrementPhaseLimitEffect.java | 16 ++++--- .../lotro/logic/timing/PlayConditions.java | 10 +++-- .../lotro/at/IndividualCardAtTest.java | 45 +++++++++++++++++++ 7 files changed, 74 insertions(+), 68 deletions(-) diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set40/shire/Card40_250.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set40/shire/Card40_250.java index fe7d093c5..bf4004c70 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set40/shire/Card40_250.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/set40/shire/Card40_250.java @@ -8,7 +8,6 @@ import com.gempukku.lotro.logic.actions.ActivateCardAction; import com.gempukku.lotro.logic.cardtype.AbstractAttachableFPPossession; import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException; import com.gempukku.lotro.logic.decisions.ForEachYouSpotDecision; -import com.gempukku.lotro.logic.effects.CheckPhaseLimitEffect; import com.gempukku.lotro.logic.effects.ChooseAndHealCharactersEffect; import com.gempukku.lotro.logic.effects.IncrementPhaseLimitEffect; import com.gempukku.lotro.logic.effects.PlayoutDecisionEffect; @@ -44,22 +43,22 @@ public class Card40_250 extends AbstractAttachableFPPossession { public List getPhaseActionsInPlay(final String playerId, LotroGame game, final PhysicalCard self) { if (PlayConditions.canUseFPCardDuringPhase(game, Phase.FELLOWSHIP, self) && Filters.canSpot(game, Keyword.PIPEWEED, CardType.POSSESSION) - && PlayConditions.checkPhaseLimit(game, self, 1)) { + && PlayConditions.checkPhaseLimit(game, self, 1)) { final ActivateCardAction action = new ActivateCardAction(self); action.appendCost( new IncrementPhaseLimitEffect(self, 1)); action.appendCost( new ChooseAndDiscardCardsFromPlayEffect(action, playerId, 1, 1, Keyword.PIPEWEED, CardType.POSSESSION)); action.appendEffect( - new PlayoutDecisionEffect(playerId, - new ForEachYouSpotDecision(1, "Choose number of pipes you wish to spot", game, Integer.MAX_VALUE, PossessionClass.PIPE) { - @Override - public void decisionMade(String result) throws DecisionResultInvalidException { - final int spotCount = getValidatedResult(result); - action.appendEffect( - new ChooseAndHealCharactersEffect(action, playerId, 1, 1, spotCount, CardType.COMPANION, Filters.hasAttached(PossessionClass.PIPE))); - } - })); + new PlayoutDecisionEffect(playerId, + new ForEachYouSpotDecision(1, "Choose number of pipes you wish to spot", game, Integer.MAX_VALUE, PossessionClass.PIPE) { + @Override + public void decisionMade(String result) throws DecisionResultInvalidException { + final int spotCount = getValidatedResult(result); + action.appendEffect( + new ChooseAndHealCharactersEffect(action, playerId, 1, 1, spotCount, CardType.COMPANION, Filters.hasAttached(PossessionClass.PIPE))); + } + })); return Collections.singletonList(action); } return null; diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachBurdenYouSpotDecision.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachBurdenYouSpotDecision.java index d11745c9c..550fbcc40 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachBurdenYouSpotDecision.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachBurdenYouSpotDecision.java @@ -1,17 +1,8 @@ package com.gempukku.lotro.logic.decisions; -import java.util.Map; - public abstract class ForEachBurdenYouSpotDecision extends IntegerAwaitingDecision { protected ForEachBurdenYouSpotDecision(int id, int burdens) { - super(id, "Choose number of burdens you wish to spot", 0, burdens); - } - - @Override - public Map getDecisionParameters() { - Map result = super.getDecisionParameters(); - result.put("defaultValue", result.get("max")); - return result; + super(id, "Choose number of burdens you wish to spot", 0, burdens, burdens); } @Override diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachTwilightTokenYouSpotDecision.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachTwilightTokenYouSpotDecision.java index 649a09ade..7f0e970d8 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachTwilightTokenYouSpotDecision.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachTwilightTokenYouSpotDecision.java @@ -1,17 +1,8 @@ package com.gempukku.lotro.logic.decisions; -import java.util.Map; - public abstract class ForEachTwilightTokenYouSpotDecision extends IntegerAwaitingDecision { protected ForEachTwilightTokenYouSpotDecision(int id, int twilightTokens) { - super(id, "Choose number of twilight tokens you wish to spot", 0, twilightTokens); - } - - @Override - public Map getDecisionParameters() { - Map result = super.getDecisionParameters(); - result.put("defaultValue", result.get("max")); - return result; + super(id, "Choose number of twilight tokens you wish to spot", 0, twilightTokens, twilightTokens); } @Override diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachYouSpotDecision.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachYouSpotDecision.java index cac8c9bbe..cd4f8be69 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachYouSpotDecision.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/decisions/ForEachYouSpotDecision.java @@ -4,8 +4,6 @@ import com.gempukku.lotro.common.Filterable; import com.gempukku.lotro.filters.Filters; import com.gempukku.lotro.game.state.LotroGame; -import java.util.Map; - public abstract class ForEachYouSpotDecision extends IntegerAwaitingDecision { private LotroGame _lotroGame; private Filterable[] _filters; @@ -13,32 +11,10 @@ public abstract class ForEachYouSpotDecision extends IntegerAwaitingDecision { private int _max; protected ForEachYouSpotDecision(int id, String text, LotroGame lotroGame, int defaultValue, Filterable... filter) { - super(id, text, 0); + super(id, text, 0, Filters.countActive(lotroGame, filter) + + ((filter.length == 1) ? lotroGame.getModifiersQuerying().getSpotBonus(lotroGame, filter[0]) : 0)); _lotroGame = lotroGame; _filters = filter; _defaultValue = defaultValue; } - - @Override - public Map getDecisionParameters() { - Map result = super.getDecisionParameters(); - int count = Filters.countActive(_lotroGame, _filters); - if (_filters.length == 1) - count += _lotroGame.getModifiersQuerying().getSpotBonus(_lotroGame, _filters[0]); - _max = count; - result.put("max", String.valueOf(count)); - if (_defaultValue > _max) - _defaultValue = _max; - result.put("defaultValue", String.valueOf(_defaultValue)); - return result; - } - - @Override - protected int getValidatedResult(String result) throws DecisionResultInvalidException { - int value = super.getValidatedResult(result); - if (_max < value) - throw new DecisionResultInvalidException(); - - return value; - } } diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/effects/IncrementPhaseLimitEffect.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/effects/IncrementPhaseLimitEffect.java index 845bce1df..9ed7aa2c9 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/effects/IncrementPhaseLimitEffect.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/effects/IncrementPhaseLimitEffect.java @@ -12,26 +12,28 @@ public class IncrementPhaseLimitEffect extends UnrespondableEffect { private String prefix; public IncrementPhaseLimitEffect(PhysicalCard card, int limit) { - this.card = card; - this.limit = limit; + this(card, null, "", 1); } public IncrementPhaseLimitEffect(PhysicalCard card, Phase phase, int limit) { - this.card = card; - this.limit = limit; - this.phase = phase; + this(card, phase, "", 1); } public IncrementPhaseLimitEffect(PhysicalCard card, String prefix, int limit) { + this(card, null, "", 1); + } + + private IncrementPhaseLimitEffect(PhysicalCard card, Phase phase, String prefix, int limit) { this.card = card; - this.limit = limit; + this.phase = phase; this.prefix = prefix; + this.limit = limit; } @Override protected void doPlayEffect(LotroGame game) { if (phase == null) - game.getGameState().getCurrentPhase(); + phase = game.getGameState().getCurrentPhase(); game.getModifiersQuerying().getUntilEndOfPhaseLimitCounter(card, prefix, phase).incrementToLimit(limit, 1); } } diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/PlayConditions.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/PlayConditions.java index 7ceb5f780..4e70a43cb 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/PlayConditions.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/PlayConditions.java @@ -139,10 +139,12 @@ public class PlayConditions { public static boolean checkUniqueness(LotroGame game, PhysicalCard self, boolean ignoreCheckingDeadPile) { LotroCardBlueprint blueprint = self.getBlueprint(); - return (!blueprint.isUnique() - || ( - Filters.countActive(game, Filters.name(blueprint.getTitle())) == 0 - && (ignoreCheckingDeadPile || (Filters.filter(game.getGameState().getDeadPile(self.getOwner()), game, Filters.name(blueprint.getTitle())).size() == 0)))); + if (!blueprint.isUnique()) + return true; + + final int activeCount = Filters.countActive(game, Filters.name(blueprint.getTitle())); + return activeCount == 0 + && (ignoreCheckingDeadPile || (Filters.filter(game.getGameState().getDeadPile(self.getOwner()), game, Filters.name(blueprint.getTitle())).size() == 0)); } private static int getTotalCompanions(String playerId, LotroGame game) { diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java index 8d375bb7c..b6b0113de 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/at/IndividualCardAtTest.java @@ -20,6 +20,7 @@ import java.util.Map; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; public class IndividualCardAtTest extends AbstractAtTest { @Test @@ -1006,4 +1007,48 @@ public class IndividualCardAtTest extends AbstractAtTest { assertEquals(Zone.DISCARD, randomCard1.getZone()); } + + @Test + public void orcMarksmanUnique() throws CardNotFoundException, DecisionResultInvalidException { + initializeSimplestGame(); + + PhysicalCardImpl marksman1 = new PhysicalCardImpl(100, "40_227", P2, _library.getLotroCardBlueprint("40_227")); + PhysicalCardImpl marksman2 = new PhysicalCardImpl(101, "40_227", P2, _library.getLotroCardBlueprint("40_227")); + + skipMulligans(); + + _game.getGameState().addCardToZone(_game, marksman1, Zone.HAND); + _game.getGameState().addCardToZone(_game, marksman2, Zone.HAND); + + _game.getGameState().addTwilight(10); + + // End fellowship + playerDecided(P1, ""); + + playerDecided(P2, "0"); + assertNull(getCardActionId(_userFeedback.getAwaitingDecision(P2), "Play Orc Mark")); + } + + @Test + public void frodosPipeOncePerPhase() throws CardNotFoundException, DecisionResultInvalidException { + initializeSimplestGame(); + + PhysicalCardImpl frodosPipe = new PhysicalCardImpl(100, "40_250", P1, _library.getLotroCardBlueprint("40_250")); + PhysicalCardImpl pipeweed1 = new PhysicalCardImpl(101, "40_255", P1, _library.getLotroCardBlueprint("40_255")); + PhysicalCardImpl pipeweed2 = new PhysicalCardImpl(102, "40_255", P1, _library.getLotroCardBlueprint("40_255")); + + _game.getGameState().addCardToZone(_game, frodosPipe, Zone.HAND); + _game.getGameState().addCardToZone(_game, pipeweed1, Zone.SUPPORT); + _game.getGameState().addCardToZone(_game, pipeweed2, Zone.SUPPORT); + + skipMulligans(); + + playerDecided(P1, getCardActionId(_userFeedback.getAwaitingDecision(P1), "Attach Frodo's Pipe")); + playerDecided(P1, getCardActionId(_userFeedback.getAwaitingDecision(P1), "Use Frodo's Pipe")); + + playerDecided(P1, String.valueOf(pipeweed1.getCardId())); + playerDecided(P1, "1"); + + assertNull(getCardActionId(_userFeedback.getAwaitingDecision(P1), "Use Frodo's Pipe")); + } }