use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class NaturalattacksLst method parseTokenWithSeparator.
/**
* NATURAL WEAPONS CODE <p>first natural weapon is primary, the rest are
* secondary; NATURALATTACKS:primary weapon name,weapon type,num
* attacks,damage|secondary1 weapon name,weapon type,num
* attacks,damage|secondary2 format is exactly as it would be in an
* equipment lst file Type is of the format Weapon.Natural.Melee.Bludgeoning
* number of attacks is the number of attacks with that weapon at BAB (for
* primary), or BAB - 5 (for secondary)
*/
@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);
}
// Currently, this isn't going to work with monk attacks
// - their unarmed stuff won't be affected.
/*
* This does not immediately resolve the Size, because it is an order of
* operations issue. This token must allow the SIZE token to appear
* AFTER this token in the LST file. Thus a deferred resolution (using a
* Resolver) is required.
*/
int count = 1;
StringTokenizer attackTok = new StringTokenizer(value, Constants.PIPE);
while (attackTok.hasMoreTokens()) {
String tokString = attackTok.nextToken();
ParseResult pr = checkForIllegalSeparator(',', tokString);
if (!pr.passed()) {
return pr;
}
Equipment anEquip = createNaturalWeapon(context, obj, tokString.intern());
if (anEquip == null) {
return ParseResult.INTERNAL_ERROR;
//return new ParseResult.Fail("Natural Weapon Creation Failed for : "
// + tokString, context);
}
if (count == 1) {
anEquip.setModifiedName("Natural/Primary");
} else {
anEquip.setModifiedName("Natural/Secondary");
}
anEquip.setOutputIndex(0);
anEquip.setOutputSubindex(count);
// these values need to be locked.
anEquip.setQty(new Float(1));
anEquip.setNumberCarried(new Float(1));
context.getObjectContext().addToList(obj, ListKey.NATURAL_WEAPON, anEquip);
count++;
}
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class SchoolToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Spell spell, String value) {
StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
while (aTok.hasMoreTokens()) {
String tokString = aTok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokString)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context);
}
context.getObjectContext().removeList(spell, ListKey.SPELL_SCHOOL);
} else if (Constants.LST_ALL.equals(tokString)) {
return new ParseResult.Fail(getTokenName() + "used reserved word ALL: " + value, context);
} else if (Constants.LST_ANY.equals(tokString)) {
return new ParseResult.Fail(getTokenName() + "used reserved word ANY: " + value, context);
} else {
SpellSchool ss = context.getReferenceContext().constructNowIfNecessary(SpellSchool.class, tokString);
context.getObjectContext().addToList(spell, ListKey.SPELL_SCHOOL, ss);
}
first = false;
}
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class FaceToken method parseFace.
protected ParseResult parseFace(LoadContext context, PCTemplate fObj, String value) {
if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
}
if (value.indexOf(',') == -1) {
value = value + ',' + 0;
}
@SuppressWarnings("unchecked") FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
ScopeInstance scopeInst = context.getActiveScope();
LegalScope scope = scopeInst.getLegalScope();
PCGenModifier<OrderedPair> modifier;
try {
modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " Modifier SET had value " + value + " but it was not valid: " + iae.getMessage(), context);
}
OrderedPair pair = modifier.process(null);
if (pair.getPreciseX().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
}
if (pair.getPreciseY().doubleValue() < 0.0) {
return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
}
String varName = VAR_NAME;
if (!context.getVariableContext().isLegalVariableID(scope, varName)) {
return new ParseResult.Fail(getTokenName() + " internal error: found invalid fact name: " + varName + ", Modified on " + fObj.getClass().getSimpleName() + ' ' + fObj.getKeyName(), context);
}
VarModifier<OrderedPair> vm = new VarModifier<>(varName, scope, modifier);
context.getObjectContext().addToList(fObj, ListKey.MODIFY, vm);
return ParseResult.SUCCESS;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class HdToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate template, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.COLON);
String hdString = tok.nextToken();
int minhd;
int maxhd;
try {
int minusLoc = hdString.indexOf('-');
if (minusLoc == -1) {
int plusLoc = hdString.indexOf('+');
if (plusLoc == 0) {
return new ParseResult.Fail("Malformed " + getTokenName() + " Cannot start with +: " + hdString, context);
} else if (plusLoc == hdString.length() - 1) {
minhd = Integer.parseInt(hdString.substring(0, hdString.length() - 1));
maxhd = Integer.MAX_VALUE;
} else {
minhd = Integer.parseInt(hdString);
maxhd = minhd;
}
} else {
minhd = Integer.parseInt(hdString.substring(0, minusLoc));
maxhd = Integer.parseInt(hdString.substring(minusLoc + 1));
}
if (maxhd < minhd) {
return new ParseResult.Fail("Malformed " + getTokenName() + " Token (Max < Min): " + hdString, context);
}
} catch (NumberFormatException ex) {
return new ParseResult.Fail("Malformed " + getTokenName() + " Token (HD syntax invalid): " + hdString, context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has one): " + value, context);
}
String typeStr = tok.nextToken();
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail("Invalid " + getTokenName() + ": requires 3 colon separated elements (has two): " + value, context);
}
String argument = tok.nextToken();
PCTemplate derivative = new PCTemplate();
derivative.put(ObjectKey.VISIBILITY, Visibility.HIDDEN);
derivative.put(IntegerKey.HD_MIN, minhd);
derivative.put(IntegerKey.HD_MAX, maxhd);
context.getReferenceContext().getManufacturer(PCTemplate.class).addDerivativeObject(derivative);
context.getObjectContext().addToList(template, ListKey.HD_TEMPLATES, derivative);
try {
if (context.processToken(derivative, typeStr, argument)) {
return ParseResult.SUCCESS;
}
} catch (PersistenceLayerException e) {
return new ParseResult.Fail(e.getMessage(), context);
}
return ParseResult.INTERNAL_ERROR;
}
use of pcgen.rules.persistence.token.ParseResult in project pcgen by PCGen.
the class LangbonusToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCTemplate template, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.COMMA);
boolean foundAny = false;
boolean foundOther = false;
boolean firstToken = true;
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tokText)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
}
context.getListContext().removeAllFromList(getTokenName(), template, Language.STARTING_LIST);
} else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
String clearText = tokText.substring(7);
CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, clearText);
if (lang == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid .CLEAR. reference: " + clearText, context);
}
context.getListContext().removeFromList(getTokenName(), template, Language.STARTING_LIST, lang);
} else {
/*
* Note this is done one-by-one, because .CLEAR. token type
* needs to be able to perform the unlink. That could be
* changed, but the increase in complexity isn't worth it.
* (Changing it to a grouping object that didn't place links in
* the graph would also make it harder to trace the source of
* class skills, etc.)
*/
CDOMReference<Language> lang;
if (Constants.LST_ALL.equals(tokText)) {
foundAny = true;
lang = context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS);
} else {
foundOther = true;
lang = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, tokText);
}
if (lang == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + tokText, context);
}
context.getListContext().addToList(getTokenName(), template, Language.STARTING_LIST, lang);
}
firstToken = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations