Search in sources :

Example 16 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class SkilllistToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    TransitionChoice<ClassSkillList> grantChanges = context.getObjectContext().getObject(pcc, ObjectKey.SKILLLIST_CHOICE);
    if (grantChanges == null) {
        // Zero indicates no Token
        return null;
    }
    StringBuilder sb = new StringBuilder();
    Formula count = grantChanges.getCount();
    if (count == null) {
        context.addWriteMessage("Unable to find " + getTokenName() + " Count");
        return null;
    }
    sb.append(count);
    sb.append(Constants.PIPE);
    sb.append(grantChanges.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
    return new String[] { sb.toString() };
}
Also used : Formula(pcgen.base.formula.Formula) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 17 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class SkilllistToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    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() || 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<ClassSkillList>> refs = new ArrayList<>();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        CDOMReference<ClassSkillList> ref;
        if (Constants.LST_ALL.equals(token)) {
            ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
        } else {
            ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
        }
        refs.add(ref);
    }
    ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
    }
    ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose class-skills this class will inherit");
    TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
}
Also used : ConcreteTransitionChoice(pcgen.cdom.base.ConcreteTransitionChoice) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 18 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class SkillListTokenTest method testUnparseNullInList.

@Test
public void testUnparseNullInList() throws PersistenceLayerException {
    ClassSkillList wp1 = construct(primaryContext, "TestWP1");
    ReferenceChoiceSet<ClassSkillList> rcs = buildRCS(CDOMDirectSingleRef.getRef(wp1), null);
    PersistentTransitionChoice<ClassSkillList> tc = buildTC(rcs);
    primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc);
    try {
        getToken().unparse(primaryContext, primaryProf);
        fail();
    } catch (NullPointerException e) {
    // Yep!
    }
}
Also used : ClassSkillList(pcgen.cdom.list.ClassSkillList) Test(org.junit.Test)

Example 19 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class SkillListTokenTest method testUnparseBadCount.

@Test
public void testUnparseBadCount() throws PersistenceLayerException {
    ClassSkillList wp1 = construct(primaryContext, "TestWP1");
    ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(Collections.singletonList(CDOMDirectSingleRef.getRef(wp1)));
    ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(token.getTokenName(), rcs);
    cs.setTitle("Pick a ClassSkillList");
    PersistentTransitionChoice<ClassSkillList> tc1 = new ConcretePersistentTransitionChoice<>(cs, null);
    primaryProf.put(ObjectKey.SKILLLIST_CHOICE, tc1);
    assertBadUnparse();
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ClassSkillList(pcgen.cdom.list.ClassSkillList) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Test(org.junit.Test)

Example 20 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class MonCSkillTokenTest method setUp.

@Override
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    ClassSkillList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSkillList.class, "Scary Monster");
    a.addType(Type.MONSTER);
    ClassSkillList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSkillList.class, "Scary Monster");
    b.addType(Type.MONSTER);
}
Also used : ClassSkillList(pcgen.cdom.list.ClassSkillList)

Aggregations

ClassSkillList (pcgen.cdom.list.ClassSkillList)25 CDOMReference (pcgen.cdom.base.CDOMReference)8 PCClass (pcgen.core.PCClass)8 Skill (pcgen.core.Skill)8 Test (org.junit.Test)6 CharID (pcgen.cdom.enumeration.CharID)6 ArrayList (java.util.ArrayList)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 SkillCost (pcgen.cdom.enumeration.SkillCost)3 SubClass (pcgen.core.SubClass)3 Formula (pcgen.base.formula.Formula)2 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)2 Race (pcgen.core.Race)2 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)2 CDOMObject (pcgen.cdom.base.CDOMObject)1 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)1 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)1