use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class SabLst method parseTokenWithSeparator.
/**
* This method sets the special abilities granted by this [object]. For
* efficiency, avoid calling this method except from I/O routines.
*
* @param context
* @param obj
* the CDOMbject that is to receive the new SpecialAbility
* @param aString
* String of special abilities delimited by pipes
*/
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String aString) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(aString, Constants.PIPE);
String firstToken = tok.nextToken();
if (looksLikeAPrerequisite(firstToken)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
boolean foundClear = false;
if (Constants.LST_DOT_CLEAR.equals(firstToken)) {
context.getObjectContext().removeList(obj, ListKey.SAB);
if (!tok.hasMoreTokens()) {
return ParseResult.SUCCESS;
}
firstToken = tok.nextToken();
foundClear = true;
}
if (looksLikeAPrerequisite(firstToken)) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
}
if (Constants.LST_DOT_CLEAR.equals(firstToken)) {
return new ParseResult.Fail("SA tag confused by redundant '.CLEAR'" + aString, context);
}
SpecialAbility sa = new SpecialAbility(firstToken.intern());
if (!tok.hasMoreTokens()) {
sa.setName(firstToken.intern());
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
StringBuilder saName = new StringBuilder(aString.length());
saName.append(firstToken);
String token = tok.nextToken();
while (true) {
if (Constants.LST_DOT_CLEAR.equals(token)) {
return new ParseResult.Fail("SA tag confused by '.CLEAR' as a " + "middle token: " + aString, context);
} else if (looksLikeAPrerequisite(token)) {
break;
} else {
saName.append(Constants.PIPE).append(token);
// sa.addVariable(FormulaFactory.getFormulaFor(token));
}
if (!tok.hasMoreTokens()) {
// No prereqs, so we're done
// CONSIDER This is a HACK and not the long term strategy of SA:
sa.setName(saName.toString());
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
token = tok.nextToken();
}
// CONSIDER This is a HACK and not the long term strategy of SA:
sa.setName(saName.toString());
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR and a Special Ability in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put Abilities after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
sa.addPrerequisite(prereq);
if (!tok.hasMoreTokens()) {
break;
}
token = tok.nextToken();
}
context.getObjectContext().addToList(obj, ListKey.SAB, sa);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class MovecloneLst 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 moves = new StringTokenizer(value, Constants.COMMA);
if (moves.countTokens() != 3) {
return new ParseResult.Fail("Invalid Version of MOVECLONE detected: " + value + "\n MOVECLONE has 3 arguments: " + "SourceMove,DestinationMove,Modifier", context);
}
String oldType = moves.nextToken();
String newType = moves.nextToken();
String formulaString = moves.nextToken();
if (formulaString.startsWith("/")) {
try {
int denom = Integer.parseInt(formulaString.substring(1));
if (denom <= 0) {
return new ParseResult.Fail(getTokenName() + " was expecting a Positive Integer " + "for dividing Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow /, was : " + formulaString, context);
}
} else if (formulaString.startsWith("*")) {
try {
float mult = Float.parseFloat(formulaString.substring(1));
if (mult < 0.0) {
return new ParseResult.Fail(getTokenName() + " was expecting a " + "Float >= 0 for multiplying Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow *, was : " + formulaString, context);
}
} else if (formulaString.startsWith("+")) {
try {
int add = Integer.parseInt(formulaString.substring(1));
if (add < 0) {
return new ParseResult.Fail(getTokenName() + " was expecting a Non-Negative " + "Integer for adding Movement, was : " + formulaString.substring(1), context);
}
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting an integer to follow +, was : " + formulaString, context);
}
} else {
try {
Integer.parseInt(formulaString);
} catch (NumberFormatException e) {
return new ParseResult.Fail(getTokenName() + " was expecting a Formula as the final value, was : " + formulaString, context);
}
}
Movement cm = new Movement(2);
cm.assignMovement(0, oldType, "0");
cm.assignMovement(1, newType, formulaString);
cm.setMoveRatesFlag(2);
context.getObjectContext().addToList(obj, ListKey.MOVEMENT, cm);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class KitLst 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 (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
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()) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be a number", context);
}
if (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<Kit>> refs = new ArrayList<>();
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<Kit> ref;
if (Constants.LST_ALL.equals(token)) {
ref = context.getReferenceContext().getCDOMAllReference(KIT_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(KIT_CLASS, token);
}
refs.add(ref);
}
ReferenceChoiceSet<Kit> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<Kit> cs = new ChoiceSet<>(getTokenName(), new QualifiedDecorator<>(rcs));
cs.setTitle("Kit Selection");
TransitionChoice<Kit> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().addToList(obj, ListKey.KIT_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
Aggregations