use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class AvailableSpellInputFacet method processList.
private void processList(CharID id, CDOMList<Spell> spelllist, CDOMReference<? extends CDOMList<?>> listref, CDOMObject cdo) {
for (CDOMReference<Spell> objref : cdo.getListMods((CDOMReference<? extends CDOMList<Spell>>) listref)) {
for (AssociatedPrereqObject apo : cdo.getListAssociations(listref, objref)) {
Collection<Spell> spells = objref.getContainedObjects();
Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
if (apo.hasPrerequisites()) {
List<Prerequisite> prereqs = apo.getPrerequisiteList();
for (Spell spell : spells) {
AvailableSpell as = new AvailableSpell(spelllist, spell, lvl);
as.addAllPrerequisites(prereqs);
conditionallyAvailableSpellFacet.add(id, as, cdo);
}
} else {
for (Spell spell : spells) {
availableSpellFacet.add(id, spelllist, lvl, spell, cdo);
}
}
}
}
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class VisionLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
AssociatedChanges<CDOMReference<Vision>> changes = context.getListContext().getChangesInList(getTokenName(), obj, Vision.VISIONLIST);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Vision>> removedItems = changes.getRemoved();
if (changes.includesGlobalClear()) {
if (removedItems != null && !removedItems.isEmpty()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR);
} else if (removedItems != null && !removedItems.isEmpty()) {
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
}
MapToList<CDOMReference<Vision>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl != null && !mtl.isEmpty()) {
MapToList<Set<Prerequisite>, Vision> m = new HashMapToList<>();
for (CDOMReference<Vision> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
m.addAllToListFor(new HashSet<>(assoc.getPrerequisiteList()), ab.getContainedObjects());
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
StringBuilder sb = new StringBuilder(StringUtil.join(m.getListFor(prereqs), Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
list.addAll(set);
}
if (list.isEmpty()) {
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class SpellsLst method processAdds.
private Collection<? extends String> processAdds(LoadContext context, MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl) {
TripleKeyMap<Set<Prerequisite>, Map<AssociationKey<?>, Object>, CDOMReference<Spell>, String> m = new TripleKeyMap<>();
for (CDOMReference<Spell> lw : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(lw)) {
Map<AssociationKey<?>, Object> am = new HashMap<>();
String dc = null;
for (AssociationKey<?> ak : assoc.getAssociationKeys()) {
// else
if (AssociationKey.DC_FORMULA.equals(ak)) {
dc = assoc.getAssociation(AssociationKey.DC_FORMULA);
} else {
am.put(ak, assoc.getAssociation(ak));
}
}
m.put(new HashSet<>(assoc.getPrerequisiteList()), am, lw, dc);
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
for (Map<AssociationKey<?>, Object> am : m.getSecondaryKeySet(prereqs)) {
StringBuilder sb = new StringBuilder();
sb.append(am.get(AssociationKey.SPELLBOOK));
Formula times = AssociationKey.TIMES_PER_UNIT.cast(am.get(AssociationKey.TIMES_PER_UNIT));
sb.append(Constants.PIPE).append("TIMES=").append(times);
String timeunit = AssociationKey.TIME_UNIT.cast(am.get(AssociationKey.TIME_UNIT));
if (timeunit != null) {
sb.append(Constants.PIPE).append("TIMEUNIT=").append(timeunit);
}
String casterLvl = AssociationKey.CASTER_LEVEL.cast(am.get(AssociationKey.CASTER_LEVEL));
if (casterLvl != null) {
sb.append(Constants.PIPE).append("CASTERLEVEL=").append(casterLvl);
}
Set<String> spellSet = new TreeSet<>();
for (CDOMReference<Spell> spell : m.getTertiaryKeySet(prereqs, am)) {
String spellString = spell.getLSTformat(false);
String dc = m.get(prereqs, am, spell);
if (dc != null) {
spellString += Constants.COMMA + dc;
}
spellSet.add(spellString);
}
sb.append(Constants.PIPE);
sb.append(StringUtil.join(spellSet, Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
}
return set;
}
use of pcgen.cdom.base.AssociatedPrereqObject 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.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class DomainApplication method applyDomain.
/**
* Sets the locked flag on a PC
*
* @param pc
*/
public static void applyDomain(PlayerCharacter pc, Domain d) {
ClassSource source = pc.getDomainSource(d);
PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
if (aClass != null) {
int maxLevel;
for (maxLevel = 0; maxLevel < 10; maxLevel++) {
if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
break;
}
}
if (maxLevel > 0) {
addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
}
if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
DomainSpellList domainSpellList = d.get(ObjectKey.DOMAIN_SPELLLIST);
final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
for (Spell gcs : aList) {
if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
pc.setDomainSpellCount(aClass, 1);
break;
}
}
}
}
Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
for (CDOMReference<Spell> ref : mods) {
Collection<Spell> spells = ref.getContainedObjects();
Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
for (AssociatedPrereqObject apo : assoc) {
if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
continue;
}
for (Spell s : spells) {
String book = apo.getAssociation(AssociationKey.SPELLBOOK);
List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);
if (aList.isEmpty()) {
Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
CharacterSpell cs = new CharacterSpell(d, s);
int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
cs.addInfo(1, resolvedTimes, book);
pc.addCharacterSpell(aClass, cs);
}
}
}
}
}
Aggregations