Search in sources :

Example 16 with PCTemplate

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

Example 17 with PCTemplate

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

Example 18 with PCTemplate

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

Example 19 with PCTemplate

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);
        }
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 20 with PCTemplate

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

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