use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class GrantLst 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, Constants.PIPE);
String scope = tok.nextToken();
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have identifier(s), " + "Format is: DYNAMICSCOPE|DynamicName: " + value, context);
}
ReferenceManufacturer<Dynamic> rm = context.getReferenceContext().getManufacturer(DYNAMIC_CLASS, DYNAMIC_CATEGORY_CLASS, scope);
if (rm == null) {
return new ParseResult.Fail("Could not get Reference Manufacturer for Dynamic Scope: " + scope, context);
}
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
CDOMReference<Dynamic> dynamic = rm.getReference(token);
if (dynamic == null) {
return ParseResult.INTERNAL_ERROR;
}
context.getObjectContext().addToList(obj, ListKey.GRANTED, dynamic);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class AbilityLst 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, Constants.PIPE);
String cat = tok.nextToken();
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(ABILITY_CATEGORY_CLASS, cat);
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have a Nature, " + "Format is: CATEGORY|NATURE|AbilityName: " + value, context);
}
final String natureKey = tok.nextToken();
Nature nature;
try {
nature = Nature.valueOf(natureKey);
} catch (IllegalArgumentException iae) {
return new ParseResult.Fail(getTokenName() + " refers to invalid Ability Nature: " + natureKey, context);
}
if (Nature.ANY.equals(nature)) {
return new ParseResult.Fail(getTokenName() + " refers to ANY Ability Nature, cannot be used in " + getTokenName() + ": " + value, context);
}
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " must have abilities, Format is: " + "CATEGORY|NATURE|AbilityName: " + value, context);
}
String token = tok.nextToken();
if (looksLikeAPrerequisite(token)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
}
String lkString = "GA_CA_" + cat + '_' + natureKey;
ListKey glk = ListKey.getKeyFor(ChooseSelectionActor.class, lkString);
ListKey<ChooseSelectionActor<?>> lk = glk;
ArrayList<PrereqObject> edgeList = new ArrayList<>();
CDOMReference<AbilityList> abilList = AbilityList.getAbilityListReference(acRef, nature);
boolean first = true;
boolean removed = false;
ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, ABILITY_CATEGORY_CLASS, cat);
if (rm == null) {
return new ParseResult.Fail("Could not get Reference Manufacturer for Category: " + cat, context);
}
boolean prereqsAllowed = true;
while (true) {
if (Constants.LST_DOT_CLEAR.equals(token)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context);
}
context.getListContext().removeAllFromList(getTokenName(), obj, abilList);
context.getObjectContext().removeFromList(obj, ListKey.GA_CAKEYS, lk);
context.getObjectContext().removeList(obj, lk);
removed = true;
} else if (token.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
String clearText = token.substring(7);
CDOMReference<Ability> ref = TokenUtilities.getTypeOrPrimitive(rm, clearText);
if (ref == null) {
return ParseResult.INTERNAL_ERROR;
}
AssociatedPrereqObject assoc = context.getListContext().removeFromList(getTokenName(), obj, abilList, ref);
assoc.setAssociation(AssociationKey.NATURE, nature);
assoc.setAssociation(AssociationKey.CATEGORY, acRef);
removed = true;
} else if (Constants.LST_PERCENT_LIST.equals(token)) {
prereqsAllowed = false;
AbilitySelector as = new AbilitySelector(getTokenName(), acRef, nature);
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, as);
} else {
CDOMReference<Ability> ability = TokenUtilities.getTypeOrPrimitive(rm, token);
if (ability == null) {
return ParseResult.INTERNAL_ERROR;
}
ability.setRequiresTarget(true);
boolean loadList = true;
List<String> choices = null;
if (token.indexOf('(') != -1) {
choices = new ArrayList<>();
AbilityUtilities.getUndecoratedName(token, choices);
if (choices.size() == 1) {
if (Constants.LST_PERCENT_LIST.equals(choices.get(0)) && (ability instanceof CDOMSingleRef)) {
CDOMSingleRef<Ability> ref = (CDOMSingleRef<Ability>) ability;
AbilityTargetSelector ats = new AbilityTargetSelector(getTokenName(), acRef, ref, nature);
context.getObjectContext().addToList(obj, ListKey.GA_CAKEYS, lk);
context.getObjectContext().addToList(obj, lk, ats);
edgeList.add(ats);
loadList = false;
}
}
}
if (loadList) {
AssociatedPrereqObject assoc = context.getListContext().addToList(getTokenName(), obj, abilList, ability);
assoc.setAssociation(AssociationKey.NATURE, nature);
assoc.setAssociation(AssociationKey.CATEGORY, acRef);
if (choices != null) {
assoc.setAssociation(AssociationKey.ASSOC_CHOICES, choices);
}
edgeList.add(assoc);
}
}
if (!tok.hasMoreTokens()) {
// No prereqs, so we're done
return ParseResult.SUCCESS;
}
first = false;
token = tok.nextToken();
if (looksLikeAPrerequisite(token)) {
break;
}
}
if (removed || !prereqsAllowed) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR, .CLEAR., or %LIST in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (PrereqObject edge : edgeList) {
edge.addPrerequisite(prereq);
}
if (!tok.hasMoreTokens()) {
break;
}
token = tok.nextToken();
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class AddLst 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);
}
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
if (Constants.LST_DOT_CLEAR.equals(value)) {
if (obj instanceof PCClassLevel) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A non-level limited .CLEAR was " + "used in a Class Level line in " + obj.getKeyName());
return cpr;
}
} else if (value.startsWith(".CLEAR.LEVEL")) {
if (!(obj instanceof PCClassLevel)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was not used in a Class Level line in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName());
return cpr;
}
String levelString = value.substring(12);
try {
int level = Integer.parseInt(levelString);
if (level != obj.get(IntegerKey.LEVEL)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But was asked to clear a " + "different Class Level ( " + level + " ) than the Class Level Line it appeared on: " + obj.getKeyName());
return cpr;
}
} catch (NumberFormatException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But the level ( " + levelString + " ) was not an integer in: " + obj.getKeyName());
return cpr;
}
} else {
return new ParseResult.Fail(getTokenName() + " requires a SubToken and argument, found: " + value, context);
}
context.getObjectContext().removeList(obj, ListKey.ADD);
return ParseResult.SUCCESS;
}
return context.processSubToken(obj, getTokenName(), value.substring(0, pipeLoc), value.substring(pipeLoc + 1));
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class BonusLst 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.indexOf("PREAPPLY:") != -1) {
return new ParseResult.Fail("Use of PREAPPLY prohibited on a BONUS , " + "please use TEMPBONUS with: " + value);
}
final String v = value.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
BonusObj bon = Bonus.newBonus(context, v);
if (bon == null) {
return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
}
bon.setTokenSource(getTokenName());
context.getObjectContext().addToList(obj, ListKey.BONUS, bon);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.base.Ungranted in project pcgen by PCGen.
the class CcskillLst 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.CCSKILL);
} 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.CCSKILL, 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.CCSKILL, 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.CCSKILL, 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.CCSKILL, ref);
}
}
}
first = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
Aggregations