use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class LeveladjustmentToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, 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(race, FormulaKey.LEVEL_ADJUSTMENT, formula);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SkilllistToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
TransitionChoice<ClassSkillList> grantChanges = context.getObjectContext().getObject(pcc, ObjectKey.SKILLLIST_CHOICE);
if (grantChanges == null) {
// Zero indicates no Token
return null;
}
StringBuilder sb = new StringBuilder();
Formula count = grantChanges.getCount();
if (count == null) {
context.addWriteMessage("Unable to find " + getTokenName() + " Count");
return null;
}
sb.append(count);
sb.append(Constants.PIPE);
sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
return new String[] { sb.toString() };
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SkilllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<ClassSkillList>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<ClassSkillList> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
}
ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose class-skills this class will inherit");
TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SpelllistToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
TransitionChoice<CDOMListObject<Spell>> grantChanges = context.getObjectContext().getObject(pcc, ObjectKey.SPELLLIST_CHOICE);
if (grantChanges == null) {
// Zero indicates no Token
return null;
}
StringBuilder sb = new StringBuilder();
Formula count = grantChanges.getCount();
if (count == null) {
context.addWriteMessage("Unable to find " + getTokenName() + " Count");
return null;
}
sb.append(count);
sb.append(Constants.PIPE);
sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
return new String[] { sb.toString() };
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class SpelllistToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a | separating " + "count from the list of possible values: " + value, context);
}
List<CDOMReference<? extends CDOMListObject<Spell>>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<? extends CDOMListObject<Spell>> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
} else if (token.startsWith("DOMAIN.")) {
ref = context.getReferenceContext().getCDOMReference(DOMAINSPELLLIST_CLASS, token.substring(7));
} else {
ref = context.getReferenceContext().getCDOMReference(SPELLLIST_CLASS, token);
}
refs.add(ref);
}
PrimitiveChoiceSet<CDOMListObject<Spell>> rcs = new SpellReferenceChoiceSet(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<? extends CDOMListObject<Spell>> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Select class whose list of spells this class will use");
TransitionChoice<CDOMListObject<Spell>> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(pcc, ObjectKey.SPELLLIST_CHOICE, tc);
tc.setRequired(false);
return ParseResult.SUCCESS;
}
Aggregations