use of pcgen.core.spell.Spell 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);
}
}
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellListToAvailableSpellFacet method dataRemoved.
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, CDOMList<Spell>> dfce) {
CharID id = dfce.getCharID();
CDOMList<Spell> list = dfce.getCDOMObject();
Collection<AvailableSpell> spells = masterAvailableSpellFacet.getSet(id.getDatasetID());
for (AvailableSpell as : spells) {
if (as.getSpelllist().equals(list)) {
remove(id, as, this);
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellListToAvailableSpellFacet method dataAdded.
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMList<Spell>> dfce) {
CharID id = dfce.getCharID();
CDOMList<Spell> list = dfce.getCDOMObject();
Collection<AvailableSpell> spells = masterAvailableSpellFacet.getSet(id.getDatasetID());
for (AvailableSpell as : spells) {
if (as.getSpelllist().equals(list)) {
add(id, as, this);
}
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class SpellBuilderFacadeImpl method buildLists.
/**
* Use the parsed rules to build up the lists that will not change,
* such as class/domain list and metamagic feats.
*/
private void buildLists() {
List<PCClass> classes = new ArrayList<>();
List<Domain> domains = new ArrayList<>();
if (classList != null) {
for (String classKey : classList) {
PObject obj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
if (obj == null) {
obj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, classKey);
if (obj != null) {
domains.add((Domain) obj);
}
} else {
classes.add((PCClass) obj);
}
}
} else {
for (Spell spell : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Spell.class)) {
if (isSpellOfSubType(spell)) {
addSpellInfoToList(spell, classes, domains, reqSpellType);
}
}
for (PCClass aClass : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCClass.class)) {
if (!aClass.getSpellType().equals(Constants.NONE)) {
// Only adds if the class can cast
if (character.getSpellSupport(aClass).canCastSpells(character)) {
continue;
}
if (!("".equals(reqSpellType)) && (!reqSpellType.contains(aClass.getSpellType()))) {
continue;
}
if (!classes.contains(aClass)) {
classes.add(aClass);
}
}
}
}
if (spellBooks != null) {
for (int i = classes.size() - 1; i >= 0; --i) {
PCClass obj = classes.get(i);
if (// can't have books
!spellBooks) {
if (obj.getSafe(ObjectKey.SPELLBOOK)) {
classes.remove(i);
}
} else // must have books
{
if (!(obj instanceof PCClass) || !obj.getSafe(ObjectKey.SPELLBOOK)) {
classes.remove(i);
}
}
}
if (spellBooks) {
domains.clear();
}
}
List<InfoFacade> allObjects = new ArrayList<>();
Globals.sortPObjectListByName(classes);
allObjects.addAll(classes);
Globals.sortPObjectListByName(domains);
allObjects.addAll(domains);
availClasses.setContents(allObjects);
// Spell levels
List<Integer> spellLevelValues = new ArrayList<>();
if ((levelList != null) && (!levelList.isEmpty())) {
for (int i = minSpellLevel; i < levelList.size(); ++i) {
spellLevelValues.add(Integer.valueOf(levelList.get(i)));
}
} else {
for (int i = minSpellLevel; i <= maxSpellLevel; i++) {
spellLevelValues.add(i);
}
}
availSpellLevels.setContents(spellLevelValues);
// Caster levels
updateAvailCasterLevels(1, 20);
//Metamagic
if (metaAllowed) {
List<Ability> metamagicFeats = new ArrayList<>();
for (Ability anAbility : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, AbilityCategory.FEAT).getAllObjects()) {
if (anAbility.isType("Metamagic")) {
metamagicFeats.add(anAbility);
}
}
Globals.sortPObjectListByName(metamagicFeats);
availMetamagicFeats.setContents(metamagicFeats);
}
}
use of pcgen.core.spell.Spell in project pcgen by PCGen.
the class Gui2InfoFactory method getDescription.
@Override
public String getDescription(SpellFacade spellFacade) {
if (spellFacade == null || !(spellFacade instanceof SpellFacadeImplem)) {
return EMPTY_STRING;
}
try {
SpellFacadeImplem spell = (SpellFacadeImplem) spellFacade;
Spell aSpell = spell.getSpell();
if (aSpell == null) {
return EMPTY_STRING;
}
return DescriptionFormatting.piWrapDesc(aSpell, pc.getDescription(aSpell), false);
} catch (Exception e) {
//$NON-NLS-1$
Logging.errorPrint("Failed to get description for " + spellFacade, e);
return EMPTY_STRING;
}
}
Aggregations