use of pcgen.cdom.base.MasterListInterface in project pcgen by PCGen.
the class SpellLevel method isLevel.
/**
* isLevel(int aLevel)
*
* @param aLevel
* level of the spell
* @param aPC
* @return true if the spell is of the given level in any spell list
*/
public static boolean isLevel(Spell sp, int aLevel, PlayerCharacter aPC) {
Integer levelKey = aLevel;
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
for (PCClass pcc : aPC.getClassSet()) {
ClassSpellList csl = pcc.get(ObjectKey.CLASS_SPELLLIST);
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(csl, sp);
if (assoc != null) {
for (AssociatedPrereqObject apo : assoc) {
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
return true;
}
}
}
}
}
for (Domain domain : aPC.getDomainSet()) {
DomainSpellList dsl = domain.get(ObjectKey.DOMAIN_SPELLLIST);
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(dsl, sp);
if (assoc != null) {
for (AssociatedPrereqObject apo : assoc) {
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
return true;
}
}
}
}
}
return false;
}
use of pcgen.cdom.base.MasterListInterface 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.MasterListInterface in project pcgen by PCGen.
the class LoadContextTest method testCloneInMasterListsAssoc.
/**
* Test method for {@link pcgen.rules.context.LoadContext#cloneInMasterLists(pcgen.cdom.base.CDOMObject, java.lang.String)}.
* Verify that associations from other objects to the object being cloned
* are copied over.
*/
public final void testCloneInMasterListsAssoc() {
final LoadContext context = Globals.getContext();
FactKey.getConstant("ClassType", new StringManager());
FactKey.getConstant("SpellType", new StringManager());
Spell testSpell = TestHelper.makeSpell("LoadContextTest");
PCClass wiz = TestHelper.makeClass("Wizard");
CDOMReference<ClassSpellList> ref = TokenUtilities.getTypeOrPrimitive(context, ClassSpellList.class, wiz.getKeyName());
AssociatedPrereqObject edge = context.getListContext().addToMasterList("CLASSES", testSpell, ref, testSpell);
edge.setAssociation(AssociationKey.SPELL_LEVEL, 1);
context.getReferenceContext().buildDerivedObjects();
assertTrue(context.getReferenceContext().resolveReferences(null));
context.commit();
Spell newSpell = context.performCopy(testSpell, "New Spell");
context.commit();
assertEquals("Old spell name incorrect", "LoadContextTest", testSpell.getDisplayName());
assertEquals("New spell name incorrect", "New Spell", newSpell.getDisplayName());
// Check associations
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, testSpell);
assertEquals("Incorrect size of assoc list for orig spell", 1, assoc.size());
AssociatedPrereqObject apo = assoc.iterator().next();
assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
assoc = masterLists.getAssociations(ref, newSpell);
assertEquals("Incorrect size of assoc list for new spell", 1, assoc.size());
apo = assoc.iterator().next();
assertEquals("Incorrect level", 1, apo.getAssociation(AssociationKey.SPELL_LEVEL).intValue());
}
use of pcgen.cdom.base.MasterListInterface in project pcgen by PCGen.
the class AbstractListContext method cloneInMasterLists.
/**
* Create a copy of any associations to the original object and link them
* to the new object. This will scan lists such as ClassSpellLists and
* DomainSpellLists which may link to the original object. For each
* association found, a new association will be created linking to the new object
* and the association will be added to the list.
*
* @param <T> The type of CDOMObject being copied (e.g. Spell, Domain etc)
* @param cdoOld The original object being copied.
* @param cdoNew The new object to be linked in.
*/
@SuppressWarnings("unchecked")
<T extends CDOMObject> void cloneInMasterLists(T cdoOld, T cdoNew) {
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
for (CDOMReference ref : masterLists.getActiveLists()) {
Collection<AssociatedPrereqObject> assocs = masterLists.getAssociations(ref, cdoOld);
if (assocs != null) {
for (AssociatedPrereqObject apo : assocs) {
// Logging.debugPrint("Found assoc from " + ref + " to "
// + apo.getAssociationKeys() + " / "
// + apo.getAssociation(AssociationKey.OWNER));
AssociatedPrereqObject newapo = getCommitStrategy().addToMasterList(apo.getAssociation(AssociationKey.TOKEN), cdoNew, ref, cdoNew);
newapo.addAllPrerequisites(apo.getPrerequisiteList());
for (AssociationKey assocKey : apo.getAssociationKeys()) {
if (assocKey != AssociationKey.TOKEN && assocKey != AssociationKey.OWNER) {
newapo.setAssociation(assocKey, apo.getAssociation(assocKey));
}
}
}
}
}
}
use of pcgen.cdom.base.MasterListInterface 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