Search in sources :

Example 21 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ClassSkillsLevelTokenTest method testUnparseExclusive.

@Test
public void testUnparseExclusive() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("EXCLUSIVE", Skill.class, getAllRef(), ObjectKey.EXCLUSIVE, Boolean.TRUE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "EXCLUSIVE");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 22 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ClassSkillsLevelTokenTest method testUnparseUntrained.

@Test
public void testUnparseUntrained() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.TRUE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "UNTRAINED");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 23 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ClassSkillsTokenTest method testUnparseUntrained.

@Test
public void testUnparseUntrained() throws PersistenceLayerException {
    List<CDOMReference<Skill>> refs = new ArrayList<>();
    ObjectMatchingReference<Skill, Boolean> omr = new ObjectMatchingReference<>("UNTRAINED", Skill.class, getAllRef(), ObjectKey.USE_UNTRAINED, Boolean.TRUE);
    omr.returnIncludesNulls(true);
    refs.add(omr);
    ReferenceChoiceSet<Skill> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<Skill> cs = new ChoiceSet<>(getSubToken().getTokenName(), rcs);
    PersistentTransitionChoice<Skill> tc = new ConcretePersistentTransitionChoice<>(cs, FormulaFactory.ONE);
    primaryProf.addToListFor(ListKey.ADD, tc);
    tc.setChoiceActor(new ClassSkillChoiceActor(fighter, null));
    String[] unparsed = getToken().unparse(primaryContext, primaryProf);
    expectSingle(unparsed, getSubTokenName() + '|' + "UNTRAINED");
}
Also used : ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Skill(pcgen.core.Skill) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) CDOMReference(pcgen.cdom.base.CDOMReference) ObjectMatchingReference(pcgen.cdom.reference.ObjectMatchingReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) Test(org.junit.Test)

Example 24 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class MoncskillToken method unparse.

@Override
public String[] unparse(LoadContext context, Race race) {
    CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
    AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(race, ListKey.NEW_CHOOSE_ACTOR);
    List<String> list = new ArrayList<>();
    Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty()) {
        if (changes.includesGlobalClear()) {
            context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
            return null;
        }
        list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
    }
    Collection<ChooseSelectionActor<?>> listRemoved = listChanges.getRemoved();
    if (listRemoved != null && !listRemoved.isEmpty()) {
        if (listRemoved.contains(this)) {
            list.add(".CLEAR.LIST");
        }
    }
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR);
    }
    MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
    if (map != null && !map.isEmpty()) {
        Set<CDOMReference<Skill>> added = map.getKeySet();
        for (CDOMReference<Skill> ab : added) {
            for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
                if (!SkillCost.CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
                    context.addWriteMessage("Skill Cost must be " + "CLASS for Token " + getTokenName());
                    return null;
                }
            }
        }
        list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
    }
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> csa : listAdded) {
            if (csa.getSource().equals(getTokenName())) {
                try {
                    list.add(csa.getLstFormat());
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    if (list.isEmpty()) {
        // Zero indicates no add or clear
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 25 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class CskillToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel obj, String value) {
    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.LOCALCSKILL);
        } 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.LOCALCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } 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.LOCALCSKILL, 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.LOCALCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } else {
                foundOther = true;
                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.LOCALCSKILL, ref);
            }
        }
        first = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult) CDOMReference(pcgen.cdom.base.CDOMReference)

Aggregations

CDOMReference (pcgen.cdom.base.CDOMReference)125 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)40 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)35 ParseResult (pcgen.rules.persistence.token.ParseResult)30 Skill (pcgen.core.Skill)24 ChoiceSet (pcgen.cdom.base.ChoiceSet)22 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)19 Prerequisite (pcgen.core.prereq.Prerequisite)18 Formula (pcgen.base.formula.Formula)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Spell (pcgen.core.spell.Spell)15 TreeSet (java.util.TreeSet)14 Test (org.junit.Test)14 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 CharID (pcgen.cdom.enumeration.CharID)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)11 ParsingSeparator (pcgen.base.text.ParsingSeparator)10 CDOMList (pcgen.cdom.base.CDOMList)10