Fixing preventable actions

This commit is contained in:
marcin.sciesinski
2019-09-07 12:02:57 -07:00
parent cc5bc91a5e
commit d2701f10d2
4 changed files with 220 additions and 12 deletions

View File

@@ -0,0 +1,150 @@
{
"0_56": {
"title": "*Ghân-buri-Ghân",
"subtitle": "Chieftain of the Woses",
"culture": "gandalf",
"cost": 2,
"type": "companion",
"race": "man",
"strength": 6,
"vitality": 3,
"resistance": 5,
"effects": [
{
"type": "modifier",
"modifier": {
"type": "cantBeOverwhelmedMultiplier",
"filter": "self",
"condition": {
"type": "canSpot",
"filter": "another,man",
"count": 2
}
}
},
{
"type": "modifier",
"modifier": {
"type": "addKeyword",
"filter": "self",
"condition": {
"type": "location",
"filter": "forest"
},
"keyword": "defender+1"
}
}
]
},
"0_57": {
"title": "*Radagast's Staff",
"culture": "gandalf",
"cost": 1,
"type": "artifact",
"possession": "staff",
"strength": 1,
"vitality": 1,
"target": "name(Radagast)",
"effects": {
"type": "trigger",
"optional": true,
"trigger": {
"type": "moves"
},
"condition": {
"type": "phase",
"phase": "regroup"
},
"effect": {
"type": "drawCards",
"count": 2
}
}
},
/**
* Set: Promotional
* Side: Free
* Culture: Gondor
* Twilight Cost: 3
* Type: Companion Man
* Strength: 7
* Vitality: 3
* Resistance: 6
* Game Text: Skirmish: Play a [GONDOR] skirmish event to make each minion skirmishing Anarion strength -X, where X is
* Anarion's vitality.
*/
"0_58": {
"title": "*Anarion",
"subtitle": "Lord of Anorien",
"culture": "gondor",
"cost": 3,
"type": "companion",
"race": "man",
"strength": 7,
"vitality": 3,
"resistance": 6,
"effects": {
"type": "activated",
"phase": "skirmish",
"cost": {
"type": "play",
"filter": "choose(culture(gondor),skirmish,event)"
},
"effect": {
"type": "modifyStrength",
"filter": "all(minion,inSkirmishAgainst(self))",
"amount": {
"type": "vita"
}
}
}
},
"0_62": {
"title": "*Gimli",
"subtitle": "Dwarven Delegate",
"culture": "dwarven",
"cost": 2,
"type": "companion",
"race": "dwarf",
"strength": 7,
"vitality": 3,
"resistance": 6,
"keyword": "damage+1"
},
"0_63": {
"title": "*Arwen",
"subtitle": "Maiden of Rivendell",
"culture": "elven",
"cost": 2,
"type": "companion",
"race": "elf",
"strength": 6,
"vitality": 3,
"resistance": 6,
"keyword": "ranger",
"effects": {
"type": "activated",
"phase": "skirmish",
"cost": {
"type": "exert",
"filter": "self"
},
"effect": {
"type": "modifyStrength",
"filter": "choose(minion,inSkirmishAgainst(elf))",
"amount": -2
}
}
},
"0_64": {
"title": "*Gandalf",
"subtitle": "Stormcraw",
"culture": "gandalf",
"cost": 4,
"type": "companion",
"race": "wizard",
"strength": 8,
"vitality": 4,
"resistance": 6
}
}

View File

@@ -45,6 +45,24 @@ public class PreventableAppenderProducer implements EffectAppenderProducer {
preventingPlayer, actionContext.getGame(), actionContext.getSource(), actionContext.getEffectResult(),
actionContext.getEffect());
costAppender.appendEffect(false, subAction, delegate);
subAction.appendEffect(
new UnrespondableEffect() {
@Override
protected void doPlayEffect(LotroGame game) {
// If the prevention was not carried out, need to do the original action anyway
if (!subAction.wasCarriedOut())
effectAppender.appendEffect(false, subAction, actionContext);
}
@Override
public boolean wasCarriedOut() {
// Cheating a bit, we need to check, if the preventing effect was carried out,
// but have no way of doing this, as we can do that through subAction only,
// and this checking effect should be ALWAYS considered fine, even before it
// was done
return true;
}
});
}
@Override
@@ -52,16 +70,6 @@ public class PreventableAppenderProducer implements EffectAppenderProducer {
effectAppender.appendEffect(false, subAction, actionContext);
}
}));
subAction.appendEffect(
new UnrespondableEffect() {
@Override
protected void doPlayEffect(LotroGame game) {
// If the prevention was not carried out, need to do the original action anyway
if (!subAction.wasCarriedOut())
effectAppender.appendEffect(false, subAction, actionContext);
}
}
);
return new StackActionEffect(subAction);
} else {
SubAction subAction = new SubAction(action);

View File

@@ -10,18 +10,22 @@ import org.json.simple.JSONObject;
public class CantBeOverwhelmedMultiplier implements ModifierSourceProducer {
@Override
public ModifierSource getModifierSource(JSONObject object, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
FieldUtils.validateAllowedFields(object, "filter", "multiplier");
FieldUtils.validateAllowedFields(object, "filter", "condition", "multiplier");
final String filter = FieldUtils.getString(object.get("filter"), "filter");
final JSONObject[] conditionArray = FieldUtils.getObjectArray(object.get("condition"), "condition");
final int multiplier = FieldUtils.getInteger(object.get("multiplier"), "multiplier", 3);
final FilterableSource filterableSource = environment.getFilterFactory().generateFilter(filter, environment);
final Requirement[] requirements = environment.getRequirementFactory().getRequirements(conditionArray, environment);
return new ModifierSource() {
@Override
public Modifier getModifier(ActionContext actionContext) {
final Filterable filterable = filterableSource.getFilterable(actionContext);
return new OverwhelmedByMultiplierModifier(actionContext.getSource(), filterable, multiplier);
return new OverwhelmedByMultiplierModifier(actionContext.getSource(), filterable,
new RequirementCondition(requirements, actionContext),
multiplier);
}
};
}

View File

@@ -202,6 +202,52 @@ public class NewCardsAtTest extends AbstractAtTest {
assertNull(_userFeedback.getAwaitingDecision(P1));
}
@Test
public void preventableEffect() throws DecisionResultInvalidException, CardNotFoundException {
initializeSimplestGame();
PhysicalCardImpl boromir = createCard(P1, "40_101");
PhysicalCardImpl gauntlets = createCard(P1, "40_103");
PhysicalCardImpl nazgul = createCard(P2, "40_211");
_game.getGameState().addCardToZone(_game, boromir, Zone.SUPPORT);
_game.getGameState().attachCard(_game, gauntlets, boromir);
_game.getGameState().addCardToZone(_game, nazgul, Zone.SHADOW_CHARACTERS);
skipMulligans();
// Pass in fellowship
playerDecided(P1, "");
// Pass in shadow
playerDecided(P2, "");
// Pass in maneuver
playerDecided(P1, "");
playerDecided(P2, "");
// Pass in archery
playerDecided(P1, "");
playerDecided(P2, "");
// Pass in assignment
playerDecided(P1, "");
playerDecided(P2, "");
playerDecided(P1, boromir.getCardId() + " " + nazgul.getCardId());
playerDecided(P1, "" + boromir.getCardId());
final int twilightPool = _game.getGameState().getTwilightPool();
// Use Gauntlets
playerDecided(P1, "0");
playerDecided(P2, "0");
assertEquals(twilightPool - 1, _game.getGameState().getTwilightPool());
}
@Test
public void costToEffect() throws DecisionResultInvalidException, CardNotFoundException {
initializeSimplestGame();