use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class ListSkillCostFacet method dataAdded.
/**
* Adds the SkillCost objects granted by CDOMObjects, as applied directly to
* a ClassSkillList, when a CDOMObject is added to a Player Character.
*
* Triggered when one of the Facets to which ListSkillCostFacet listens
* fires a DataFacetChangeEvent to indicate a CDOMObject was added to a
* Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
CharID id = dfce.getCharID();
for (CDOMReference ref : cdo.getModifiedLists()) {
List<ClassSkillList> useList = new ArrayList<>();
for (Object list : ref.getContainedObjects()) {
if (list instanceof ClassSkillList) {
useList.add((ClassSkillList) list);
}
}
if (!useList.isEmpty()) {
Collection<CDOMReference<Skill>> mods = cdo.getListMods(ref);
for (CDOMReference<Skill> skRef : mods) {
for (AssociatedPrereqObject apo : (Iterable<AssociatedPrereqObject>) cdo.getListAssociations(ref, skRef)) {
SkillCost sc = apo.getAssociation(AssociationKey.SKILL_COST);
for (ClassSkillList csl : useList) {
for (Skill skill : skRef.getContainedObjects()) {
add(id, csl, sc, skill, cdo);
}
}
}
}
}
}
}
use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.
the class AvailableSpellInputFacet method dataAdded.
/**
* Triggered when one of the Facets to which ConditionallyKnownSpellFacet
* listens fires a DataFacetChangeEvent to indicate a CDOMObject was added
* to a Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
Collection<CDOMReference<? extends CDOMList<?>>> listrefs = cdo.getModifiedLists();
CharID id = dfce.getCharID();
for (CDOMReference<? extends CDOMList<?>> ref : listrefs) {
processListRef(id, cdo, ref);
}
}
use of pcgen.cdom.base.CDOMReference 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.CDOMReference 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.CDOMReference in project pcgen by PCGen.
the class DeityToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
String retString = "";
CharacterDisplay display = pc.getDisplay();
Deity deity = display.getDeity();
if (deity != null) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
String subTag = "OUTPUTNAME";
if (aTok.countTokens() > 1) {
aTok.nextToken();
subTag = aTok.nextToken();
}
if ("NAME".equals(subTag)) {
if (!display.getSuppressBioField(BiographyField.DEITY)) {
retString = deity.getDisplayName();
}
} else if ("OUTPUTNAME".equals(subTag)) {
if (!display.getSuppressBioField(BiographyField.DEITY)) {
retString = OutputNameFormatting.getOutputName(deity);
}
} else if ("DOMAINLIST".equals(subTag)) {
retString = getDomainListToken(deity);
} else if ("FOLLOWERALIGNMENT".equals(subTag)) {
Logging.errorPrint("Output Sheet uses DEITY.FOLLOWERALIGN: " + "Function has been removed from PCGen");
} else if ("ALIGNMENT".equals(subTag)) {
CDOMSingleRef<PCAlignment> al = deity.get(ObjectKey.ALIGNMENT);
retString = al == null ? "" : al.get().getKeyName();
} else if ("APPEARANCE".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Appearance");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("DESCRIPTION".equals(subTag)) {
retString = pc.getDescription(deity);
} else if ("HOLYITEM".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Symbol");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("FAVOREDWEAPON".equals(subTag)) {
List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
retString = ReferenceUtilities.joinLstFormat(dwp, Constants.PIPE, true);
} else if ("PANTHEONLIST".equals(subTag)) {
FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
Set<String> pset = new TreeSet<>();
for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
pset.add(indirect.get());
}
retString = StringUtil.join(pset, ", ");
} else if ("SOURCE".equals(subTag)) {
retString = SourceFormat.getFormattedString(deity, Globals.getSourceDisplay(), true);
} else if ("SA".equals(subTag)) {
retString = getSAToken(deity, display);
} else if ("TITLE".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Title");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
} else if ("WORSHIPPERS".equals(subTag)) {
FactKey<String> fk = FactKey.valueOf("Worshippers");
String str = deity.getResolved(fk);
retString = (str == null) ? "" : str;
}
}
return retString;
}
Aggregations