Search in sources :

Example 21 with ClassSkillList

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

the class MonCCSkillTokenTest 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)

Example 22 with ClassSkillList

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

the class RaceMonCCSkillTest method testDirect.

@Test
public void testDirect() throws PersistenceLayerException {
    Race source = create(Race.class, "Source");
    ParseResult result = token.parseToken(context, source, "MySkill");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    new ExclusiveToken().parseToken(context, sk, "Yes");
    finishLoad();
    assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(sk, dragon));
    raceFacet.directSet(id, source, getAssoc());
    ClassSkillList dragonCSL = context.getReferenceContext().silentlyGetConstructedCDOMObject(ClassSkillList.class, "Dragon");
    assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(sk, dragon));
    pc.incrementClassLevel(1, dragon);
    assertEquals(SkillCost.CROSS_CLASS, pc.getSkillCostForClass(sk, dragon));
    assertTrue(lscFacet.contains(id, dragonCSL, SkillCost.CROSS_CLASS, sk));
    raceFacet.remove(id);
    assertFalse(lscFacet.contains(id, dragonCSL, SkillCost.CROSS_CLASS, sk));
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) Race(pcgen.core.Race) ExclusiveToken(plugin.lsttokens.skill.ExclusiveToken) ClassSkillList(pcgen.cdom.list.ClassSkillList) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 23 with ClassSkillList

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

the class ClassesToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Skill skill, String value) {
    StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
    boolean added = false;
    List<CDOMReference<ClassSkillList>> allow = new ArrayList<>();
    while (pipeTok.hasMoreTokens()) {
        String className = pipeTok.nextToken();
        if (Constants.LST_ALL.equals(className)) {
            if (added) {
                return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ALL after a specific reference: " + value, context);
            }
            break;
        }
        if (className.startsWith("!")) {
            return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ! without (or before) ALL: " + value, context);
        }
        allow.add(context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, className));
        added = true;
    }
    if (pipeTok.hasMoreTokens()) {
        // allow is not used (empty or an error)
        FilteredReference<ClassSkillList> filtered = new FilteredReference<>(SKILLLIST_CLASS, context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS));
        while (pipeTok.hasMoreTokens()) {
            String className = pipeTok.nextToken();
            if (className.startsWith("!")) {
                String clString = className.substring(1);
                if (Constants.LST_ALL.equals(clString) || Constants.LST_ANY.equals(clString)) {
                    return new ParseResult.Fail("Invalid " + getTokenName() + " cannot use !ALL", context);
                }
                CDOMSingleRef<ClassSkillList> ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, clString);
                filtered.addProhibitedItem(ref);
            } else {
                return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ALL and a specific reference: " + value, context);
            }
        }
        context.getListContext().addToMasterList(getTokenName(), skill, filtered, skill);
    } else if (allow.isEmpty()) {
        // unqualified ALL
        context.getListContext().addToMasterList(getTokenName(), skill, context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS), skill);
    } else {
        // use allow
        for (CDOMReference<ClassSkillList> ref : allow) {
            context.getListContext().addToMasterList(getTokenName(), skill, ref, skill);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) FilteredReference(pcgen.cdom.reference.FilteredReference) CDOMReference(pcgen.cdom.base.CDOMReference) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 24 with ClassSkillList

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

the class CskillToken method process.

@Override
public boolean process(LoadContext context, PCClass obj) {
    List<CDOMReference<Skill>> list = obj.getListFor(ListKey.CLASS_SKILL);
    if (list != null) {
        ClassSkillList csl = obj.get(ObjectKey.CLASS_SKILLLIST);
        CDOMDirectSingleRef<ClassSkillList> listref = new CDOMDirectSingleRef<>(csl);
        for (CDOMReference<Skill> ref : list) {
            for (Skill sk : ref.getContainedObjects()) {
                context.getListContext().addToMasterList(getTokenName(), obj, listref, sk);
                context.commit();
            }
        }
    }
    return true;
}
Also used : Skill(pcgen.core.Skill) CDOMDirectSingleRef(pcgen.cdom.reference.CDOMDirectSingleRef) CDOMReference(pcgen.cdom.base.CDOMReference) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 25 with ClassSkillList

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

the class ListToSkillCostFacet method dataAdded.

@Override
public void dataAdded(SubScopeFacetChangeEvent<ClassSkillList, SkillCost, Skill> dfce) {
    CharID id = dfce.getCharID();
    ClassSkillList skilllist = dfce.getScope1();
    SkillCost cost = dfce.getScope2();
    Skill sk = dfce.getCDOMObject();
    for (PCClass cl : skillListFacet.getScopes(id)) {
        if (skillListFacet.contains(id, cl, skilllist)) {
            add(id, cl, cost, sk, cl);
        }
    }
}
Also used : Skill(pcgen.core.Skill) SkillCost(pcgen.cdom.enumeration.SkillCost) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) 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