use of pcgen.cdom.base.Ungranted 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.cdom.base.Ungranted in project pcgen by PCGen.
the class SelectLst method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject cdo, String value) {
if (cdo instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + cdo.getClass().getSimpleName(), context);
}
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
context.getObjectContext().put(cdo, FormulaKey.SELECT, formula);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class DefineLst method parseToken.
@Override
public ParseResult parseToken(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);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String firstItem = sep.next();
if (firstItem.startsWith("UNLOCK.")) {
return new ParseResult.Fail("DEFINE:UNLOCK. has been deprecated, " + "please use DEFINESTAT:STAT| or DEFINESTAT:UNLOCK|", context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " varName|varFormula" + "or LOCK.<stat>|value syntax requires an argument", context);
}
String var = firstItem;
if (var.isEmpty()) {
return new ParseResult.Fail("Empty Variable Name found in " + getTokenName() + ": " + value, context);
}
try {
Formula f = FormulaFactory.getFormulaFor(sep.next());
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
if ((!f.isStatic() || f.resolveStatic().intValue() != 0) && !(var.startsWith("MAXLEVELSTAT="))) {
Logging.deprecationPrint("DEFINE with a non zero value has been deprecated, " + "please use a DEFINE of 0 and an appropriate bonus. Tag was DEFINE:" + value + " in " + obj, context);
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + ' ' + firstItem + " syntax requires only one argument: " + value, context);
}
if (value.startsWith("LOCK.")) {
return new ParseResult.Fail("DEFINE:LOCK. has been deprecated, " + "please use DEFINESTAT:LOCL| or DEFINESTAT:NONSTAT|", context);
} else {
context.getObjectContext().put(obj, VariableKey.getConstant(var), f);
}
return ParseResult.SUCCESS;
} catch (IllegalArgumentException e) {
return new ParseResult.Fail("Illegal Formula found in " + getTokenName() + ": " + value + ' ' + e.getLocalizedMessage(), context);
}
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class DefineStatLst method parseToken.
@Override
public ParseResult parseToken(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);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " may not be empty", context);
}
String firstItem = sep.next();
DefineStatSubToken subToken;
try {
subToken = DefineStatSubToken.valueOf(firstItem);
} catch (IllegalArgumentException e1) {
return new ParseResult.Fail("Found unexpected sub tag " + firstItem + " in " + getTokenName() + Constants.COLON + value + ". Must be one of " + StringUtils.join(DefineStatSubToken.values(), ", ") + Constants.DOT, context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + subToken + "| must be followed by a stat.", context);
}
String statKey = sep.next();
CDOMSingleRef<PCStat> stat = context.getReferenceContext().getCDOMReference(PCSTAT_CLASS, statKey);
Formula f = null;
if (subToken == DefineStatSubToken.LOCK || subToken == DefineStatSubToken.MINVALUE || subToken == DefineStatSubToken.MAXVALUE) {
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + subToken + "| must be followed by both a stat and a value.", context);
}
String formula = sep.next();
f = FormulaFactory.getFormulaFor(formula);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
}
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + Constants.COLON + value + " has too many pipe separated item.", context);
}
switch(subToken) {
case LOCK:
context.getObjectContext().addToList(obj, ListKey.STAT_LOCKS, new StatLock(stat, f));
break;
case UNLOCK:
context.getObjectContext().addToList(obj, ListKey.UNLOCKED_STATS, stat);
break;
case NONSTAT:
context.getObjectContext().addToList(obj, ListKey.NONSTAT_STATS, stat);
break;
case STAT:
context.getObjectContext().addToList(obj, ListKey.NONSTAT_TO_STAT_STATS, stat);
break;
case MINVALUE:
context.getObjectContext().addToList(obj, ListKey.STAT_MINVALUE, new StatLock(stat, f));
break;
case MAXVALUE:
context.getObjectContext().addToList(obj, ListKey.STAT_MAXVALUE, new StatLock(stat, f));
break;
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class FollowersLst method parseToken.
@Override
public ParseResult parseToken(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 ((value == null) || value.isEmpty()) {
return new ParseResult.Fail("Argument in " + getTokenName() + " cannot be empty", context);
}
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String followerType = sep.next();
if (followerType.isEmpty()) {
return new ParseResult.Fail("Follower Type in " + getTokenName() + " cannot be empty", context);
}
if (!sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " has no PIPE character: " + "Must be of the form <follower type>|<formula>", context);
}
String followerNumber = sep.next();
if (sep.hasNext()) {
return new ParseResult.Fail(getTokenName() + " has too many PIPE characters: " + "Must be of the form <follower type>|<formula", context);
}
if (followerNumber.isEmpty()) {
return new ParseResult.Fail("Follower Count in " + getTokenName() + " cannot be empty", context);
}
CDOMSingleRef<CompanionList> cl = context.getReferenceContext().getCDOMReference(CompanionList.class, followerType);
Formula num = FormulaFactory.getFormulaFor(followerNumber);
if (!num.isValid()) {
return new ParseResult.Fail("Number of Followers in " + getTokenName() + " was not valid: " + num.toString(), context);
}
context.getObjectContext().addToList(obj, ListKey.FOLLOWERS, new FollowerLimit(cl, num));
return ParseResult.SUCCESS;
}
Aggregations