MCPcopy Create free account
hub / github.com/PCGen/pcgen / dataAdded

Method dataAdded

code/src/java/pcgen/cdom/facet/SpellsFacet.java:57–95  ·  view source on GitHub ↗

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 DataFacetChan

(DataFacetChangeEvent<CharID, CDOMObject> dfce)

Source from the content-addressed store, hash-verified

55 * change
56 */
57 @Override
58 public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce)
59 {
60 CharID id = dfce.getCharID();
61 CDOMObject cdo = dfce.getCDOMObject();
62
63 Collection<CDOMReference<Spell>> mods = cdo.getListMods(Spell.SPELLS);
64 if (mods == null)
65 {
66 return;
67 }
68
69 for (CDOMReference<Spell> ref : mods)
70 {
71 Collection<AssociatedPrereqObject> assocs = cdo.getListAssociations(Spell.SPELLS, ref);
72 Collection<Spell> spells = ref.getContainedObjects();
73 for (AssociatedPrereqObject apo : assocs)
74 {
75 Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
76 String timeunit = apo.getAssociation(AssociationKey.TIME_UNIT);
77 // The timeunit needs to default to day as per the docs
78 if (timeunit == null)
79 {
80 timeunit = "Day";
81 }
82 String casterlevel = apo.getAssociation(AssociationKey.CASTER_LEVEL);
83 String dcformula = apo.getAssociation(AssociationKey.DC_FORMULA);
84 String book = apo.getAssociation(AssociationKey.SPELLBOOK);
85 String ident = cdo.getQualifiedKey();
86 for (Spell sp : spells)
87 {
88 SpellLikeAbility sla =
89 new SpellLikeAbility(sp, times, timeunit, book, casterlevel, dcformula, ident);
90 sla.addAllPrerequisites(apo.getPrerequisiteList());
91 add(id, sla, cdo);
92 }
93 }
94 }
95 }
96
97 /**
98 * Removes all SpellLikeAbility objects granted by a CDOMObject when that

Callers

nothing calls this directly

Calls 10

getListModsMethod · 0.95
getListAssociationsMethod · 0.95
getQualifiedKeyMethod · 0.95
getCharIDMethod · 0.65
getCDOMObjectMethod · 0.65
getContainedObjectsMethod · 0.65
getAssociationMethod · 0.65
addAllPrerequisitesMethod · 0.65
getPrerequisiteListMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected