use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class ChangeprofLst 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);
}
// value should be of the format:
// Name1,TYPE.type1,Name3=Prof1|Name4,Name5=Prof2
//
// e.g.: TYPE.Hammer,Hand Axe=Simple|Urgosh,Waraxe=Martial
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
List<ChangeProf> list = new ArrayList<>();
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
int equalLoc = tokText.indexOf('=');
if (equalLoc < 0) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": No = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
} else if (equalLoc != tokText.lastIndexOf('=')) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Two = found. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
String newType = tokText.substring(equalLoc + 1);
if (newType.isEmpty()) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Result Type. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
if (newType.indexOf(Constants.DOT) != -1) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Invalid (Compound) Result Type: cannot contain a period (.) " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
String[] val = { newType };
CDOMGroupRef<WeaponProf> newTypeProf = context.getReferenceContext().getCDOMTypeReference(WEAPONPROF_CLASS, val);
String profs = tokText.substring(0, equalLoc);
if (profs.isEmpty()) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Improper " + getTokenName() + ": Empty Source Prof. " + "Expect format to be <Prof>,<Prof>=<Prof Type>");
cpr.addErrorMessage(" Token was: " + tokText);
cpr.addErrorMessage(" Tag was: " + value);
return cpr;
}
StringTokenizer pTok = new StringTokenizer(profs, Constants.COMMA);
while (pTok.hasMoreTokens()) {
CDOMReference<WeaponProf> wp = TokenUtilities.getTypeOrPrimitive(context, WEAPONPROF_CLASS, pTok.nextToken());
list.add(new ChangeProf(wp, newTypeProf));
}
}
for (ChangeProf cp : list) {
context.getObjectContext().addToList(obj, ListKey.CHANGEPROF, cp);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted 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.cdom.base.Ungranted in project pcgen by PCGen.
the class CompanionListLst 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);
}
StringTokenizer tok = new StringTokenizer(value, LstUtils.PIPE);
String companionType = tok.nextToken();
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " requires more than just a Type: " + value, context);
}
String list = tok.nextToken();
ParseResult pr = checkForIllegalSeparator(',', list);
if (!pr.passed()) {
return pr;
}
StringTokenizer subTok = new StringTokenizer(list, LstUtils.COMMA);
Set<CDOMReference<Race>> races = new HashSet<>();
boolean foundAny = false;
while (subTok.hasMoreTokens()) {
String tokString = subTok.nextToken();
if (Constants.LST_ANY.equalsIgnoreCase(tokString)) {
foundAny = true;
races.add(context.getReferenceContext().getCDOMAllReference(Race.class));
} else if (tokString.startsWith("RACETYPE=")) {
String raceType = tokString.substring(9);
if (raceType.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " Error: RaceType was not specified.", context);
}
races.add(new ObjectMatchingReference<>(tokString, Race.class, context.getReferenceContext().getCDOMAllReference(Race.class), ObjectKey.RACETYPE, RaceType.getConstant(raceType)));
} else if (tokString.startsWith("RACESUBTYPE=")) {
String raceSubType = tokString.substring(12);
if (raceSubType.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " Error: RaceSubType was not specified.", context);
}
races.add(new ListMatchingReference<>(tokString, Race.class, context.getReferenceContext().getCDOMAllReference(Race.class), ListKey.RACESUBTYPE, RaceSubType.getConstant(raceSubType)));
} else if (looksLikeAPrerequisite(tokString)) {
return new ParseResult.Fail(getTokenName() + " Error: " + tokString + " found where companion race expected.", context);
} else {
races.add(context.getReferenceContext().getCDOMReference(Race.class, tokString));
}
}
if (foundAny && races.size() > 1) {
return new ParseResult.Fail("Non-sensical Race List includes Any and specific races: " + value, context);
}
if (!tok.hasMoreTokens()) {
// No other args, so we're done
finish(context, obj, companionType, races, null, null);
return ParseResult.SUCCESS;
}
// The remainder of the elements are optional.
Integer followerAdjustment = null;
String optArg = tok.nextToken();
while (true) {
if (optArg.startsWith(FOLLOWERADJUSTMENT)) {
if (followerAdjustment != null) {
return new ParseResult.Fail(getTokenName() + " Error: Multiple " + FOLLOWERADJUSTMENT + " tags specified.", context);
}
int faStringLength = FOLLOWERADJUSTMENT.length();
if (optArg.length() <= faStringLength + 1) {
return new ParseResult.Fail("Empty FOLLOWERADJUSTMENT value in " + getTokenName() + " is prohibited", context);
}
String adj = optArg.substring(faStringLength + 1);
try {
followerAdjustment = Integer.valueOf(adj);
} catch (NumberFormatException nfe) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Expecting a number for FOLLOWERADJUSTMENT: " + adj);
cpr.addErrorMessage(" was parsing Token " + getTokenName());
return cpr;
}
} else if (looksLikeAPrerequisite(optArg)) {
break;
} else {
return new ParseResult.Fail(getTokenName() + ": Unknown argument (was expecting FOLLOWERADJUSTMENT: or PRExxx): " + optArg, context);
}
if (!tok.hasMoreTokens()) {
// No prereqs, so we're done
finish(context, obj, companionType, races, followerAdjustment, null);
return ParseResult.SUCCESS;
}
optArg = tok.nextToken();
}
List<Prerequisite> prereqs = new ArrayList<>();
while (true) {
Prerequisite prereq = getPrerequisite(optArg);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
if (!tok.hasMoreTokens()) {
break;
}
optArg = tok.nextToken();
}
finish(context, obj, companionType, races, followerAdjustment, prereqs);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class CskillLst 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);
}
boolean first = true;
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokText)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(obj, ListKey.CSKILL);
} else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
String clearText = tokText.substring(7);
if (Constants.LST_ALL.equals(clearText)) {
context.getObjectContext().removeFromList(obj, ListKey.CSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
} else if (Constants.LST_LIST.equals(clearText)) {
context.getObjectContext().removeFromList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
} else {
CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getObjectContext().removeFromList(obj, ListKey.CSKILL, ref);
}
} else {
/*
* Note this HAS to be done one-by-one, because the
* .clearChildNodeOfClass method above does NOT recognize the
* C/CC Skill object and therefore doesn't know how to search
* the sublists
*/
if (Constants.LST_ALL.equals(tokText)) {
foundAny = true;
context.getObjectContext().addToList(obj, ListKey.CSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
} else {
foundOther = true;
if (Constants.LST_LIST.equals(tokText)) {
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
} else {
CDOMReference<Skill> ref = getSkillReference(context, tokText);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered " + "while parsing " + getTokenName(), context);
}
context.getObjectContext().addToList(obj, ListKey.CSKILL, ref);
}
}
}
first = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted 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;
}
Aggregations