Search in sources :

Example 36 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class AddVFeatToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String addType = sep.next();
    if (!"VFEAT".equals(addType)) {
        return new ParseResult.Fail("Incompatible with ADD:VFEAT: " + value);
    }
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in ADD:VFEAT must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail("ADD:VFEAT had too many pipe separated items: " + value, context);
    }
    try {
        if (!context.processToken(obj, "ADD", "ABILITY|" + count.toString() + "|FEAT|VIRTUAL|" + activeValue)) {
            Logging.replayParsedMessages();
            return new ParseResult.Fail("Delegation Error from ADD:VFEAT");
        }
    } catch (PersistenceLayerException e) {
        return new ParseResult.Fail("Delegation Error from ADD:VFEAT: " + e.getLocalizedMessage());
    }
    return ParseResult.SUCCESS;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 37 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class UserInputToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    UserChooseInformation ci = new UserChooseInformation();
    if (value != null) {
        int pipeLoc = value.indexOf('|');
        String titleString;
        if (pipeLoc == -1) {
            titleString = value;
        } else {
            String countString = value.substring(0, pipeLoc);
            Logging.deprecationPrint("CHOOSE:USERINPUT with count is deprecated, " + "please use SELECT: to identify the quantity of selections", context);
            int firstarg;
            try {
                firstarg = Integer.parseInt(countString);
            } catch (NumberFormatException nfe) {
                return new ParseResult.Fail("If CHOOSE:" + getTokenName() + " contains a pipe, " + "first argument must be an Integer : " + value, context);
            }
            Formula count = FormulaFactory.getFormulaFor(firstarg);
            context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, count);
            context.getObjectContext().put(obj, FormulaKey.SELECT, count);
            titleString = value.substring(pipeLoc + 1);
        }
        if (!titleString.startsWith("TITLE=")) {
            return new ParseResult.Fail("CHOOSE:" + getTokenName() + " in " + obj.getClass() + " " + obj.getKeyName() + " had invalid arguments: " + value, context);
        }
        String title = titleString.substring(6);
        if (title.startsWith("\"")) {
            title = title.substring(1, title.length() - 1);
        }
        ci.setTitle(title);
    } else {
        ci.setTitle(getDefaultTitle());
    }
    // No args - legal
    context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, ci);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParseResult(pcgen.rules.persistence.token.ParseResult) UserChooseInformation(pcgen.cdom.base.UserChooseInformation)

Example 38 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class PageUsageToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
    Formula formula = FormulaFactory.getFormulaFor(value);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    context.getObjectContext().put(eq, FormulaKey.PAGE_USAGE, formula);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 39 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class CostpreToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, EquipmentModifier mod, String value) {
    Formula formula = FormulaFactory.getFormulaFor(value);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    context.getObjectContext().put(mod, FormulaKey.BASECOST, formula);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula)

Example 40 with Formula

use of pcgen.base.formula.Formula in project pcgen by PCGen.

the class DefineLst method parseToken.

@Override
public ParseResult parseToken(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);
    }
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    if (!sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " may not be empty", context);
    }
    String firstItem = sep.next();
    if (firstItem.startsWith("UNLOCK.")) {
        return new ParseResult.Fail("DEFINE:UNLOCK. has been deprecated, " + "please use DEFINESTAT:STAT| or DEFINESTAT:UNLOCK|", context);
    }
    if (!sep.hasNext()) {
        return new ParseResult.Fail(getTokenName() + " varName|varFormula" + "or LOCK.<stat>|value syntax requires an argument", context);
    }
    String var = firstItem;
    if (var.isEmpty()) {
        return new ParseResult.Fail("Empty Variable Name found in " + getTokenName() + ": " + value, context);
    }
    try {
        Formula f = FormulaFactory.getFormulaFor(sep.next());
        if (!f.isValid()) {
            return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
        }
        if ((!f.isStatic() || f.resolveStatic().intValue() != 0) && !(var.startsWith("MAXLEVELSTAT="))) {
            Logging.deprecationPrint("DEFINE with a non zero value has been deprecated, " + "please use a DEFINE of 0 and an appropriate bonus. Tag was DEFINE:" + value + " in " + obj, context);
        }
        if (sep.hasNext()) {
            return new ParseResult.Fail(getTokenName() + ' ' + firstItem + " syntax requires only one argument: " + value, context);
        }
        if (value.startsWith("LOCK.")) {
            return new ParseResult.Fail("DEFINE:LOCK. has been deprecated, " + "please use DEFINESTAT:LOCL| or DEFINESTAT:NONSTAT|", context);
        } else {
            context.getObjectContext().put(obj, VariableKey.getConstant(var), f);
        }
        return ParseResult.SUCCESS;
    } catch (IllegalArgumentException e) {
        return new ParseResult.Fail("Illegal Formula found in " + getTokenName() + ": " + value + ' ' + e.getLocalizedMessage(), context);
    }
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) ParseResult(pcgen.rules.persistence.token.ParseResult) Ungranted(pcgen.cdom.base.Ungranted)

Aggregations

Formula (pcgen.base.formula.Formula)106 ArrayList (java.util.ArrayList)30 ParsingSeparator (pcgen.base.text.ParsingSeparator)26 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 CDOMReference (pcgen.cdom.base.CDOMReference)16 StringTokenizer (java.util.StringTokenizer)15 ChoiceSet (pcgen.cdom.base.ChoiceSet)11 Ungranted (pcgen.cdom.base.Ungranted)10 CDOMObject (pcgen.cdom.base.CDOMObject)9 PersistentTransitionChoice (pcgen.cdom.base.PersistentTransitionChoice)9 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)8 PCClass (pcgen.core.PCClass)7 Prerequisite (pcgen.core.prereq.Prerequisite)7 Map (java.util.Map)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)6 PCTemplate (pcgen.core.PCTemplate)6 Race (pcgen.core.Race)6 Spell (pcgen.core.spell.Spell)6 HashMap (java.util.HashMap)5