Search in sources :

Example 51 with PCTemplate

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

the class ConditionalTemplateFacetTest method getObject.

@Override
protected PCTemplate getObject() {
    PCTemplate t = new PCTemplate();
    t.setName("PCTemplate" + n++);
    return t;
}
Also used : PCTemplate(pcgen.core.PCTemplate)

Example 52 with PCTemplate

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

the class TemplateToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
        count = FormulaFactory.ONE;
    } else {
        count = FormulaFactory.getFormulaFor(activeValue);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
        }
        activeValue = sep.next();
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
    if (!pr.passed()) {
        return pr;
    }
    List<CDOMReference<PCTemplate>> refs = new ArrayList<>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
        refs.add(context.getReferenceContext().getCDOMReference(PCTEMPLATE_CLASS, tok.nextToken()));
    }
    ReferenceChoiceSet<PCTemplate> rcs = new ReferenceChoiceSet<>(refs);
    ChoiceSet<PCTemplate> cs = new ChoiceSet<>("TEMPLATE", rcs);
    PersistentTransitionChoice<PCTemplate> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet) ChoiceSet(pcgen.cdom.base.ChoiceSet) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) StringTokenizer(java.util.StringTokenizer) ParsingSeparator(pcgen.base.text.ParsingSeparator) PCTemplate(pcgen.core.PCTemplate) CDOMReference(pcgen.cdom.base.CDOMReference) ReferenceChoiceSet(pcgen.cdom.choiceset.ReferenceChoiceSet)

Example 53 with PCTemplate

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

the class AddClassSkillsTest method testGetChoicesListWithClassSkill.

/**
	 * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
	 */
@Test
public void testGetChoicesListWithClassSkill() {
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    String classPCCText = "CLASS:Cleric	HD:8		TYPE:Base.PC	ABB:Clr\n" + "CLASS:Cleric	STARTSKILLPTS:2	CSKILL:KEY_Knowledge (Dungeoneering)";
    PCClass po;
    try {
        po = parsePCClassText(classPCCText, source);
    } catch (PersistenceLayerException e) {
        throw new UnreachableError(e);
    }
    getCharacter().incrementClassLevel(1, po, false);
    PCTemplate pct = new PCTemplate();
    Skill bluff = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, "KEY_Bluff");
    pct.addToListFor(ListKey.CSKILL, CDOMDirectSingleRef.getRef(bluff));
    getCharacter().addTemplate(pct);
    Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Knowledge (Arcana)");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
    assertEquals(1, choiceList.size());
    TransitionChoice<?> choice = choiceList.get(0);
    Collection<?> choiceSet = choice.getChoices().getSet(getCharacter());
    assertEquals(3, choiceSet.size());
    Set<Object> limitedSet = new HashSet<>();
    ClassSkillChoiceActor csca = new ClassSkillChoiceActor(po, 0);
    for (Object sc : choiceSet) {
        if (csca.allow((Skill) sc, getCharacter(), true)) {
            limitedSet.add(sc);
        }
    }
    assertEquals(2, limitedSet.size());
    assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
    List<String> choiceStrings = new ArrayList<>();
    for (Object o : limitedSet) {
        choiceStrings.add(o.toString());
    }
    assertTrue(choiceStrings.contains("Listen"));
    assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
Also used : PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) Campaign(pcgen.core.Campaign) ClassSkillChoiceActor(pcgen.cdom.helper.ClassSkillChoiceActor) PCTemplate(pcgen.core.PCTemplate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with PCTemplate

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

the class RegionFacetTest method testUseTemplateNameRegionTrue.

@Test
public void testUseTemplateNameRegionTrue() {
    PCTemplate pct = new PCTemplate();
    pct.setName("TestTemplate");
    pct.put(ObjectKey.USETEMPLATENAMEFORREGION, true);
    tfacet.add(id, pct, this);
    assertEquals("TestTemplate", facet.getRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterRegion(id));
    assertEquals(Constants.NONE, facet.getSubRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterSubRegion(id));
    assertEquals("TestTemplate", facet.getFullRegion(id));
}
Also used : PCTemplate(pcgen.core.PCTemplate) Test(org.junit.Test)

Example 55 with PCTemplate

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

the class RegionFacetTest method testMultipleRegionSetSecondDominatesRegion.

@Test
public void testMultipleRegionSetSecondDominatesRegion() {
    PCTemplate pct = new PCTemplate();
    pct.setName("PCT");
    pct.put(ObjectKey.REGION, Region.getConstant(TEST_REGION_NAME));
    tfacet.add(id, pct, this);
    assertEquals(TEST_REGION_NAME, facet.getRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterRegion(id));
    assertEquals(Constants.NONE, facet.getSubRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterSubRegion(id));
    assertEquals(TEST_REGION_NAME, facet.getFullRegion(id));
    PCTemplate pct2 = new PCTemplate();
    pct2.setName("Other");
    pct2.put(ObjectKey.REGION, Region.getConstant("TestRegionToo"));
    tfacet.add(id, pct2, this);
    assertEquals("TestRegionToo", facet.getRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterRegion(id));
    assertEquals(Constants.NONE, facet.getSubRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterSubRegion(id));
    assertEquals("TestRegionToo", facet.getFullRegion(id));
    tfacet.remove(id, pct2, this);
    assertEquals(TEST_REGION_NAME, facet.getRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterRegion(id));
    assertEquals(Constants.NONE, facet.getSubRegion(id));
    assertEquals(Constants.NONE, facet.getCharacterSubRegion(id));
    assertEquals(TEST_REGION_NAME, facet.getFullRegion(id));
}
Also used : PCTemplate(pcgen.core.PCTemplate) Test(org.junit.Test)

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