Search in sources :

Example 1 with NonInteractive

use of pcgen.cdom.base.NonInteractive in project pcgen by PCGen.

the class RegionLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    String item = tok.nextToken();
    Formula count = FormulaFactory.getFormulaFor(item);
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (count.isStatic()) {
        if (!tok.hasMoreTokens()) {
            return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
        }
        item = tok.nextToken();
        if (count.resolveStatic().intValue() <= 0) {
            return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
        }
    } else {
        count = FormulaFactory.ONE;
    }
    List<Region> regions = new ArrayList<>();
    while (true) {
        regions.add(Region.getConstant(item));
        if (!tok.hasMoreTokens()) {
            break;
        }
        item = tok.nextToken();
    }
    SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
    ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Region Selection");
    TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
    tc.setRequired(false);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) SimpleChoiceSet(pcgen.cdom.choiceset.SimpleChoiceSet) NonInteractive(pcgen.cdom.base.NonInteractive) Region(pcgen.cdom.enumeration.Region)

Example 2 with NonInteractive

use of pcgen.cdom.base.NonInteractive in project pcgen by PCGen.

the class AddLst method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        if (Constants.LST_DOT_CLEAR.equals(value)) {
            if (obj instanceof PCClassLevel) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A non-level limited .CLEAR was " + "used in a Class Level line in " + obj.getKeyName());
                return cpr;
            }
        } else if (value.startsWith(".CLEAR.LEVEL")) {
            if (!(obj instanceof PCClassLevel)) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was not used in a Class Level line in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName());
                return cpr;
            }
            String levelString = value.substring(12);
            try {
                int level = Integer.parseInt(levelString);
                if (level != obj.get(IntegerKey.LEVEL)) {
                    ComplexParseResult cpr = new ComplexParseResult();
                    cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
                    cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
                    cpr.addErrorMessage("  But was asked to clear a " + "different Class Level ( " + level + " ) than the Class Level Line it appeared on: " + obj.getKeyName());
                    return cpr;
                }
            } catch (NumberFormatException e) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
                cpr.addErrorMessage("  A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
                cpr.addErrorMessage("  But the level ( " + levelString + " ) was not an integer in: " + obj.getKeyName());
                return cpr;
            }
        } else {
            return new ParseResult.Fail(getTokenName() + " requires a SubToken and argument, found: " + value, context);
        }
        context.getObjectContext().removeList(obj, ListKey.ADD);
        return ParseResult.SUCCESS;
    }
    return context.processSubToken(obj, getTokenName(), value.substring(0, pipeLoc), value.substring(pipeLoc + 1));
}
Also used : ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) NonInteractive(pcgen.cdom.base.NonInteractive) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 3 with NonInteractive

use of pcgen.cdom.base.NonInteractive in project pcgen by PCGen.

the class ChooseLst method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    String key;
    String val;
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (value.startsWith("FEAT=")) {
        key = "FEATEQ";
        val = value.substring(5);
    } else if (value.startsWith("LANGAUTO:")) {
        key = "LANGAUTO";
        val = value.substring(9);
    } else if (pipeLoc == -1) {
        key = value;
        val = null;
    } else {
        key = value.substring(0, pipeLoc);
        val = value.substring(pipeLoc + 1);
    }
    if (!((obj instanceof Ability) || (obj instanceof Domain) || (obj instanceof Race) || (obj instanceof PCTemplate) || (obj instanceof Skill) || (obj instanceof EquipmentModifier))) {
        //Allow TEMPBONUS related choose
        if (!"NUMBER".equals(key)) {
            return new ParseResult.Fail(getTokenName() + " is not supported for " + obj.getClass().getSimpleName(), context);
        }
    }
    if (key.startsWith("NUMCHOICES=")) {
        String maxCount = key.substring(11);
        if (maxCount == null || maxCount.isEmpty()) {
            return new ParseResult.Fail("NUMCHOICES in CHOOSE must be a formula: " + value, context);
        }
        Formula f = FormulaFactory.getFormulaFor(maxCount);
        if (!f.isValid()) {
            return new ParseResult.Fail("Number of Choices in " + getTokenName() + " was not valid: " + f.toString(), context);
        }
        context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, f);
        pipeLoc = val.indexOf(Constants.PIPE);
        if (pipeLoc == -1) {
            key = val;
            val = null;
        } else {
            key = val.substring(0, pipeLoc);
            val = val.substring(pipeLoc + 1);
        }
    }
    return context.processSubToken(obj, getTokenName(), key, val);
}
Also used : Ability(pcgen.core.Ability) Formula(pcgen.base.formula.Formula) Skill(pcgen.core.Skill) EquipmentModifier(pcgen.core.EquipmentModifier) Race(pcgen.core.Race) NonInteractive(pcgen.cdom.base.NonInteractive) Domain(pcgen.core.Domain) PCTemplate(pcgen.core.PCTemplate) Ungranted(pcgen.cdom.base.Ungranted)

Example 4 with NonInteractive

use of pcgen.cdom.base.NonInteractive in project pcgen by PCGen.

the class KitLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
    if (!count.isValid()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (!count.isStatic()) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be a number", context);
    }
    if (count.resolveStatic().intValue() <= 0) {
        return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
    }
    if (!tok.hasMoreTokens()) {
        return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
    }
    List<CDOMReference<Kit>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<Kit> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
        } else {
            ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
    cs.setTitle("Kit Selection");
    TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.KIT_CHOICE, tc);
    tc.setRequired(false);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) Ungranted(pcgen.cdom.base.Ungranted) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) Kit(pcgen.core.Kit) NonInteractive(pcgen.cdom.base.NonInteractive) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Aggregations

NonInteractive (pcgen.cdom.base.NonInteractive)4 Ungranted (pcgen.cdom.base.Ungranted)4 Formula (pcgen.base.formula.Formula)3 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 ConcreteTransitionChoice (pcgen.cdom.base.ConcreteTransitionChoice)2 CDOMReference (pcgen.cdom.base.CDOMReference)1 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)1 SimpleChoiceSet (pcgen.cdom.choiceset.SimpleChoiceSet)1 Region (pcgen.cdom.enumeration.Region)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 Ability (pcgen.core.Ability)1 Domain (pcgen.core.Domain)1 EquipmentModifier (pcgen.core.EquipmentModifier)1 Kit (pcgen.core.Kit)1 PCTemplate (pcgen.core.PCTemplate)1 Race (pcgen.core.Race)1 Skill (pcgen.core.Skill)1 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)1