Search in sources :

Example 91 with CDOMReference

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

the class PlayerCharacter method processAbilityListsOnAdd.

private void processAbilityListsOnAdd(CDOMObject cdo, CDOMReference<? extends CDOMList<?>> ref) {
    for (CDOMList<?> list : ref.getContainedObjects()) {
        if (list instanceof AbilityList) {
            CDOMReference r = ref;
            processAbilityList(cdo, r);
            // Only do once
            break;
        }
    }
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 92 with CDOMReference

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

the class AbstractSpellListToken method getMap.

/**
	 * Gets the map.
	 *
	 * @param context the context
	 * @param obj the obj
	 * @param changedLists the changed lists
	 * @param knownSpells Should this scan be for known spells
	 * @return the map
	 */
protected TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> getMap(LoadContext context, CDOMObject obj, Collection<CDOMReference<? extends CDOMList<?>>> changedLists, boolean knownSpells) {
    TripleKeyMapToList<String, Integer, CDOMReference<? extends CDOMList<?>>, CDOMReference<Spell>> map = new TripleKeyMapToList<>();
    for (CDOMReference listRef : changedLists) {
        AssociatedChanges<CDOMReference<Spell>> changes = context.getListContext().getChangesInList(getTokenName(), obj, listRef);
        Collection<?> removedItems = changes.getRemoved();
        if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
            context.addWriteMessage(getTokenName() + " does not support .CLEAR");
            return null;
        }
        MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
        if (mtl == null || mtl.isEmpty()) {
            // TODO Error message - unexpected?
            continue;
        }
        for (CDOMReference<Spell> added : mtl.getKeySet()) {
            for (AssociatedPrereqObject assoc : mtl.getListFor(added)) {
                Integer lvl = assoc.getAssociation(AssociationKey.SPELL_LEVEL);
                String prereqString = getPrerequisiteString(context, assoc.getPrerequisiteList());
                Boolean known = assoc.getAssociation(AssociationKey.KNOWN);
                boolean isKnown = known != null && known.booleanValue();
                if (knownSpells == isKnown) {
                    map.addToListFor(prereqString, lvl, listRef, added);
                }
            }
        }
    }
    return map;
}
Also used : Spell(pcgen.core.spell.Spell) TripleKeyMapToList(pcgen.base.util.TripleKeyMapToList) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 93 with CDOMReference

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

the class CskillToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass 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.CLASS_SKILL);
        } 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.CLASS_SKILL, 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.CLASS_SKILL, 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.CLASS_SKILL, 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.CLASS_SKILL, 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)

Example 94 with CDOMReference

use of pcgen.cdom.base.CDOMReference 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 95 with CDOMReference

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

the class LangbonusToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass cl, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.COMMA);
    boolean foundAny = false;
    boolean foundOther = false;
    boolean firstToken = true;
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokText)) {
            if (!firstToken) {
                return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
            }
            context.getListContext().removeAllFromList(getTokenName(), cl, Language.STARTING_LIST);
        } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            CDOMReference<Language> lang;
            String clearText = tokText.substring(7);
            if (Constants.LST_ALL.equals(clearText)) {
                lang = context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS);
            } else {
                lang = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, clearText);
            }
            if (lang == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid .CLEAR. reference: " + clearText, context);
            }
            context.getListContext().removeFromList(getTokenName(), cl, Language.STARTING_LIST, lang);
        } else {
            /*
				 * Note this is done one-by-one, because .CLEAR. token type
				 * needs to be able to perform the unlink. That could be
				 * changed, but the increase in complexity isn't worth it.
				 * (Changing it to a grouping object that didn't place links in
				 * the graph would also make it harder to trace the source of
				 * class skills, etc.)
				 */
            CDOMReference<Language> lang;
            if (Constants.LST_ALL.equals(tokText)) {
                foundAny = true;
                lang = context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS);
            } else {
                foundOther = true;
                lang = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, tokText);
            }
            if (lang == null) {
                return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + tokText, context);
            }
            context.getListContext().addToList(getTokenName(), cl, Language.STARTING_LIST, lang);
        }
        firstToken = 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