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;
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations