Additional validation and tested events
This commit is contained in:
@@ -1,4 +1,26 @@
|
||||
{
|
||||
"1_9": {
|
||||
"title": "Dwarven Axe",
|
||||
"side": "free people",
|
||||
"culture": "dwarven",
|
||||
"cost": 0,
|
||||
"type": "possession",
|
||||
"possession": "hand weapon",
|
||||
"strength": 2,
|
||||
"target": "dwarf",
|
||||
"effects": {
|
||||
"type": "trigger",
|
||||
"trigger": {
|
||||
"type": "losesSkirmish",
|
||||
"filter": "minion",
|
||||
"against": "hasAttached(self)"
|
||||
},
|
||||
"effect": {
|
||||
"type": "discardTopCardFromDeck",
|
||||
"deck": "owner(skirmishLoser)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"1_13": {
|
||||
"title": "Gimli",
|
||||
"subtitle": "Son of Gloin",
|
||||
@@ -31,25 +53,23 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"1_9": {
|
||||
"title": "Dwarven Axe",
|
||||
"1_38": {
|
||||
"title": "Double Shot",
|
||||
"side": "free people",
|
||||
"culture": "dwarven",
|
||||
"culture": "elven",
|
||||
"cost": 0,
|
||||
"type": "possession",
|
||||
"possession": "hand weapon",
|
||||
"strength": 2,
|
||||
"target": "dwarf",
|
||||
"type": "event",
|
||||
"keyword": "archery",
|
||||
"requirement": {
|
||||
"type": "canSpot",
|
||||
"filter": "elf,archer,companion"
|
||||
},
|
||||
"effects": {
|
||||
"type": "trigger",
|
||||
"trigger": {
|
||||
"type": "losesSkirmish",
|
||||
"filter": "minion",
|
||||
"against": "hasAttached(self)"
|
||||
},
|
||||
"type": "event",
|
||||
"effect": {
|
||||
"type": "discardTopCardFromDeck",
|
||||
"deck": "owner(skirmishLoser)"
|
||||
"type": "addArcheryTotal",
|
||||
"side": "free people",
|
||||
"amount": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,12 +51,12 @@
|
||||
"cost": 0,
|
||||
"type": "event",
|
||||
"keyword": "skirmish",
|
||||
"requirement": {
|
||||
"type": "canExert",
|
||||
"filter": "dwarf"
|
||||
},
|
||||
"effects": {
|
||||
"type": "event",
|
||||
"requirement": {
|
||||
"type": "canExert",
|
||||
"filter": "dwarf"
|
||||
},
|
||||
"cost": {
|
||||
"type": "exert",
|
||||
"filter": "choose(dwarf)"
|
||||
@@ -75,12 +75,12 @@
|
||||
"cost": 2,
|
||||
"type": "event",
|
||||
"keyword": "skirmish",
|
||||
"requirement": {
|
||||
"type": "canExert",
|
||||
"filter": "name(Gimli)"
|
||||
},
|
||||
"effects": {
|
||||
"type": "event",
|
||||
"requirement": {
|
||||
"type": "canExert",
|
||||
"filter": "name(Gimli)"
|
||||
},
|
||||
"cost": {
|
||||
"type": "exert",
|
||||
"filter": "choose(name(Gimli))",
|
||||
|
||||
@@ -372,7 +372,7 @@ public class BuiltLotroCardBlueprint implements LotroCardBlueprint {
|
||||
return true;
|
||||
|
||||
for (PlayRequirement playRequirement : playRequirements) {
|
||||
if (!playRequirement.accepts(game, self))
|
||||
if (!playRequirement.accepts(null, game, self, null, null))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public class LotroCardBlueprintBuilder implements CardGenerationEnvironment {
|
||||
fieldProcessors.put("direction", new DirectionFieldProcessor());
|
||||
fieldProcessors.put("effects", new EffectFieldProcessor());
|
||||
fieldProcessors.put("target", new TargetFieldProcessor());
|
||||
fieldProcessors.put("requirement", new RequirementFieldProcessor());
|
||||
}
|
||||
|
||||
public LotroCardBlueprint buildFromJson(JSONObject json) throws InvalidCardDefinitionException {
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.gempukku.lotro.cards.build;
|
||||
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||
|
||||
public interface PlayRequirement {
|
||||
boolean accepts(LotroGame game, PhysicalCard self);
|
||||
boolean accepts(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class FieldUtils {
|
||||
|
||||
public static int getInteger(Object value, String key) throws InvalidCardDefinitionException {
|
||||
@@ -68,4 +70,20 @@ public class FieldUtils {
|
||||
}
|
||||
throw new InvalidCardDefinitionException("Unknown type in " + key + " field");
|
||||
}
|
||||
|
||||
public static void validateAllowedFields(JSONObject object, String... fields) throws InvalidCardDefinitionException {
|
||||
Set<String> keys = object.keySet();
|
||||
for (String key : keys) {
|
||||
if (!key.equals("type") && !contains(fields, key))
|
||||
throw new InvalidCardDefinitionException("Unrecognized field: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean contains(String[] fields, String key) {
|
||||
for (String field : fields) {
|
||||
if (field.equals(key))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.gempukku.lotro.cards.build.field;
|
||||
|
||||
import com.gempukku.lotro.cards.build.*;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class RequirementFieldProcessor implements FieldProcessor {
|
||||
@Override
|
||||
public void processField(String key, Object value, BuiltLotroCardBlueprint blueprint, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
final JSONObject[] requirementsArray = FieldUtils.getObjectArray(value, key);
|
||||
for (JSONObject requirement : requirementsArray) {
|
||||
final PlayRequirement playRequirement = environment.getRequirementFactory().getRequirement(requirement, environment);
|
||||
blueprint.appendPlayRequirement(playRequirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import org.json.simple.JSONObject;
|
||||
public class ActivatedEffectProcessor implements EffectProcessor {
|
||||
@Override
|
||||
public void processEffect(JSONObject value, BuiltLotroCardBlueprint blueprint, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "phase", "requirement", "cost", "effect");
|
||||
|
||||
final String[] phaseArray = FieldUtils.getStringArray(value.get("phase"), "phase");
|
||||
|
||||
for (String phaseString : phaseArray) {
|
||||
@@ -19,7 +21,7 @@ public class ActivatedEffectProcessor implements EffectProcessor {
|
||||
|
||||
DefaultActionSource actionSource = new DefaultActionSource();
|
||||
actionSource.addPlayRequirement(
|
||||
(game, self) -> PlayConditions.isPhase(game, phase));
|
||||
(playerId, game, self, effectResult, effect) -> PlayConditions.isPhase(game, phase));
|
||||
EffectUtils.processRequirementsCostsAndEffects(value, environment, actionSource);
|
||||
|
||||
blueprint.appendInPlayPhaseAction(actionSource);
|
||||
|
||||
@@ -5,20 +5,23 @@ import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.field.EffectProcessor;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerActionSource;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerChecker;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ActivatedTriggerEffectProcessor implements EffectProcessor {
|
||||
@Override
|
||||
public void processEffect(JSONObject value, BuiltLotroCardBlueprint blueprint, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "trigger", "requirement", "cost", "effect");
|
||||
|
||||
final JSONObject[] triggerArray = FieldUtils.getObjectArray(value.get("trigger"), "trigger");
|
||||
|
||||
for (JSONObject trigger : triggerArray) {
|
||||
final TriggerChecker triggerChecker = environment.getTriggerCheckerFactory().getTriggerChecker(trigger, environment);
|
||||
final boolean before = triggerChecker.isBefore();
|
||||
|
||||
TriggerActionSource triggerActionSource = EffectUtils.getTriggerActionSource(value, triggerChecker, environment);
|
||||
DefaultActionSource triggerActionSource = new DefaultActionSource();
|
||||
triggerActionSource.addPlayRequirement(triggerChecker);
|
||||
EffectUtils.processRequirementsCostsAndEffects(value, environment, triggerActionSource);
|
||||
|
||||
if (before) {
|
||||
blueprint.appendBeforeActivatedTrigger(triggerActionSource);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DefaultActionSource implements ActionSource {
|
||||
@Override
|
||||
public boolean isValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
for (PlayRequirement playRequirement : playRequirements) {
|
||||
if (!playRequirement.accepts(game, self))
|
||||
if (!playRequirement.accepts(playerId, game, self, effectResult, effect))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,8 @@ public class EffectAppenderFactory {
|
||||
effectAppenderProducers.put("preventdiscardfromplay", new PreventCardEffectAppender());
|
||||
effectAppenderProducers.put("exert", new Exert());
|
||||
effectAppenderProducers.put("addstrength", new AddStrength());
|
||||
effectAppenderProducers.put("addkeyword", new AddStrength());
|
||||
effectAppenderProducers.put("addkeyword", new AddKeyword());
|
||||
effectAppenderProducers.put("addarcherytotal", new AddArcheryTotal());
|
||||
effectAppenderProducers.put("discardtopcardfromdeck", new DiscardTopCardFromDeck());
|
||||
effectAppenderProducers.put("addtwilight", new AddTwilight());
|
||||
effectAppenderProducers.put("wound", new Wound());
|
||||
|
||||
@@ -4,36 +4,39 @@ import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.PlayRequirement;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerActionSource;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerChecker;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class EffectUtils {
|
||||
public static TriggerActionSource getTriggerActionSource(JSONObject value, TriggerChecker triggerChecker, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
TriggerActionSource triggerActionSource = new TriggerActionSource();
|
||||
triggerActionSource.setTriggerChecker(triggerChecker);
|
||||
public static DefaultActionSource getTriggerActionSource(JSONObject value, TriggerChecker triggerChecker, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
DefaultActionSource triggerActionSource = new DefaultActionSource();
|
||||
triggerActionSource.addPlayRequirement(triggerChecker);
|
||||
|
||||
processRequirementsCostsAndEffects(value, environment, triggerActionSource);
|
||||
return triggerActionSource;
|
||||
}
|
||||
|
||||
public static void processRequirementsCostsAndEffects(JSONObject value, CardGenerationEnvironment environment, DefaultActionSource triggerActionSource) throws InvalidCardDefinitionException {
|
||||
public static void processRequirementsCostsAndEffects(JSONObject value, CardGenerationEnvironment environment, DefaultActionSource actionSource) throws InvalidCardDefinitionException {
|
||||
final JSONObject[] requirementArray = FieldUtils.getObjectArray(value.get("requirement"), "requirement");
|
||||
for (JSONObject requirement : requirementArray) {
|
||||
final PlayRequirement playRequirement = environment.getRequirementFactory().getRequirement(requirement, environment);
|
||||
triggerActionSource.addPlayRequirement(playRequirement);
|
||||
actionSource.addPlayRequirement(playRequirement);
|
||||
}
|
||||
|
||||
processCostsAndEffects(value, environment, actionSource);
|
||||
}
|
||||
|
||||
public static void processCostsAndEffects(JSONObject value, CardGenerationEnvironment environment, DefaultActionSource actionSource) throws InvalidCardDefinitionException {
|
||||
final JSONObject[] costArray = FieldUtils.getObjectArray(value.get("cost"), "cost");
|
||||
for (JSONObject cost : costArray) {
|
||||
final EffectAppender effectAppender = environment.getEffectAppenderFactory().getEffectAppender(cost, environment);
|
||||
triggerActionSource.addCost(effectAppender);
|
||||
actionSource.addCost(effectAppender);
|
||||
}
|
||||
|
||||
final JSONObject[] effectArray = FieldUtils.getObjectArray(value.get("effect"), "effect");
|
||||
for (JSONObject effect : effectArray) {
|
||||
final EffectAppender effectAppender = environment.getEffectAppenderFactory().getEffectAppender(effect, environment);
|
||||
triggerActionSource.addEffect(effectAppender);
|
||||
actionSource.addEffect(effectAppender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@ import com.gempukku.lotro.cards.build.BuiltLotroCardBlueprint;
|
||||
import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.field.EffectProcessor;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class EventEffectProcessor implements EffectProcessor {
|
||||
@Override
|
||||
public void processEffect(JSONObject value, BuiltLotroCardBlueprint blueprint, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "cost", "effect");
|
||||
|
||||
DefaultActionSource actionSource = new DefaultActionSource();
|
||||
EffectUtils.processRequirementsCostsAndEffects(value, environment, actionSource);
|
||||
EffectUtils.processCostsAndEffects(value, environment, actionSource);
|
||||
|
||||
blueprint.setPlayEventAction(actionSource);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.field.EffectProcessor;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerActionSource;
|
||||
import com.gempukku.lotro.cards.build.field.effect.trigger.TriggerChecker;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class TriggerEffectProcessor implements EffectProcessor {
|
||||
@Override
|
||||
public void processEffect(JSONObject value, BuiltLotroCardBlueprint blueprint, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "trigger", "optional", "requirement", "cost", "effect");
|
||||
|
||||
final JSONObject[] triggerArray = FieldUtils.getObjectArray(value.get("trigger"), "trigger");
|
||||
final boolean optional = FieldUtils.getBoolean(value.get("optional"), "optional", false);
|
||||
|
||||
@@ -19,7 +20,9 @@ public class TriggerEffectProcessor implements EffectProcessor {
|
||||
final TriggerChecker triggerChecker = environment.getTriggerCheckerFactory().getTriggerChecker(trigger, environment);
|
||||
final boolean before = triggerChecker.isBefore();
|
||||
|
||||
TriggerActionSource triggerActionSource = EffectUtils.getTriggerActionSource(value, triggerChecker, environment);
|
||||
DefaultActionSource triggerActionSource = new DefaultActionSource();
|
||||
triggerActionSource.addPlayRequirement(triggerChecker);
|
||||
EffectUtils.processRequirementsCostsAndEffects(value, environment, triggerActionSource);
|
||||
|
||||
if (before) {
|
||||
if (optional)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.gempukku.lotro.cards.build.field.effect.appender;
|
||||
|
||||
import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import com.gempukku.lotro.cards.build.field.effect.EffectAppender;
|
||||
import com.gempukku.lotro.cards.build.field.effect.EffectAppenderProducer;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.effects.AddUntilEndOfPhaseModifierEffect;
|
||||
import com.gempukku.lotro.logic.modifiers.ArcheryTotalModifier;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class AddArcheryTotal implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "amount", "side");
|
||||
|
||||
final int amount = FieldUtils.getInteger(effectObject.get("amount"), "amount");
|
||||
final Side side = FieldUtils.getEnum(Side.class, effectObject.get("side"), "side");
|
||||
|
||||
MultiEffectAppender result = new MultiEffectAppender();
|
||||
|
||||
result.addEffectAppender(
|
||||
new DelayedAppender() {
|
||||
@Override
|
||||
protected Effect createEffect(CostToEffectAction action, String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
return new AddUntilEndOfPhaseModifierEffect(
|
||||
new ArcheryTotalModifier(self, side, amount));
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import java.util.Collection;
|
||||
public class AddKeyword implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "count", "filter", "memory", "keyword");
|
||||
|
||||
final CountResolver.Count count = CountResolver.resolveCount(effectObject.get("count"), 1);
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
final String memory = FieldUtils.getString(effectObject.get("memory"), "memory", "_temp");
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.Collection;
|
||||
public class AddStrength implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "amount", "count", "filter", "memory");
|
||||
|
||||
final int amount = FieldUtils.getInteger(effectObject.get("amount"), "amount");
|
||||
final CountResolver.Count count = CountResolver.resolveCount(effectObject.get("count"), 1);
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.json.simple.JSONObject;
|
||||
public class AddTwilight implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "amount");
|
||||
|
||||
final int amount = FieldUtils.getInteger(effectObject.get("amount"), "amount");
|
||||
|
||||
return new AbstractEffectAppender() {
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.Collection;
|
||||
public class DiscardFromPlay implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "count", "filter", "memory");
|
||||
|
||||
final CountResolver.Count count = CountResolver.resolveCount(effectObject.get("count"), 1);
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
final String memory = FieldUtils.getString(effectObject.get("memory"), "memory", "_temp");
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.json.simple.JSONObject;
|
||||
public class DiscardTopCardFromDeck implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "deck", "count");
|
||||
|
||||
final String deck = FieldUtils.getString(effectObject.get("deck"), "deck", "owner");
|
||||
final int count = FieldUtils.getInteger(effectObject.get("count"), "count", 1);
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.Collection;
|
||||
public class Exert implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "count", "times", "filter", "memory");
|
||||
|
||||
final CountResolver.Count count = CountResolver.resolveCount(effectObject.get("count"), 1);
|
||||
final int times = FieldUtils.getInteger(effectObject.get("times"), "times", 1);
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.json.simple.JSONObject;
|
||||
public class PreventCardEffectAppender implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "filter", "memory");
|
||||
|
||||
String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
final String memory = FieldUtils.getString(effectObject.get("memory"), "memory", "_temp");
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ import org.json.simple.JSONObject;
|
||||
public class ReplaceInSkirmish implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "filter", "with");
|
||||
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
final String with = FieldUtils.getString(effectObject.get("with"), "with");
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ import org.json.simple.JSONObject;
|
||||
public class StackTopCardOfDrawDeck implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "deck", "where", "count");
|
||||
|
||||
final String deck = FieldUtils.getString(effectObject.get("deck"), "deck", "owner");
|
||||
final String where = FieldUtils.getString(effectObject.get("where"), "where");
|
||||
final int count = FieldUtils.getInteger(effectObject.get("count"), "count", 1);
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.Collection;
|
||||
public class Wound implements EffectAppenderProducer {
|
||||
@Override
|
||||
public EffectAppender createEffectAppender(JSONObject effectObject, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(effectObject, "count", "times", "filter", "memory");
|
||||
|
||||
final CountResolver.Count count = CountResolver.resolveCount(effectObject.get("count"), 1);
|
||||
final int times = FieldUtils.getInteger(effectObject.get("times"), "times", 1);
|
||||
final String filter = FieldUtils.getString(effectObject.get("filter"), "filter");
|
||||
|
||||
@@ -12,11 +12,13 @@ import org.json.simple.JSONObject;
|
||||
public class CanDiscardFromPlay implements RequirementProducer {
|
||||
@Override
|
||||
public PlayRequirement getPlayRequirement(JSONObject object, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(object, "count", "filter");
|
||||
|
||||
final int count = FieldUtils.getInteger(object.get("count"), "count", 1);
|
||||
final String filter = FieldUtils.getString(object.get("filter"), "filter");
|
||||
|
||||
final FilterableSource filterableSource = environment.getFilterFactory().generateFilter(filter);
|
||||
return (game, self) -> {
|
||||
return (playerId, game, self, effectResult, effect) -> {
|
||||
final Filterable filterable = filterableSource.getFilterable(null, game, self, null, null);
|
||||
return PlayConditions.canDiscardFromPlay(self, game, count, filterable);
|
||||
};
|
||||
|
||||
@@ -12,12 +12,14 @@ import org.json.simple.JSONObject;
|
||||
public class CanExert implements RequirementProducer {
|
||||
@Override
|
||||
public PlayRequirement getPlayRequirement(JSONObject object, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(object, "count", "times", "filter");
|
||||
|
||||
final int count = FieldUtils.getInteger(object.get("count"), "count", 1);
|
||||
final int times = FieldUtils.getInteger(object.get("times"), "times", 1);
|
||||
final String filter = FieldUtils.getString(object.get("filter"), "filter");
|
||||
|
||||
final FilterableSource filterableSource = environment.getFilterFactory().generateFilter(filter);
|
||||
return (game, self) -> {
|
||||
return (playerId, game, self, effectResult, effect) -> {
|
||||
final Filterable filterable = filterableSource.getFilterable(null, game, self, null, null);
|
||||
return PlayConditions.canExert(self, game, times, count, filterable);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.gempukku.lotro.cards.build.field.effect.requirement;
|
||||
|
||||
import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.FilterableSource;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.PlayRequirement;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
import com.gempukku.lotro.common.Filterable;
|
||||
import com.gempukku.lotro.logic.timing.PlayConditions;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class CanSpot implements RequirementProducer {
|
||||
@Override
|
||||
public PlayRequirement getPlayRequirement(JSONObject object, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(object, "count", "filter");
|
||||
|
||||
final int count = FieldUtils.getInteger(object.get("count"), "count", 1);
|
||||
final String filter = FieldUtils.getString(object.get("filter"), "filter");
|
||||
|
||||
final FilterableSource filterableSource = environment.getFilterFactory().generateFilter(filter);
|
||||
return (playerId, game, self, effectResult, effect) -> {
|
||||
final Filterable filterable = filterableSource.getFilterable(null, game, self, null, null);
|
||||
return PlayConditions.canSpot(game, count, filterable);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class RequirementFactory {
|
||||
public RequirementFactory() {
|
||||
requirementProducers.put("candiscardfromplay", new CanDiscardFromPlay());
|
||||
requirementProducers.put("canexert", new CanExert());
|
||||
requirementProducers.put("canspot", new CanSpot());
|
||||
}
|
||||
|
||||
public PlayRequirement getRequirement(JSONObject object, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.json.simple.JSONObject;
|
||||
public class AboutToDiscardFromPlay implements TriggerCheckerProducer {
|
||||
@Override
|
||||
public TriggerChecker getTriggerChecker(JSONObject value, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "source", "filter");
|
||||
|
||||
String source = FieldUtils.getString(value.get("source"), "source", "any");
|
||||
String filter = FieldUtils.getString(value.get("filter"), "source");
|
||||
|
||||
@@ -22,7 +24,7 @@ public class AboutToDiscardFromPlay implements TriggerCheckerProducer {
|
||||
|
||||
return new TriggerChecker() {
|
||||
@Override
|
||||
public boolean isTriggerValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
public boolean accepts(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
return TriggerConditions.isGettingDiscardedBy(effect, game,
|
||||
sourceFilter.getFilterable(playerId, game, self, effectResult, effect),
|
||||
affectedFilter.getFilterable(playerId, game, self, effectResult, effect));
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.json.simple.JSONObject;
|
||||
public class LosesSkirmish implements TriggerCheckerProducer {
|
||||
@Override
|
||||
public TriggerChecker getTriggerChecker(JSONObject value, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "filter", "against");
|
||||
|
||||
String loser = FieldUtils.getString(value.get("filter"), "filter", "any");
|
||||
String against = FieldUtils.getString(value.get("against"), "against", "any");
|
||||
|
||||
@@ -22,7 +24,7 @@ public class LosesSkirmish implements TriggerCheckerProducer {
|
||||
|
||||
return new TriggerChecker() {
|
||||
@Override
|
||||
public boolean isTriggerValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
public boolean accepts(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
return TriggerConditions.losesSkirmishInvolving(game, effectResult,
|
||||
loserFilter.getFilterable(playerId, game, self, effectResult, effect),
|
||||
againstFilter.getFilterable(playerId, game, self, effectResult, effect));
|
||||
|
||||
@@ -15,11 +15,13 @@ import org.json.simple.JSONObject;
|
||||
public class PlayedTriggerCheckerProducer implements TriggerCheckerProducer {
|
||||
@Override
|
||||
public TriggerChecker getTriggerChecker(JSONObject value, CardGenerationEnvironment environment) throws InvalidCardDefinitionException {
|
||||
FieldUtils.validateAllowedFields(value, "filter");
|
||||
|
||||
final String filterString = FieldUtils.getString(value.get("filter"), "filter");
|
||||
final FilterableSource filter = environment.getFilterFactory().generateFilter(filterString);
|
||||
return new TriggerChecker() {
|
||||
@Override
|
||||
public boolean isTriggerValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
public boolean accepts(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
final Filterable filterable = filter.getFilterable(playerId, game, self, effectResult, effect);
|
||||
return TriggerConditions.played(game, effectResult, filterable);
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.gempukku.lotro.cards.build.field.effect.trigger;
|
||||
|
||||
import com.gempukku.lotro.cards.build.field.effect.DefaultActionSource;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||
|
||||
public class TriggerActionSource extends DefaultActionSource {
|
||||
private TriggerChecker triggerChecker;
|
||||
|
||||
public void setTriggerChecker(TriggerChecker triggerChecker) {
|
||||
this.triggerChecker = triggerChecker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect) {
|
||||
final boolean triggerValid = triggerChecker.isTriggerValid(playerId, game, self, effectResult, effect);
|
||||
if (!triggerValid)
|
||||
return false;
|
||||
|
||||
return super.isValid(playerId, game, self, effectResult, effect);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
package com.gempukku.lotro.cards.build.field.effect.trigger;
|
||||
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.EffectResult;
|
||||
|
||||
public interface TriggerChecker {
|
||||
boolean isTriggerValid(String playerId, LotroGame game, PhysicalCard self, EffectResult effectResult, Effect effect);
|
||||
import com.gempukku.lotro.cards.build.PlayRequirement;
|
||||
|
||||
public interface TriggerChecker extends PlayRequirement {
|
||||
boolean isBefore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user