use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class AutoLangListTest method testFromTemplate.
@Test
public void testFromTemplate() throws PersistenceLayerException {
PCTemplate source = create(PCTemplate.class, "Source");
Language granted = createGrantedObject();
processToken(source);
assertEquals(0, getCount());
templateInputFacet.directAdd(id, source, getAssoc());
assertTrue(containsExpected(granted));
assertEquals(1, getCount());
templateInputFacet.remove(id, source);
assertEquals(0, getCount());
assertTrue(cleanedSideEffects());
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class AddLevelFacet method dataRemoved.
/**
* Drives the necessary removal of the results of an ADDLEVEL: token to
* remove the added levels from a Player Character because the object
* granting the ADDLEVEL: was removed from the Player Character.
*
* Triggered when one of the Facets to which AddLevelFacet 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 dataRemoved(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
PCTemplate template = dfce.getCDOMObject();
CharID id = dfce.getCharID();
PlayerCharacter pc = trackingFacet.getPC(id);
List<LevelCommandFactory> lcfList = template.getSafeListFor(ListKey.ADD_LEVEL);
for (ListIterator<LevelCommandFactory> it = lcfList.listIterator(lcfList.size()); it.hasPrevious(); ) {
LevelCommandFactory lcf = it.previous();
remove(lcf.getLevelCount(), lcf.getPCClass(), pc);
}
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class KitTemplate method apply.
/**
* Actually applies the templates to this PC.
*
* @param aPC The PlayerCharacter the alignment is applied to
*/
@Override
public void apply(PlayerCharacter aPC) {
HashMapToList<PCTemplate, PCTemplate> selectedMap = buildSelectedTemplateMap(aPC, true);
boolean tempShowHP = SettingsHandler.getShowHPDialogAtLevelUp();
SettingsHandler.setShowHPDialogAtLevelUp(false);
for (PCTemplate template : selectedMap.getKeySet()) {
List<PCTemplate> added = selectedMap.getListFor(template);
if (added != null) {
for (PCTemplate subtemplate : added) {
aPC.setTemplatesAdded(template, subtemplate);
}
}
aPC.addTemplate(template);
}
SettingsHandler.setShowHPDialogAtLevelUp(tempShowHP);
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class KitTemplate method buildSelectedTemplateMap.
/**
* Extract the templates to be applied and their choices
* @param aPC The PC the kit is being applied to.
* @param apply Is this a real application, false if a test run.
* @return The map of templates and child templates to be added
*/
private HashMapToList<PCTemplate, PCTemplate> buildSelectedTemplateMap(PlayerCharacter aPC, boolean apply) {
boolean tempShowHP = SettingsHandler.getShowHPDialogAtLevelUp();
SettingsHandler.setShowHPDialogAtLevelUp(false);
if (!apply) {
ChooserFactory.pushChooserClassname(//$NON-NLS-1$
"pcgen.util.chooser.RandomChooser");
}
HashMapToList<PCTemplate, PCTemplate> selectedMap = new HashMapToList<>();
for (CDOMSingleRef<PCTemplate> ref : templateList.getKeySet()) {
PCTemplate templateToAdd = ref.get();
List<CDOMSingleRef<PCTemplate>> subList = templateList.getListFor(ref);
List<PCTemplate> subAdded = new ArrayList<>();
if (subList != null) {
for (CDOMSingleRef<PCTemplate> subRef : subList) {
PCTemplate ownedTemplate = subRef.get();
subAdded.add(ownedTemplate);
aPC.setTemplatesAdded(templateToAdd, ownedTemplate);
}
}
aPC.addTemplate(templateToAdd);
selectedMap.initializeListFor(templateToAdd);
selectedMap.addAllToListFor(templateToAdd, subAdded);
}
if (!apply) {
ChooserFactory.popChooserClassname();
}
SettingsHandler.setShowHPDialogAtLevelUp(tempShowHP);
return selectedMap;
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class TemplateListToken method getToken.
/**
* @see pcgen.io.exporttoken.AbstractExportToken#getToken(java.lang.String, pcgen.core.display.CharacterDisplay, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) {
StringBuilder retString = new StringBuilder();
String del = "";
for (PCTemplate template : display.getOutputVisibleTemplateList()) {
// karianna bug 1514970
retString.append(del).append(OutputNameFormatting.getOutputName(template));
del = ", ";
}
return retString.toString();
}
Aggregations