use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method addSpellInfoToList.
private void addSpellInfoToList(final Spell aSpell, List<PCClass> classes, List<Domain> domains, String spellType) {
Set<String> unfoundItems = new HashSet<>();
final HashMapToList<CDOMList<Spell>, Integer> levelInfo = character.getSpellLevelInfo(aSpell);
if ((levelInfo == null) || (levelInfo.isEmpty())) {
return;
}
for (CDOMList<Spell> spellList : levelInfo.getKeySet()) {
if (spellList instanceof ClassSpellList) {
String key = spellList.getKeyName();
final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, key);
if (aClass != null) {
if (!("".equals(spellType)) && (!spellType.contains(aClass.getSpellType()))) {
continue;
}
if (!classes.contains(aClass)) {
classes.add(aClass);
}
} else {
key = 'C' + key;
if (!unfoundItems.contains(key)) {
unfoundItems.add(key);
Logging.errorPrint("Class " + key.substring(1) + " not found. Was used in spell " + aSpell);
}
}
} else if (spellList instanceof DomainSpellList) {
if (!("".equals(spellType)) && (!spellType.contains("Divine"))) {
continue;
}
String key = spellList.getKeyName();
final Domain aDomain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, key);
if (aDomain != null) {
if (!domains.contains(aDomain)) {
domains.add(aDomain);
}
} else {
key = 'D' + key;
if (!unfoundItems.contains(key)) {
unfoundItems.add(key);
Logging.errorPrint("Domain " + key.substring(1) + " not found. Was used in spell " + aSpell);
}
}
} else {
Logging.errorPrint("Unknown spell source: " + spellList);
}
}
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class ClassDataHandler method getSpellsIn.
/**
* Returns a List of Spell with following criteria:
*
* @param level (optional, ignored if < 0),
* @param spellLists the lists of spells
* @param pc TODO
* @return a List of Spell
*/
public static List<Spell> getSpellsIn(final int level, List<? extends CDOMList<Spell>> spellLists) {
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
ArrayList<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
for (CDOMReference ref : masterLists.getActiveLists()) {
for (CDOMList<Spell> list : spellLists) {
if (ref.contains(list)) {
useLists.add(ref);
break;
}
}
}
boolean allLevels = level == -1;
Set<Spell> spellList = new HashSet<>();
for (CDOMReference<CDOMList<Spell>> ref : useLists) {
for (Spell spell : masterLists.getObjects(ref)) {
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
for (AssociatedPrereqObject apo : assoc) {
// TODO Not sure if effect of null for PC
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), (PlayerCharacter) null, null)) {
int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
if (allLevels || level == lvl) {
spellList.add(spell);
break;
}
}
}
}
}
return new ArrayList<>(spellList);
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class AbstractListContext method commit.
void commit() {
ListCommitStrategy commit = getCommitStrategy();
for (CDOMReference<? extends CDOMList<?>> list : edits.positiveMasterMap.getKeySet()) {
//Note: Intentional Generics Violation due to Sun Compiler
commitDirect((CDOMReference) list);
}
for (CDOMReference<? extends CDOMList<?>> list : edits.negativeMasterMap.getKeySet()) {
//Note: Intentional Generics Violation due to Sun Compiler
removeDirect((CDOMReference) list);
}
for (URI uri : edits.globalClearSet.getKeySet()) {
for (CDOMObject owner : edits.globalClearSet.getSecondaryKeySet(uri)) {
for (String tokenName : edits.globalClearSet.getTertiaryKeySet(uri, owner)) {
for (CDOMReference<? extends CDOMList<?>> list : edits.globalClearSet.getListFor(uri, owner, tokenName)) {
commit.removeAllFromList(tokenName, owner, list);
}
}
}
}
for (URI uri : edits.negativeMap.getKeySet()) {
for (CDOMObject owner : edits.negativeMap.getSecondaryKeySet(uri)) {
CDOMObject neg = edits.negativeMap.get(uri, owner);
Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
//Note: Intentional Generics Violation due to Sun Compiler
remove(owner, neg, (CDOMReference) list);
}
}
}
for (URI uri : edits.positiveMap.getKeySet()) {
for (CDOMObject owner : edits.positiveMap.getSecondaryKeySet(uri)) {
CDOMObject neg = edits.positiveMap.get(uri, owner);
Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
//Note: Intentional Generics Violation due to Sun Compiler
add(owner, neg, (CDOMReference) list);
}
}
}
for (String token : edits.masterAllClear.getKeySet()) {
for (OwnerURI ou : edits.masterAllClear.getListFor(token)) {
commit.clearAllMasterLists(token, ou.owner);
}
}
rollback();
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class SpelllevelLst method subParse.
private <CL extends Loadable & CDOMList<Spell>> boolean subParse(LoadContext context, CDOMObject obj, Class<CL> tagType, String tokString, String spellString, List<Prerequisite> prereqs) {
int equalLoc = tokString.indexOf(Constants.EQUALS);
if (equalLoc == -1) {
Logging.errorPrint("Expected an = in SPELLLEVEL " + "definition: " + tokString);
return false;
}
String casterString = tokString.substring(0, equalLoc);
String spellLevel = tokString.substring(equalLoc + 1);
Integer splLevel;
try {
splLevel = Integer.decode(spellLevel);
} catch (NumberFormatException nfe) {
Logging.errorPrint("Expected a number for SPELLLEVEL, found: " + spellLevel);
return false;
}
if (isEmpty(casterString) || hasIllegalSeparator(',', casterString)) {
return false;
}
StringTokenizer clTok = new StringTokenizer(casterString, Constants.COMMA);
List<CDOMReference<? extends CDOMList<Spell>>> slList = new ArrayList<>();
while (clTok.hasMoreTokens()) {
String classString = clTok.nextToken();
CDOMReference<CL> ref;
if (classString.startsWith("SPELLCASTER.")) {
/*
* This is actually a TYPE
*/
ref = context.getReferenceContext().getCDOMTypeReference(tagType, classString.substring(12));
} else {
ref = context.getReferenceContext().getCDOMReference(tagType, classString);
}
slList.add(ref);
}
if (hasIllegalSeparator(',', spellString)) {
return false;
}
StringTokenizer spTok = new StringTokenizer(spellString, ",");
while (spTok.hasMoreTokens()) {
String spellName = spTok.nextToken();
CDOMReference<Spell> sp = context.getReferenceContext().getCDOMReference(Spell.class, spellName);
for (CDOMReference<? extends CDOMList<Spell>> sl : slList) {
AssociatedPrereqObject tpr = context.getListContext().addToList(getTokenName(), obj, sl, sp);
tpr.setAssociation(AssociationKey.SPELL_LEVEL, splLevel);
tpr.addAllPrerequisites(prereqs);
}
}
return true;
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class SpellknownLst method subParse.
/**
* Parse the tag contents after the SPELLKNOWN:CLASS| section.
*
* @param context the context under which the tag is being parsed.
* @param obj the obj The object owning the tag.
* @param tagType the type of object the tag creates
* @param tokString the tok string The string defining the caster type/class and spell level.
* @param spellString the spell string The string containing the spell name(s)
* @param prereqs the prereqs The prerequisites to be applied.
*
* @return true, if successful
*/
private <CL extends Loadable & CDOMList<Spell>> boolean subParse(LoadContext context, CDOMObject obj, Class<CL> tagType, String tokString, String spellString, List<Prerequisite> prereqs) {
int equalLoc = tokString.indexOf(Constants.EQUALS);
if (equalLoc == -1) {
Logging.errorPrint("Expected an = in SPELLKNOWN " + "definition: " + tokString);
return false;
}
String casterString = tokString.substring(0, equalLoc);
String spellLevel = tokString.substring(equalLoc + 1);
Integer splLevel;
try {
splLevel = Integer.decode(spellLevel);
} catch (NumberFormatException nfe) {
Logging.errorPrint("Expected a number for SPELLKNOWN, found: " + spellLevel);
return false;
}
if (isEmpty(casterString) || hasIllegalSeparator(',', casterString)) {
return false;
}
StringTokenizer clTok = new StringTokenizer(casterString, Constants.COMMA);
List<CDOMReference<? extends CDOMList<Spell>>> slList = new ArrayList<>();
while (clTok.hasMoreTokens()) {
String classString = clTok.nextToken();
CDOMReference<CL> ref;
if (classString.startsWith("SPELLCASTER.")) {
/*
* This is actually a TYPE
*/
ref = context.getReferenceContext().getCDOMTypeReference(tagType, classString.substring(12));
} else {
ref = context.getReferenceContext().getCDOMReference(tagType, classString);
}
slList.add(ref);
}
if (hasIllegalSeparator(',', spellString)) {
return false;
}
StringTokenizer spTok = new StringTokenizer(spellString, ",");
while (spTok.hasMoreTokens()) {
String spellName = spTok.nextToken();
CDOMReference<Spell> sp = context.getReferenceContext().getCDOMReference(Spell.class, spellName);
for (CDOMReference<? extends CDOMList<Spell>> sl : slList) {
AssociatedPrereqObject tpr = context.getListContext().addToList(getTokenName(), obj, sl, sp);
tpr.setAssociation(AssociationKey.SPELL_LEVEL, splLevel);
tpr.setAssociation(AssociationKey.KNOWN, Boolean.TRUE);
tpr.addAllPrerequisites(prereqs);
}
}
return true;
}
Aggregations