Search in sources :

Example 26 with PCTemplate

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());
}
Also used : Language(pcgen.core.Language) PCTemplate(pcgen.core.PCTemplate) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 27 with PCTemplate

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);
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID)

Example 28 with PCTemplate

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);
}
Also used : PCTemplate(pcgen.core.PCTemplate)

Example 29 with PCTemplate

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;
}
Also used : HashMapToList(pcgen.base.util.HashMapToList) ArrayList(java.util.ArrayList) PCTemplate(pcgen.core.PCTemplate) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 30 with PCTemplate

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();
}
Also used : PCTemplate(pcgen.core.PCTemplate)

Aggregations

PCTemplate (pcgen.core.PCTemplate)215 Test (org.junit.Test)105 Race (pcgen.core.Race)66 PlayerCharacter (pcgen.core.PlayerCharacter)38 CDOMObject (pcgen.cdom.base.CDOMObject)31 ArrayList (java.util.ArrayList)19 CharID (pcgen.cdom.enumeration.CharID)18 ParseResult (pcgen.rules.persistence.token.ParseResult)14 SimpleAssociatedObject (pcgen.cdom.base.SimpleAssociatedObject)13 Vision (pcgen.core.Vision)12 LoadContext (pcgen.rules.context.LoadContext)12 PCClass (pcgen.core.PCClass)11 StringTokenizer (java.util.StringTokenizer)10 VariableKey (pcgen.cdom.enumeration.VariableKey)8 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)8 Ability (pcgen.core.Ability)8 Formula (pcgen.base.formula.Formula)6 Equipment (pcgen.core.Equipment)6 PCStat (pcgen.core.PCStat)6 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)6