use of pcgen.cdom.base.AssociatedPrereqObject 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.AssociatedPrereqObject in project pcgen by PCGen.
the class PlayerCharacter method processAbilityList.
private void processAbilityList(CDOMObject cdo, CDOMReference<AbilityList> ref) {
Collection<CDOMReference<Ability>> mods = cdo.getListMods(ref);
for (CDOMReference<Ability> objref : mods) {
Collection<Ability> objs = objref.getContainedObjects();
Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(ref, objref);
for (Ability ab : objs) {
if (ab == null) {
Logging.log(Logging.LST_ERROR, "Missing object referenced in the ability list for '" + cdo + "' list is " + ref + ". Source " + cdo.getSourceURI());
continue;
}
for (AssociatedPrereqObject apo : assoc) {
Nature nature = apo.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> acRef = apo.getAssociation(AssociationKey.CATEGORY);
AbilityCategory cat = acRef.get();
if (ab.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
List<String> choices = apo.getAssociation(AssociationKey.ASSOC_CHOICES);
if (choices == null) {
//CHOOSE:NOCHOICE can be unconditionally applied (must be STACK:YES)
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), "");
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
} else {
for (final String choice : choices) {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), choice);
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
} else {
CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab));
cas.addAllPrerequisites(apo.getPrerequisiteList());
applyAbility(cas, cdo);
}
}
}
}
cabFacet.update(id);
}
use of pcgen.cdom.base.AssociatedPrereqObject 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.AssociatedPrereqObject in project pcgen by PCGen.
the class AdddomainsToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), pcc, PCClass.ALLOWED_DOMAINS);
Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR");
return null;
}
MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl == null || mtl.isEmpty()) {
return null;
}
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
Set<String> set = new TreeSet<>();
Set<String> noPrereqSet = new TreeSet<>();
for (CDOMReference<Domain> domain : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
List<Prerequisite> prereqs = assoc.getPrerequisiteList();
if (prereqs == null || prereqs.isEmpty()) {
noPrereqSet.add(sb.toString());
continue;
}
for (Prerequisite prereq : prereqs) {
sb.append(Constants.PIPE);
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append(swriter.toString());
}
set.add(sb.toString());
}
}
if (!noPrereqSet.isEmpty()) {
set.add(StringUtil.join(noPrereqSet, Constants.PIPE));
}
return set.toArray(new String[set.size()]);
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class MoncskillToken method unparse.
@Override
public String[] unparse(LoadContext context, Race race) {
CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(race, ListKey.NEW_CHOOSE_ACTOR);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty()) {
if (changes.includesGlobalClear()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
}
Collection<ChooseSelectionActor<?>> listRemoved = listChanges.getRemoved();
if (listRemoved != null && !listRemoved.isEmpty()) {
if (listRemoved.contains(this)) {
list.add(".CLEAR.LIST");
}
}
if (changes.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR);
}
MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
if (map != null && !map.isEmpty()) {
Set<CDOMReference<Skill>> added = map.getKeySet();
for (CDOMReference<Skill> ab : added) {
for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
if (!SkillCost.CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
context.addWriteMessage("Skill Cost must be " + "CLASS for Token " + getTokenName());
return null;
}
}
}
list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
}
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> csa : listAdded) {
if (csa.getSource().equals(getTokenName())) {
try {
list.add(csa.getLstFormat());
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (list.isEmpty()) {
// Zero indicates no add or clear
return null;
}
return list.toArray(new String[list.size()]);
}
Aggregations