use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class SpellListTokenTest method testUnparseBadCount.
@Test
public void testUnparseBadCount() throws PersistenceLayerException {
ClassSpellList wp1 = construct(primaryContext, "TestWP1");
ReferenceChoiceSet<ClassSpellList> rcs = new ReferenceChoiceSet<>(Collections.singletonList(CDOMDirectSingleRef.getRef(wp1)));
ChoiceSet<ClassSpellList> cs = new ChoiceSet<>(token.getTokenName(), rcs);
cs.setTitle("Pick a ClassSpellList");
PersistentTransitionChoice<CDOMListObject<Spell>> tc1 = new ConcretePersistentTransitionChoice<>(cs, null);
primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc1);
assertBadUnparse();
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class SpellListTokenTest method testUnparseSingle.
@Test
public void testUnparseSingle() throws PersistenceLayerException {
ClassSpellList wp1 = construct(primaryContext, "TestWP1");
PersistentTransitionChoice<CDOMListObject<Spell>> tc = buildChoice(CDOMDirectSingleRef.getRef(wp1));
primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, "1|TestWP1");
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class SpellListTokenTest method testUnparseNullInList.
@Test
public void testUnparseNullInList() throws PersistenceLayerException {
ClassSpellList wp1 = construct(primaryContext, "TestWP1");
ReferenceChoiceSet<ClassSpellList> rcs = buildRCS(CDOMDirectSingleRef.getRef(wp1), null);
PersistentTransitionChoice<CDOMListObject<Spell>> tc = buildTC(rcs);
primaryProf.put(ObjectKey.SPELLLIST_CHOICE, tc);
try {
getToken().unparse(primaryContext, primaryProf);
fail();
} catch (NullPointerException e) {
// Yep!
}
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class ClassesToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Spell spell, String value) {
// Note: May contain PRExxx
String classKey;
Prerequisite prereq = null;
int openBracketLoc = value.indexOf('[');
if (openBracketLoc == -1) {
classKey = value;
} else {
if (value.lastIndexOf(']') != value.length() - 1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must end with ']' if it contains a PREREQ tag", context);
}
if (value.lastIndexOf('|') > openBracketLoc) {
return new ParseResult.Fail("Invalid " + getTokenName() + ": PRExxx must be at the END of the Token. Token was " + value, context);
}
classKey = value.substring(0, openBracketLoc);
String prereqString = value.substring(openBracketLoc + 1, value.length() - 1);
if (prereqString.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " cannot have empty prerequisite : " + value, context);
}
prereq = getPrerequisite(prereqString);
if (prereq == null) {
return new ParseResult.Fail(getTokenName() + " had invalid prerequisite : " + prereqString, context);
}
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer pipeTok = new StringTokenizer(classKey, Constants.PIPE);
while (pipeTok.hasMoreTokens()) {
// could be name=x or name,name=x
String tokString = pipeTok.nextToken();
int startPos = tokString.startsWith("TYPE=") ? "TYPE=".length() : 0;
int equalLoc = tokString.indexOf(Constants.EQUALS, startPos);
if (equalLoc == -1) {
return new ParseResult.Fail("Malformed " + getTokenName() + " Token (expecting an =): " + tokString, context);
}
if (equalLoc != tokString.lastIndexOf(Constants.EQUALS)) {
return new ParseResult.Fail("Malformed " + getTokenName() + " Token (more than one =): " + tokString, context);
}
String nameList = tokString.substring(0, equalLoc);
String levelString = tokString.substring(equalLoc + 1);
Integer level;
try {
level = Integer.valueOf(levelString);
if (level.intValue() < -1) {
return new ParseResult.Fail(getTokenName() + " may not use a negative level: " + value, context);
} else if (level.intValue() == -1) {
if (prereq != null) {
return new ParseResult.Fail(getTokenName() + " may not use -1 with a PREREQ: " + value, context);
}
// Logging.deprecationPrint(getTokenName()
// + " should not use a negative level: " + value);
}
} catch (NumberFormatException nfe) {
return new ParseResult.Fail("Malformed Level in " + getTokenName() + " (expected an Integer): " + levelString, context);
}
ParseResult pr = checkForIllegalSeparator(',', nameList);
if (!pr.passed()) {
return pr;
}
StringTokenizer commaTok = new StringTokenizer(nameList, Constants.COMMA);
while (commaTok.hasMoreTokens()) {
CDOMReference<ClassSpellList> ref;
String token = commaTok.nextToken();
if (Constants.LST_ALL.equals(token)) {
foundAny = true;
ref = context.getReferenceContext().getCDOMAllReference(SPELLLIST_CLASS);
} else {
foundOther = true;
ref = TokenUtilities.getTypeOrPrimitive(context, SPELLLIST_CLASS, token);
if (ref == null) {
return new ParseResult.Fail(" error was in " + getTokenName(), context);
}
}
if (level == -1) {
//No need to check for prereq here - done above
context.getListContext().removeFromMasterList(getTokenName(), spell, ref, spell);
} else {
AssociatedPrereqObject edge = context.getListContext().addToMasterList(getTokenName(), spell, ref, spell);
edge.setAssociation(AssociationKey.SPELL_LEVEL, level);
if (prereq != null) {
edge.addPrerequisite(prereq);
}
context.getObjectContext().addToList(spell, ListKey.SPELL_CLASSLEVEL, token + ' ' + level);
}
}
}
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.list.ClassSpellList in project pcgen by PCGen.
the class SpellLevelLstTest method testRoundRobinSpellCaster.
@Test
public void testRoundRobinSpellCaster() throws PersistenceLayerException {
ClassSpellList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
a.addType(Type.getConstant("Arcane"));
ClassSpellList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
b.addType(Type.getConstant("Arcane"));
primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
runRoundRobin("CLASS|SPELLCASTER.Arcane=2|Fireball|PRECLASS:1,Fighter=2");
}
Aggregations