use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class TemplateFavoredClassTest method testDirect.
@Test
public void testDirect() throws PersistenceLayerException {
PCTemplate source = create(PCTemplate.class, "Source");
ParseResult result = token.parseToken(context, source, "Favorite");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(baseCount(), targetFacetCount());
templateInputFacet.directAdd(id, source, getAssoc());
assertTrue(containsExpected());
assertEquals(baseCount() + 1, targetFacetCount());
templateInputFacet.remove(id, source);
assertEquals(baseCount(), targetFacetCount());
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class AbstractContentTokenTest method testFromTemplate.
@Test
public void testFromTemplate() throws PersistenceLayerException {
PCTemplate source = create(PCTemplate.class, "Source");
processToken(source);
assertEquals(baseCount(), targetFacetCount());
templateInputFacet.directAdd(id, source, getAssoc());
assertTrue(containsExpected());
assertEquals(baseCount() + 1, targetFacetCount());
templateInputFacet.remove(id, source);
assertEquals(baseCount(), targetFacetCount());
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class LevelFacet method getLevelAdjustment.
/**
* Returns the level adjustment for the Player Character identified by the
* given CharID.
*
* @param id
* The CharID of the Player Character for which the level
* adjustment will be returned
* @return The level adjustment for the Player Character identified by the
* given CharID
*/
public int getLevelAdjustment(CharID id) {
Race race = raceFacet.get(id);
int levelAdj = 0;
if (race != null) {
Formula raceLA = race.getSafe(FormulaKey.LEVEL_ADJUSTMENT);
levelAdj += formulaResolvingFacet.resolve(id, raceLA, "").intValue();
}
for (PCTemplate template : templateFacet.getSet(id)) {
Formula templateLA = template.getSafe(FormulaKey.LEVEL_ADJUSTMENT);
levelAdj += formulaResolvingFacet.resolve(id, templateLA, "").intValue();
}
return levelAdj;
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class ConditionalTemplateFacet method levelChanged.
/**
* Adds (or removes) all of the conditional Templates available to the
* Player Character to this ConditionalTemplateFacet. This requires a global
* check of all Templates granted to the Player Character, since this is
* occurring when the Player Character level changes.
*
* Triggered when the Level of the Player Character changes.
*
* @param lce
* The LevelChangeEvent containing the information about the
* level change
*
* @see pcgen.cdom.facet.analysis.LevelFacet.LevelChangeListener#levelChanged(pcgen.cdom.facet.analysis.LevelFacet.LevelChangeEvent)
*/
@Override
public void levelChanged(LevelChangeEvent lce) {
CharID id = lce.getCharID();
Collection<PCTemplate> oldSet = getSet(id);
int totalLevels = levelFacet.getTotalLevels(id);
int totalHitDice = levelFacet.getMonsterLevelCount(id);
Map<PCTemplate, PCTemplate> newMap = new IdentityHashMap<>();
for (PCTemplate sourceTempl : templateFacet.getSet(id)) {
List<PCTemplate> conditionalTemplates = sourceTempl.getConditionalTemplates(totalLevels, totalHitDice);
for (PCTemplate condTempl : conditionalTemplates) {
newMap.put(condTempl, sourceTempl);
}
}
// Delete items that the PC no longer has
for (PCTemplate a : oldSet) {
if (!newMap.containsKey(a)) {
remove(id, a);
}
}
//Add new items
for (Map.Entry<PCTemplate, PCTemplate> me : newMap.entrySet()) {
PCTemplate a = me.getKey();
// We need to check for presence by object identity (==) rather than equality (.equals)
boolean found = false;
for (PCTemplate pcTemplate : oldSet) {
if (a == pcTemplate) {
found = true;
}
}
if (!found) {
add(id, a);
}
}
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class ConditionalTemplateFacet method dataRemoved.
/**
* Removes all of the conditional Templates granted by the object removed
* from the Player Character.
*
* Triggered when one of the Facets to which ConditionalTemplateFacet
* listens fires a DataFacetChangeEvent to indicate a PCTemplate was removed
* from a Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataRemoved(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataRemoved(DataFacetChangeEvent<CharID, PCTemplate> dfce) {
CharID id = dfce.getCharID();
int totalLevels = levelFacet.getTotalLevels(id);
int totalHitDice = levelFacet.getMonsterLevelCount(id);
PCTemplate source = dfce.getCDOMObject();
removeAll(dfce.getCharID(), source.getConditionalTemplates(totalLevels, totalHitDice));
}
Aggregations