use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class SpellLevelLstTest method testRoundRobinSpellCaster.
@Test
public void testRoundRobinSpellCaster() throws PersistenceLayerException {
ClassSpellList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
a.addType(Type.getConstant("Arcane"));
ClassSpellList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
b.addType(Type.getConstant("Arcane"));
primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
runRoundRobin("CLASS|SPELLCASTER.Arcane=2|Fireball|PRECLASS:1,Fighter=2");
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class SpellknownLstTest method testRoundRobinSpellCaster.
@Test
public void testRoundRobinSpellCaster() throws PersistenceLayerException {
primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Fireball");
ClassSpellList a = primaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
a.addType(Type.getConstant("Arcane"));
ClassSpellList b = secondaryContext.getReferenceContext().constructCDOMObject(ClassSpellList.class, "Wizard");
b.addType(Type.getConstant("Arcane"));
runRoundRobin("CLASS|SPELLCASTER.Arcane=2|Fireball|PRECLASS:1,Fighter=2");
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class AvailableSpellFacet method getSpellLevelInfo.
/**
* Returns a non-null HashMapToList indicating the spell levels and sources
* of those spell levels available to a Player Character for a given Spell.
*
* This may return multiple spell levels because it is possible for a spell
* to be accessible to a Player Character at multiple levels since it may be
* available from multiple sources. This also returns the spell lists
* associated with the given level, since it is possible for a multi-class
* character to have access to the same spell at different levels. By
* returning the source as well as the spell levels, such scenarios can be
* appropriately distinguished.
*
* This method is value-semantic in that ownership of the returned
* HashMapToList is transferred to the class calling this method.
* Modification of the returned HashMapToList will not modify this
* AvailableSpellFacet and modification of this AvailableSpellFacet will not
* modify the returned HashMapToList. Modifications to the returned
* HashMapToList will also not modify any future or previous objects
* returned by this (or other) methods on AvailableSpellFacet. If you wish
* to modify the information stored in this AvailableSpellFacet, you must
* use the add*() and remove*() methods of AvailableSpellFacet.
*
* @param id
* The CharID identifying the Player Character for which the
* spell levels should be returned
* @param sp
* The Spell for which the spell levels should be returned
* @return A non-null HashMapToList indicating the spell levels and sources
* of those spell levels available to a Player Character for a given
* Spell.
*/
public HashMapToList<CDOMList<Spell>, Integer> getSpellLevelInfo(CharID id, Spell sp) {
HashMapToList<CDOMList<Spell>, Integer> levelInfo = new HashMapToList<>();
Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap = (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
if (listMap == null) {
return levelInfo;
}
for (Entry<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> me : listMap.entrySet()) {
CDOMList<Spell> list = me.getKey();
//Check to ensure we don't use SPELLS:
if (!(list instanceof ClassSpellList) && !(list instanceof DomainSpellList)) {
continue;
}
Map<Integer, Map<Spell, Set<Object>>> levelMap = me.getValue();
for (Map.Entry<Integer, Map<Spell, Set<Object>>> lme : levelMap.entrySet()) {
Integer level = lme.getKey();
Map<Spell, Set<Object>> spellMap = lme.getValue();
if (spellMap.containsKey(sp)) {
levelInfo.addToListFor(list, level);
} else {
for (Spell spell : spellMap.keySet()) {
if (spell.getKeyName().equals(sp.getKeyName())) {
if (Logging.isLoggable(Logging.INFO)) {
Logging.log(Logging.INFO, "Found alternate spell of same key: " + spell + " from " + spell.getSource() + " rather than " + sp.getSource());
}
levelInfo.addToListFor(list, level);
}
}
}
}
}
return levelInfo;
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class PCGVer2Parser method parseSpellListLines.
/*
* ###############################################################
* Spell List Information methods
* ###############################################################
*/
/*
* #Spell List Information
* SPELLLIST:sourceclassname|spelllistentry|spelllistentry
*/
private void parseSpellListLines(final String line) {
final String subLine = line.substring(IOConstants.TAG_SPELLLIST.length() + 1);
final StringTokenizer stok = new StringTokenizer(subLine, IOConstants.TAG_SEPARATOR, false);
final String classKey = stok.nextToken();
final PCClass aClass = thePC.getClassKeyed(classKey);
AbstractReferenceContext refContext = Globals.getContext().getReferenceContext();
while ((aClass != null) && stok.hasMoreTokens()) {
final String tok = stok.nextToken();
if (tok.startsWith("CLASS.")) {
ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok.substring(6));
thePC.addClassSpellList(csl, aClass);
} else if (tok.startsWith("DOMAIN.")) {
DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok.substring(7));
thePC.addClassSpellList(dsl, aClass);
} else {
/*
* This is 5.14-ish, but have to try anyway:
*/
ClassSpellList csl = refContext.silentlyGetConstructedCDOMObject(ClassSpellList.class, tok);
if (csl == null) {
DomainSpellList dsl = refContext.silentlyGetConstructedCDOMObject(DomainSpellList.class, tok);
if (dsl != null) {
thePC.addClassSpellList(dsl, aClass);
}
} else {
thePC.addClassSpellList(csl, aClass);
}
}
}
}
use of pcgen.cdom.list.ClassSpellList in project pcgen by PCGen.
the class MasterAvailableSpellFacet method initialize.
/**
* Initializes the global lists of ClassSkillLists. This method only needs
* to be called once for each set of sources that are loaded.
*/
@Override
public synchronized void initialize(LoadContext lc) {
DataSetID dsID = lc.getDataSetID();
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
List<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
for (CDOMReference ref : masterLists.getActiveLists()) {
Collection<CDOMList<Spell>> lists = ref.getContainedObjects();
for (CDOMList<Spell> list : lists) {
if ((list instanceof ClassSpellList) || (list instanceof DomainSpellList)) {
useLists.add(ref);
break;
}
}
}
for (CDOMReference<CDOMList<Spell>> ref : useLists) {
for (Spell spell : masterLists.getObjects(ref)) {
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
for (AssociatedPrereqObject apo : assoc) {
int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
for (CDOMList<Spell> list : ref.getContainedObjects()) {
AvailableSpell as = new AvailableSpell(list, spell, lvl);
if (apo.hasPrerequisites()) {
as.addAllPrerequisites(apo.getPrerequisiteList());
}
add(dsID, as);
}
}
}
}
}
Aggregations