use of pcgen.base.formula.Formula 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);
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class DrLst 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 (Constants.LST_DOT_CLEAR.equals(value)) {
context.getObjectContext().removeList(obj, ListKey.DAMAGE_REDUCTION);
return ParseResult.SUCCESS;
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
String drString = tok.nextToken();
ParseResult pr = checkForIllegalSeparator('/', drString);
if (!pr.passed()) {
return pr;
}
String[] values = drString.split("/");
if (values.length != 2) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage(getTokenName() + " failed to build DamageReduction with value " + value);
cpr.addErrorMessage(" ...expected a String with one / as a separator");
return cpr;
}
Formula formula = FormulaFactory.getFormulaFor(values[0]);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
DamageReduction dr = new DamageReduction(formula, values[1]);
if (tok.hasMoreTokens()) {
String currentToken = tok.nextToken();
Prerequisite prereq = getPrerequisite(currentToken);
if (prereq == null) {
return ParseResult.INTERNAL_ERROR;
}
dr.addPrerequisite(prereq);
}
context.getObjectContext().addToList(obj, ListKey.DAMAGE_REDUCTION, dr);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SpellLevelToken method parseTokenWithSeparator.
@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
int pipeLoc = value.lastIndexOf('|');
String activeValue;
String title;
if (pipeLoc == -1) {
activeValue = value;
title = getDefaultTitle();
} else {
String titleString = value.substring(pipeLoc + 1);
if (titleString.startsWith("TITLE=")) {
title = titleString.substring(6);
if (title.startsWith("\"")) {
title = title.substring(1, title.length() - 1);
}
activeValue = value.substring(0, pipeLoc);
} else {
activeValue = value;
title = getDefaultTitle();
}
}
pipeLoc = value.indexOf('|');
ParsingSeparator sep = new ParsingSeparator(activeValue, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail("Found no arguments in " + getFullName() + ": " + value, context);
}
List<SpellLevelInfo> sliList = new ArrayList<>();
while (sep.hasNext()) {
String token = sep.next();
PrimitiveCollection<PCClass> pcf = context.getPrimitiveChoiceFilter(context.getReferenceContext().getManufacturer(PCClass.class), token);
if (!sep.hasNext()) {
return new ParseResult.Fail("Expected minimum level argument after " + token + " in " + getFullName() + ": " + value, context);
}
String minLevelString = sep.next();
Formula minLevel = FormulaFactory.getFormulaFor(minLevelString);
if (!sep.hasNext()) {
return new ParseResult.Fail("Expected maximum level argument after " + minLevelString + " in " + getFullName() + ": " + value, context);
}
String maxLevelString = sep.next();
Formula maxLevel = FormulaFactory.getFormulaFor(maxLevelString);
if (!maxLevel.isValid()) {
return new ParseResult.Fail("Max Level Formula in " + getTokenName() + " was not valid: " + maxLevel.toString(), context);
}
SpellLevelInfo sli = new SpellLevelInfo(pcf, minLevel, maxLevel);
sliList.add(sli);
}
SpellLevelChooseInformation tc = new SpellLevelChooseInformation(getTokenName(), sliList);
tc.setTitle(title);
tc.setChoiceActor(this);
context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class LeveladjustmentToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCTemplate template, 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(template, FormulaKey.LEVEL_ADJUSTMENT, formula);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class PlayerCharacter method updateBaseSkillMod.
private int updateBaseSkillMod(PCClass pcClass, int spMod) {
// skill min is 1, unless class gets 0 skillpoints per level (for second
// apprentice class)
final int skillMin = (spMod > 0) ? 1 : 0;
if (pcClass.getSafe(ObjectKey.MOD_TO_SKILLS)) {
spMod += (int) getStatBonusTo("MODSKILLPOINTS", "NUMBER");
if (spMod < 1) {
spMod = 1;
}
}
// Race modifiers apply after Intellegence. BUG 577462
Formula safe = getRace().getSafe(FormulaKey.SKILL_POINTS_PER_LEVEL);
spMod += safe.resolve(this, "").intValue();
// Minimum 1, not sure if bonus
spMod = Math.max(skillMin, spMod);
// level can be < 1, better safe than sorry
for (PCTemplate template : getTemplateSet()) {
spMod += template.getSafe(IntegerKey.BONUS_CLASS_SKILL_POINTS);
}
return spMod;
}
Aggregations