/** * Drives the selection of the AgeSet Kit for a Player Character when relevant changes (change to * an AgeSet) are made to a Player Character. * * <p>Triggered when one of the Facets to which AgeSetKitFacet 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, Integer> dfce) { CharID id = dfce.getCharID(); AgeSet ageSet = ageSetFacet.get(id); PlayerCharacter pc = trackingFacet.getPC(id); // TODO Is ageSet null check necessary? if (ageSet == null || pc.isImporting()) { return; } int ageSetIndex = ageSetFacet.getAgeSetIndex(id); /* * TODO The method of storing what AgeSets have had kit selections made * should be converted to store the actual AgeSet rather than the index, * in order to reduce the number of calls to ageSetFacet.getAgeSetIndex. * This (of course) drives the move of the AgeSets for which a kit * selection has been made into a Facet. It is possible that the * CacheInfo of AgeSetKitFacet is actually a good place to store that * information (or it may be implicit with the information already * stored there??) */ if (!pc.hasMadeKitSelectionForAgeSet(ageSetIndex)) { CacheInfo cache = getConstructingClassInfo(id); List<Kit> kits = cache.get(ageSet); if (kits != null) { // Need to do selection BioSet bioSet = bioSetFacet.get(id); for (TransitionChoice<Kit> kit : ageSet.getKits()) { Collection<? extends Kit> choice = kit.driveChoice(pc); cache.put(ageSet, choice); kit.act(choice, bioSet, pc); } } pc.setHasMadeKitSelectionForAgeSet(ageSetIndex, true); } }