Search in sources :

Example 1 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class ExchangelevelToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    final StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    if (tok.countTokens() != 4) {
        return new ParseResult.Fail(getTokenName() + " must have 4 | delimited arguments : " + value, context);
    }
    String classString = tok.nextToken();
    CDOMSingleRef<PCClass> cl = context.getReferenceContext().getCDOMReference(PCClass.class, classString);
    String mindlString = tok.nextToken();
    int mindl;
    try {
        mindl = Integer.parseInt(mindlString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + mindlString, context);
    }
    String maxdlString = tok.nextToken();
    int maxdl;
    try {
        maxdl = Integer.parseInt(maxdlString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + maxdlString, context);
    }
    String minremString = tok.nextToken();
    int minrem;
    try {
        minrem = Integer.parseInt(minremString);
    } catch (NumberFormatException nfe) {
        return new ParseResult.Fail(getTokenName() + " expected an integer: " + minremString, context);
    }
    try {
        LevelExchange le = new LevelExchange(cl, mindl, maxdl, minrem);
        context.getObjectContext().put(pcc, ObjectKey.EXCHANGE_LEVEL, le);
        return ParseResult.SUCCESS;
    } catch (IllegalArgumentException e) {
        ComplexParseResult pr = new ComplexParseResult();
        pr.addErrorMessage("Error in " + getTokenName() + ' ' + e.getMessage());
        pr.addErrorMessage("  Token contents: " + value);
        return pr;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) LevelExchange(pcgen.cdom.content.LevelExchange) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass)

Example 2 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class OutputnameLst method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof EquipmentModifier) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addWarningMessage(getTokenName() + " is not valid for an equipment modifier. The " + "FORMATCAT and NAMEOPT tags should be used instead. Will assume " + "NAMEOPT:TEXT=" + value + ". Object was " + obj.toString());
        context.getObjectContext().put(obj, StringKey.NAME_TEXT, value);
        context.getObjectContext().put(obj, ObjectKey.NAME_OPT, EqModNameOpt.valueOfIgnoreCase("TEXT"));
        return cpr;
    }
    context.getObjectContext().put(obj, StringKey.OUTPUT_NAME, value);
    return ParseResult.SUCCESS;
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult)

Example 3 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class VisionLst 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);
    }
    StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
    String visionString = aTok.nextToken();
    if (looksLikeAPrerequisite(visionString)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
    }
    ArrayList<AssociatedPrereqObject> edgeList = new ArrayList<>();
    boolean foundClear = false;
    while (true) {
        if (Constants.LST_DOT_CLEAR.equals(visionString)) {
            context.getListContext().removeAllFromList(getTokenName(), obj, Vision.VISIONLIST);
            foundClear = true;
        } else if (visionString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            try {
                Vision vis = Vision.getVision(visionString.substring(7));
                context.getListContext().removeFromList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vis));
            } catch (IllegalArgumentException e) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Bad Syntax for Cleared Vision in " + getTokenName());
                cpr.addErrorMessage(e.getMessage());
                return cpr;
            }
            foundClear = true;
        } else if (looksLikeAPrerequisite(visionString)) {
            break;
        } else {
            try {
                Vision vision = Vision.getVision(visionString);
                AssociatedPrereqObject edge = context.getListContext().addToList(getTokenName(), obj, Vision.VISIONLIST, new CDOMDirectSingleRef<>(vision));
                edgeList.add(edge);
            } catch (IllegalArgumentException e) {
                ComplexParseResult cpr = new ComplexParseResult();
                cpr.addErrorMessage("Bad Syntax for Vision in " + getTokenName());
                cpr.addErrorMessage(e.getMessage());
                return cpr;
            }
        }
        if (!aTok.hasMoreTokens()) {
            return ParseResult.SUCCESS;
        }
        visionString = aTok.nextToken();
    }
    if (foundClear) {
        return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR or .CLEAR. in " + getTokenName(), context);
    }
    while (true) {
        Prerequisite prereq = getPrerequisite(visionString);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put vision after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        for (AssociatedPrereqObject edge : edgeList) {
            edge.addPrerequisite(prereq);
        }
        if (!aTok.hasMoreTokens()) {
            break;
        }
        visionString = aTok.nextToken();
    }
    return ParseResult.SUCCESS;
}
Also used : CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) ArrayList(java.util.ArrayList) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) Ungranted(pcgen.cdom.base.Ungranted) StringTokenizer(java.util.StringTokenizer) Vision(pcgen.core.Vision) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 4 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class AddLevelToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCTemplate template, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String classString = sep.next();
    if (classString.isEmpty()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Empty Class found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    if (!sep.hasNext()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("No | found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    String numLevels = sep.next();
    if (numLevels.isEmpty()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Empty Level Count found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    if (sep.hasNext()) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage("Two | found in " + getTokenName());
        cpr.addErrorMessage("  " + getTokenName() + " requires at format: Class|LevelCount");
        return cpr;
    }
    CDOMSingleRef<PCClass> cl = context.getReferenceContext().getCDOMReference(PCClass.class, classString);
    Formula f;
    try {
        int lvls = Integer.parseInt(numLevels);
        if (lvls <= 0) {
            return new ParseResult.Fail("Number of Levels granted in " + getTokenName() + " must be greater than zero", context);
        }
        f = FormulaFactory.getFormulaFor(lvls);
    } catch (NumberFormatException nfe) {
        f = FormulaFactory.getFormulaFor(numLevels);
    }
    if (!f.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
    }
    LevelCommandFactory cf = new LevelCommandFactory(cl, f);
    context.getObjectContext().addToList(template, ListKey.ADD_LEVEL, cf);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) ParsingSeparator(pcgen.base.text.ParsingSeparator) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass)

Example 5 with ComplexParseResult

use of pcgen.rules.persistence.token.ComplexParseResult in project pcgen by PCGen.

the class ChoiceToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, SubClass sc, String value) {
    int pipeLoc = value.indexOf('|');
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " has no | separator for arguments: " + value, context);
    }
    if (value.lastIndexOf('|') != pipeLoc) {
        return new ParseResult.Fail(getTokenName() + " has more than two | separated arguments: " + value, context);
    }
    String pstString = value.substring(0, pipeLoc);
    ProhibitedSpellType type;
    try {
        type = ProhibitedSpellType.valueOf(pstString);
    } catch (IllegalArgumentException e) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(getTokenName() + " encountered an invalid Prohibited Spell Type: " + value);
        cpr.addErrorMessage("  Legal values are: " + StringUtil.join(Arrays.asList(ProhibitedSpellType.values()), ", "));
        return cpr;
    }
    if (type.equals(ProhibitedSpellType.SCHOOL) || type.equals(ProhibitedSpellType.SUBSCHOOL) || type.equals(ProhibitedSpellType.DESCRIPTOR)) {
        SpellProhibitor sp = new SpellProhibitor();
        sp.setType(type);
        sp.addValue(value.substring(pipeLoc + 1));
        context.getObjectContext().put(sc, ObjectKey.CHOICE, sp);
        return ParseResult.SUCCESS;
    }
    return new ParseResult.Fail("Invalid TYPE in " + getTokenName() + ": " + pstString, context);
}
Also used : ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ProhibitedSpellType(pcgen.util.enumeration.ProhibitedSpellType) SpellProhibitor(pcgen.core.SpellProhibitor)

Aggregations

ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)25 ParseResult (pcgen.rules.persistence.token.ParseResult)12 StringTokenizer (java.util.StringTokenizer)11 Ungranted (pcgen.cdom.base.Ungranted)6 PCClass (pcgen.core.PCClass)5 ArrayList (java.util.ArrayList)4 Ability (pcgen.core.Ability)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AddingFormula (pcgen.base.formula.AddingFormula)2 DividingFormula (pcgen.base.formula.DividingFormula)2 Formula (pcgen.base.formula.Formula)2 MultiplyingFormula (pcgen.base.formula.MultiplyingFormula)2 SubtractingFormula (pcgen.base.formula.SubtractingFormula)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 CategorizedChooseInformation (pcgen.cdom.base.CategorizedChooseInformation)2 CollectionToChoiceSet (pcgen.cdom.choiceset.CollectionToChoiceSet)2 HitDie (pcgen.cdom.content.HitDie)2 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)2 PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 HitDieFormula (pcgen.cdom.processor.HitDieFormula)2