Search in sources :

Example 11 with ClassSpellList

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();
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ClassSpellList(pcgen.cdom.list.ClassSpellList) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Example 12 with ClassSpellList

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");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Example 13 with ClassSpellList

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!
    }
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMListObject(pcgen.cdom.base.CDOMListObject) Test(org.junit.Test)

Example 14 with ClassSpellList

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;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ClassSpellList(pcgen.cdom.list.ClassSpellList) StringTokenizer(java.util.StringTokenizer) Prerequisite(pcgen.core.prereq.Prerequisite) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 15 with ClassSpellList

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");
}
Also used : ClassSpellList(pcgen.cdom.list.ClassSpellList) Test(org.junit.Test)

Aggregations

ClassSpellList (pcgen.cdom.list.ClassSpellList)21 Test (org.junit.Test)7 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)7 Spell (pcgen.core.spell.Spell)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)6 PCClass (pcgen.core.PCClass)6 CDOMListObject (pcgen.cdom.base.CDOMListObject)4 Domain (pcgen.core.Domain)4 ArrayList (java.util.ArrayList)3 CDOMList (pcgen.cdom.base.CDOMList)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 MasterListInterface (pcgen.cdom.base.MasterListInterface)3 AvailableSpell (pcgen.cdom.helper.AvailableSpell)3 StringTokenizer (java.util.StringTokenizer)2 DataSetID (pcgen.cdom.enumeration.DataSetID)2 CharacterSpell (pcgen.core.character.CharacterSpell)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 StringWriter (java.io.StringWriter)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1