Actions that have phase limits should be working correctly now

This commit is contained in:
marcin.sciesinski
2019-08-19 08:58:33 -07:00
parent c1cdd6ec4d
commit 14307937a3
7 changed files with 74 additions and 68 deletions

View File

@@ -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<? extends Action> 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;

View File

@@ -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<String, Object> getDecisionParameters() {
Map<String, Object> 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

View File

@@ -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<String, Object> getDecisionParameters() {
Map<String, Object> 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

View File

@@ -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<String, Object> getDecisionParameters() {
Map<String, Object> 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;
}
}

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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"));
}
}