Search in sources :

Example 11 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class TemplateTargetSaveRestoreTest method testTemplateFavoredClass.

@Test
public void testTemplateFavoredClass() {
    PCClass monclass = create(PCClass.class, "MonClass");
    new TypeLst().parseToken(context, monclass, "Monster");
    PCTemplate monster = create(PCTemplate.class, "Monster");
    create(PCClass.class, "MyClass");
    new FavoredclassToken().parseToken(context, monster, "%LIST");
    new ClassToken().parseToken(context, monster, "MonClass|MyClass");
    finishLoad();
    pc.addTemplate(monster);
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.getDisplay().getFavoredClasses().contains(monclass));
    assertTrue(reloadedPC.getDisplay().getFavoredClasses().contains(monclass));
    reloadedPC.removeTemplate(monster);
    reloadedPC.setDirty(true);
    assertFalse(reloadedPC.getDisplay().getFavoredClasses().contains(monclass));
}
Also used : FavoredclassToken(plugin.lsttokens.template.FavoredclassToken) ClassToken(plugin.lsttokens.choose.ClassToken) PCClass(pcgen.core.PCClass) TypeLst(plugin.lsttokens.TypeLst) PCTemplate(pcgen.core.PCTemplate) AbstractGlobalTargetedSaveRestoreTest(pcgen.io.testsupport.AbstractGlobalTargetedSaveRestoreTest) Test(org.junit.Test)

Example 12 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class GeneralSaveRestoreTest method testTemplateFeat.

public void testTemplateFeat() {
    //Represents CODE-2547
    TokenRegistration.register(new plugin.lsttokens.deprecated.TemplateFeatToken());
    TokenRegistration.register(new plugin.lsttokens.ability.StackToken());
    TokenRegistration.register(new plugin.exporttokens.deprecated.TemplateToken());
    Language lang = context.getReferenceContext().constructCDOMObject(Language.class, "English");
    Ability a = context.getReferenceContext().constructCDOMObject(Ability.class, "Ab");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, a);
    PCTemplate pct = context.getReferenceContext().constructCDOMObject(PCTemplate.class, "Templ");
    try {
        assertTrue(context.processToken(a, "MULT", "YES"));
        assertTrue(context.processToken(a, "STACK", "YES"));
        assertTrue(context.processToken(a, "CHOOSE", "LANG|English"));
        assertTrue(context.processToken(a, "AUTO", "LANG|%LIST"));
        assertTrue(context.processToken(pct, "FEAT", "Ab"));
    } catch (PersistenceLayerException e) {
        fail(e.getMessage());
    }
    finishLoad();
    pc.addTemplate(pct);
    assertTrue(pc.hasLanguage(lang));
    runRoundRobin(null);
    assertTrue(reloadedPC.hasLanguage(lang));
    List<CNAbility> cnaList = pc.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    List<String> assocs = pc.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    cnaList = reloadedPC.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    assocs = reloadedPC.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    assertEquals("Ab(English)", ExportHandler.getTokenString(pc, "TEMPLATE.0.FEAT"));
    assertEquals("Ab(English)", ExportHandler.getTokenString(reloadedPC, "TEMPLATE.0.FEAT"));
    reloadedPC.removeTemplate(pct);
    assertFalse(reloadedPC.hasLanguage(lang));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CNAbility(pcgen.cdom.content.CNAbility) Language(pcgen.core.Language) PCTemplate(pcgen.core.PCTemplate)

Example 13 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class BasicSaveRestoreTest method testTemplate.

//TODO No way to remove a alignment once set :(
//	@Test
//	public void testAlignmentAddRemove()
//	{
//		finishLoad();
//		runWriteRead();
//		pc.setAlignment(le);
//		pc.removeAlignment();
//		testEquality();
//	}
@Test
public void testTemplate() {
    PCTemplate template = create(PCTemplate.class, "MyTemplate");
    finishLoad();
    pc.addTemplate(template);
    runRoundRobin(null);
}
Also used : PCTemplate(pcgen.core.PCTemplate) Test(org.junit.Test) AbstractSaveRestoreTest(pcgen.io.testsupport.AbstractSaveRestoreTest)

Example 14 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class TemplateFavoredClassTest method testList.

@Test
public void testList() throws PersistenceLayerException {
    PCTemplate source = create(PCTemplate.class, "Source");
    ParseResult result = token.parseToken(context, source, "%LIST");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    result = CHOOSE_CLASS_TOKEN.parseToken(context, source, "Favorite");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    finishLoad();
    assertEquals(baseCount(), targetFacetCount());
    templateInputFacet.add(id, source);
    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 15 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class GlobalSpellKnownTest method testConditional.

public void testConditional() {
    Ability source = create(Ability.class, "Source");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, source);
    ParseResult result = token.parseToken(context, source, "CLASS|Wizard=2|Fireball|PREVARLTEQ:3,MyCasterLevel");
    if (result != ParseResult.SUCCESS) {
        result.printMessages();
        fail("Test Setup Failed");
    }
    finishLoad();
    assertEquals(baseCount(), targetFacetCount());
    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, source));
    directAbilityFacet.add(id, cas, UserSelection.getInstance());
    assertFalse(containsExpected());
    PCTemplate varsource = create(PCTemplate.class, "VarSource");
    varsource.put(VariableKey.getConstant("MyCasterLevel"), FormulaFactory.getFormulaFor(4.0));
    templateInputFacet.directAdd(id, varsource, null);
    pc.calcActiveBonuses();
    assertTrue(containsExpected());
    assertEquals(baseCount() + 1, targetFacetCount());
    directAbilityFacet.remove(id, cas, UserSelection.getInstance());
    pc.calcActiveBonuses();
    assertEquals(baseCount(), targetFacetCount());
}
Also used : Ability(pcgen.core.Ability) ParseResult(pcgen.rules.persistence.token.ParseResult) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) 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