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 };
}
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;
}
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;
}
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;
}
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;
}
Aggregations