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;
}
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;
}
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)"));
}
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));
}
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));
}
Aggregations