use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class TemplateToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, KitTemplate kitTemplate, String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
int openLoc = tokText.indexOf('[');
String name;
List<CDOMSingleRef<PCTemplate>> subList;
if (openLoc == -1) {
name = tokText;
subList = null;
} else {
name = tokText.substring(0, openLoc);
subList = new ArrayList<>();
String rest = tokText.substring(openLoc + 1);
StringTokenizer subTok = new StringTokenizer(rest, "[]");
while (subTok.hasMoreTokens()) {
String subStr = subTok.nextToken();
if (subStr.startsWith("TEMPLATE:")) {
String ownedTemplateName = subStr.substring(9);
CDOMSingleRef<PCTemplate> ref = context.getReferenceContext().getCDOMReference(TEMPLATE_CLASS, ownedTemplateName);
subList.add(ref);
} else {
return new ParseResult.Fail("Did not understand " + getTokenName() + " option: " + subStr + " in line: " + value, context);
}
}
}
CDOMSingleRef<PCTemplate> ref = context.getReferenceContext().getCDOMReference(TEMPLATE_CLASS, name);
kitTemplate.addTemplate(ref, subList);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class SizeFacetTest method testGetFromTemplateHigherOverridesRace.
@Test
public void testGetFromTemplateHigherOverridesRace() {
Race r = new Race();
r.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(3));
rfacet.set(id, r);
PCTemplate t1 = new PCTemplate();
t1.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(4));
tfacet.add(id, t1, this);
facet.update(id);
assertEquals(4, facet.sizeInt(id));
tfacet.remove(id, t1, this);
facet.update(id);
assertEquals(3, facet.sizeInt(id));
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class SizeFacetTest method testGetAbbWithBonus.
@Test
public void testGetAbbWithBonus() {
assertEquals("M", facet.getSizeAbb(id));
facet.update(id);
assertEquals("M", facet.getSizeAbb(id));
Race r = new Race();
r.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(1));
rfacet.set(id, r);
facet.update(id);
assertEquals("S", facet.getSizeAbb(id));
bonusInfo.put(altid, 2.0);
// No pollution
facet.update(id);
assertEquals("S", facet.getSizeAbb(id));
bonusInfo.put(id, 2.0);
facet.update(id);
assertEquals("L", facet.getSizeAbb(id));
PCTemplate t1 = new PCTemplate();
t1.setName("PCT");
t1.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(0));
tfacet.add(id, t1, this);
facet.update(id);
assertEquals("M", facet.getSizeAbb(id));
PCTemplate t2 = new PCTemplate();
t2.setName("Other");
t2.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(3));
tfacet.add(id, t2, this);
facet.update(id);
assertEquals("H", facet.getSizeAbb(id));
tfacet.remove(id, t2, this);
facet.update(id);
assertEquals("M", facet.getSizeAbb(id));
bonusInfo.put(id, -2.0);
t1.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(1));
facet.update(id);
assertEquals("T", facet.getSizeAbb(id));
t2.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(4));
tfacet.add(id, t2, this);
facet.update(id);
assertEquals("M", facet.getSizeAbb(id));
tfacet.remove(id, t2, this);
facet.update(id);
assertEquals("T", facet.getSizeAbb(id));
bonusInfo.clear();
facet.update(id);
assertEquals("S", facet.getSizeAbb(id));
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class SizeFacetTest method testGetFromTemplateLowerOverridesDefault.
@Test
public void testGetFromTemplateLowerOverridesDefault() {
rfacet.set(id, new Race());
PCTemplate t1 = new PCTemplate();
t1.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(1));
tfacet.add(id, t1, this);
facet.update(id);
assertEquals(1, facet.sizeInt(id));
tfacet.remove(id, t1, this);
facet.update(id);
assertEquals(2, facet.sizeInt(id));
}
use of pcgen.core.PCTemplate in project pcgen by PCGen.
the class SizeFacetTest method testGetWithNegativeBonus.
@Test
public void testGetWithNegativeBonus() {
assertEquals(2, facet.sizeInt(id));
assertEquals(2, facet.racialSizeInt(id));
Race r = new Race();
r.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(3));
rfacet.set(id, r);
facet.update(id);
assertEquals(3, facet.sizeInt(id));
assertEquals(3, facet.racialSizeInt(id));
bonusInfo.put(altid, -2.0);
// No pollution
facet.update(id);
assertEquals(3, facet.sizeInt(id));
assertEquals(3, facet.racialSizeInt(id));
bonusInfo.put(id, -2.0);
facet.update(id);
assertEquals(1, facet.sizeInt(id));
assertEquals(3, facet.racialSizeInt(id));
PCTemplate t1 = new PCTemplate();
t1.setName("PCT");
t1.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(1));
tfacet.add(id, t1, this);
facet.update(id);
assertEquals(0, facet.sizeInt(id));
assertEquals(1, facet.racialSizeInt(id));
PCTemplate t2 = new PCTemplate();
t2.setName("Other");
t2.put(FormulaKey.SIZE, FormulaFactory.getFormulaFor(4));
tfacet.add(id, t2, this);
facet.update(id);
assertEquals(2, facet.sizeInt(id));
assertEquals(4, facet.racialSizeInt(id));
tfacet.remove(id, t2, this);
facet.update(id);
assertEquals(0, facet.sizeInt(id));
assertEquals(1, facet.racialSizeInt(id));
bonusInfo.clear();
facet.update(id);
assertEquals(1, facet.sizeInt(id));
assertEquals(1, facet.racialSizeInt(id));
}
Aggregations