Search in sources :

Example 91 with PCTemplate

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) PCTemplate(pcgen.core.PCTemplate) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 92 with PCTemplate

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

Example 93 with PCTemplate

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

Example 94 with PCTemplate

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

Example 95 with PCTemplate

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