Search in sources :

Example 16 with Formula

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

the class TotalCostToken method unparse.

@Override
public String[] unparse(LoadContext context, Kit kit) {
    QualifiedObject<Formula> qo = kit.get(ObjectKey.KIT_TOTAL_COST);
    if (qo == null) {
        return null;
    }
    Formula f = qo.getRawObject();
    List<Prerequisite> prereqs = qo.getPrerequisiteList();
    String ab = f.toString();
    if (prereqs != null && !prereqs.isEmpty()) {
        ab = ab + Constants.PIPE + getPrerequisiteString(context, prereqs);
    }
    return new String[] { ab };
}
Also used : Formula(pcgen.base.formula.Formula) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 17 with Formula

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

the class CrToken method parseNonEmptyToken.

@Override
public ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    try {
        int intRating = Integer.parseInt(value.startsWith("1/") ? value.substring(2) : value);
        if (intRating < 0) {
            return new ParseResult.Fail(getTokenName() + " Challenge Rating cannot be negative", context);
        }
    } catch (NumberFormatException e) {
        return new ParseResult.Fail(getTokenName() + "Challenge Rating must be a positive integer i or 1/i", context);
    }
    Formula formula = FormulaFactory.getFormulaFor(value);
    if (!formula.isValid()) {
        return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
    }
    ChallengeRating cr = new ChallengeRating(formula);
    context.getObjectContext().put(race, ObjectKey.CHALLENGE_RATING, cr);
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ChallengeRating(pcgen.cdom.content.ChallengeRating) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 18 with Formula

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

the class CastToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
    context.getObjectContext().removeList(level, ListKey.CAST);
    ParsingSeparator sep = new ParsingSeparator(value, ',');
    sep.addGroupingPair('(', ')');
    while (sep.hasNext()) {
        String tok = sep.next();
        try {
            if (Integer.parseInt(tok) < 0) {
                return new ParseResult.Fail("Invalid Spell Count: " + tok + " is less than zero", context);
            }
        } catch (NumberFormatException e) {
        // OK, it must be a formula...
        }
        Formula formula = FormulaFactory.getFormulaFor(tok);
        if (!formula.isValid()) {
            return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
        }
        context.getObjectContext().addToList(level, ListKey.CAST, formula);
    }
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator)

Example 19 with Formula

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

the class SpecialtyknownToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
    context.getObjectContext().removeList(level, ListKey.SPECIALTYKNOWN);
    ParsingSeparator sep = new ParsingSeparator(value, ',');
    sep.addGroupingPair('(', ')');
    while (sep.hasNext()) {
        String tok = sep.next();
        try {
            if (Integer.parseInt(tok) < 0) {
                return new ParseResult.Fail("Invalid Spell Count: " + tok + " is less than zero", context);
            }
        } catch (NumberFormatException e) {
        // OK, it must be a formula...
        }
        Formula formula = FormulaFactory.getFormulaFor(tok);
        if (!formula.isValid()) {
            return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
        }
        context.getObjectContext().addToList(level, ListKey.SPECIALTYKNOWN, formula);
    }
    return ParseResult.SUCCESS;
}
Also used : Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator)

Example 20 with Formula

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

the class CrToken method process.

@Override
public boolean process(LoadContext context, Race race) {
    Formula levelAdjFormula = race.getSafe(FormulaKey.LEVEL_ADJUSTMENT);
    if (levelAdjFormula.isStatic()) {
        Number la = levelAdjFormula.resolveStatic();
        ChallengeRating cr = race.get(ObjectKey.CHALLENGE_RATING);
        if ((la.floatValue() != 0) && cr == null) {
            race.put(ObjectKey.CHALLENGE_RATING, new ChallengeRating(FormulaFactory.getFormulaFor(la.toString())));
        }
    }
    //TODO Should there at LEAST be a message in an else??
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) ChallengeRating(pcgen.cdom.content.ChallengeRating)

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