use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class ConsolidatedListCommitStrategy method getChangesInMasterList.
@Override
public <T extends CDOMObject> AssociatedChanges<T> getChangesInMasterList(String tokenName, CDOMObject owner, CDOMReference<? extends CDOMList<T>> swl) {
Set<CDOMObject> added = masterList.getSecondaryKeySet(swl);
MapToList<T, AssociatedPrereqObject> owned = new TreeMapToList<>(CDOMObjectUtilities.CDOM_SORTER);
for (CDOMObject lw : added) {
List<AssociatedPrereqObject> list = masterList.getListFor(swl, lw);
for (AssociatedPrereqObject assoc : list) {
if (owner.equals(assoc.getAssociation(AssociationKey.OWNER))) {
owned.addToListFor((T) lw, assoc);
break;
}
}
}
return new AssociatedCollectionChanges<>(owned, null, false);
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class ListChanges method getAdded.
@Override
public Collection<CDOMReference<T>> getAdded() {
TreeSet<CDOMReference<T>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
Collection<CDOMReference<T>> listMods = positive.getListMods(list);
if (listMods != null) {
for (CDOMReference<T> ref : listMods) {
for (AssociatedPrereqObject assoc : positive.getListAssociations(list, ref)) {
if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
set.add(ref);
}
}
}
}
return set;
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class ListChanges method getRemoved.
@Override
public Collection<CDOMReference<T>> getRemoved() {
TreeSet<CDOMReference<T>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
if (negative == null) {
return set;
}
Collection<CDOMReference<T>> listMods = negative.getListMods(list);
if (listMods != null) {
for (CDOMReference<T> ref : listMods) {
for (AssociatedPrereqObject assoc : negative.getListAssociations(list, ref)) {
if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
set.add(ref);
}
}
}
}
return set;
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class AbstractListContext method remove.
private <BT extends CDOMObject, L extends CDOMList<BT>> void remove(CDOMObject owner, CDOMObject neg, CDOMReference<L> list) {
ListCommitStrategy commit = getCommitStrategy();
Collection<CDOMReference<BT>> mods = neg.getListMods(list);
for (CDOMReference<BT> ref : mods) {
for (AssociatedPrereqObject assoc : neg.getListAssociations(list, ref)) {
String token = assoc.getAssociation(AssociationKey.TOKEN);
AssociatedPrereqObject edge = commit.removeFromList(token, owner, list, ref);
Collection<AssociationKey<?>> associationKeys = assoc.getAssociationKeys();
for (AssociationKey<?> ak : associationKeys) {
setAssoc(assoc, edge, ak);
}
edge.addAllPrerequisites(assoc.getPrerequisiteList());
}
}
}
use of pcgen.cdom.base.AssociatedPrereqObject in project pcgen by PCGen.
the class SpellsFacet method dataAdded.
/**
* Adds a SpellLikeAbility to this facet if the CDOMObject added to a Player
* Character contains a SPELLS entry.
*
* Triggered when one of the Facets to which SpellsFacet 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) {
CharID id = dfce.getCharID();
CDOMObject cdo = dfce.getCDOMObject();
Collection<CDOMReference<Spell>> mods = cdo.getListMods(Spell.SPELLS);
if (mods == null) {
return;
}
for (CDOMReference<Spell> ref : mods) {
Collection<AssociatedPrereqObject> assocs = cdo.getListAssociations(Spell.SPELLS, ref);
Collection<Spell> spells = ref.getContainedObjects();
for (AssociatedPrereqObject apo : assocs) {
Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
String timeunit = apo.getAssociation(AssociationKey.TIME_UNIT);
// The timeunit needs to default to day as per the docs
if (timeunit == null) {
timeunit = "Day";
}
String casterlevel = apo.getAssociation(AssociationKey.CASTER_LEVEL);
String dcformula = apo.getAssociation(AssociationKey.DC_FORMULA);
String book = apo.getAssociation(AssociationKey.SPELLBOOK);
String ident = cdo.getQualifiedKey();
for (Spell sp : spells) {
SpellLikeAbility sla = new SpellLikeAbility(sp, times, timeunit, book, casterlevel, dcformula, ident);
sla.addAllPrerequisites(apo.getPrerequisiteList());
add(id, sla, cdo);
}
}
}
}
Aggregations