Search in sources :

Example 16 with SubClass

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

the class SubClassTokenTest method testInvalidInputOnlyOne.

@Test
public void testInvalidInputOnlyOne() throws PersistenceLayerException {
    SubClassCategory cat = SubClassCategory.getConstant("Wizard");
    SubClass sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
    primaryContext.getReferenceContext().reassociateCategory(cat, sc);
    sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
    secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
    sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "English");
    primaryContext.getReferenceContext().reassociateCategory(cat, sc);
    sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "English");
    secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
    assertTrue(parse("Fireball,English"));
    assertConstructionError();
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) Test(org.junit.Test)

Example 17 with SubClass

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

the class SubClassTokenTest method testRoundRobinSimple.

@Test
public void testRoundRobinSimple() throws PersistenceLayerException {
    SubClassCategory cat = SubClassCategory.getConstant("Wizard");
    SubClass sc = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
    primaryContext.getReferenceContext().reassociateCategory(cat, sc);
    sc = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Fireball");
    secondaryContext.getReferenceContext().reassociateCategory(cat, sc);
    runRoundRobin("Fireball");
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) Test(org.junit.Test)

Example 18 with SubClass

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

the class SubClassApplication method setSubClassKey.

public static void setSubClassKey(PlayerCharacter pc, PCClass cl, final String aKey) {
    if (aKey == null || cl == null) {
        return;
    }
    pc.setSubClassName(cl, aKey);
    if (!aKey.equals(cl.getKeyName())) {
        final SubClass a = cl.getSubClassKeyed(aKey);
        if (a != null) {
            cl.inheritAttributesFrom(a);
            pc.reInheritClassLevels(cl);
        }
    }
}
Also used : SubClass(pcgen.core.SubClass)

Example 19 with SubClass

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

the class FavClassConvertPlugin method process.

@Override
public String process(TokenProcessEvent tpe) {
    String value = tpe.getValue();
    if (!value.startsWith(Constants.LST_CHOOSE_COLON)) {
        // Don't consume, force the default processor to do the work...
        return null;
    }
    String choices = value.substring(7);
    if (isEmpty(choices) || hasIllegalSeparator('|', choices)) {
        return "Empty Token";
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(choices, Constants.PIPE);
    List<CDOMReference<? extends PCClass>> refList = new ArrayList<>();
    LoadContext context = tpe.getContext();
    while (tok.hasMoreTokens()) {
        CDOMReference<? extends PCClass> ref;
        String token = tok.nextToken();
        if (Constants.LST_ALL.equalsIgnoreCase(token) || Constants.LST_ANY.equalsIgnoreCase(token)) {
            foundAny = true;
            ref = context.getReferenceContext().getCDOMAllReference(PCCLASS_CLASS);
        } else {
            foundOther = true;
            int dotLoc = token.indexOf('.');
            if (dotLoc == -1) {
                // Primitive
                ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
            } else {
                // SubClass
                String parent = token.substring(0, dotLoc);
                String subclass = token.substring(dotLoc + 1);
                SubClassCategory scc = SubClassCategory.getConstant(parent);
                ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
            }
        }
        refList.add(ref);
    }
    if (foundAny && foundOther) {
        return "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value;
    }
    String name = tpe.getPrimary().get(StringKey.CONVERT_NAME);
    // TODO Need a method of guaranteeing this name is unique?
    String templName = "Race " + name + " Favored Class";
    tpe.append("TEMPLATE:");
    tpe.append(templName);
    PCTemplate templ = new PCTemplate();
    context.unconditionallyProcess(templ, "FAVOREDCLASS", "%LIST");
    StringBuilder chooseValue = new StringBuilder();
    chooseValue.append("CLASS|");
    boolean first = true;
    for (CDOMReference<? extends PCClass> ref : refList) {
        if (!first) {
            chooseValue.append(Constants.COMMA);
        }
        first = false;
        Class<? extends PCClass> refClass = ref.getReferenceClass();
        if (SUBCLASS_CLASS.equals(refClass)) {
            Category<SubClass> parent = ((CategorizedCDOMReference<SubClass>) ref).getCDOMCategory();
            chooseValue.append(parent);
            chooseValue.append('.');
        }
        chooseValue.append(ref.getLSTformat(false));
    }
    context.unconditionallyProcess(templ, "CHOOSE", chooseValue.toString());
    templ.setName(templName);
    tpe.inject(templ);
    tpe.consume();
    return null;
}
Also used : SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference) StringTokenizer(java.util.StringTokenizer) LoadContext(pcgen.rules.context.LoadContext) PCTemplate(pcgen.core.PCTemplate) CDOMReference(pcgen.cdom.base.CDOMReference) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference)

Example 20 with SubClass

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

the class Gui2InfoFactory method getHTMLInfo.

/**
	 * @see pcgen.core.facade.InfoFactory#getHTMLInfo(pcgen.core.facade.ClassFacade, pcgen.core.facade.ClassFacade)
	 */
@Override
public String getHTMLInfo(ClassFacade classFacade, ClassFacade parentClassFacade) {
    if (!(classFacade instanceof PCClass)) {
        return EMPTY_STRING;
    }
    PCClass aClass = (PCClass) classFacade;
    PCClass parentClass = aClass;
    String aString;
    boolean isSubClass = aClass instanceof SubClass;
    if (isSubClass && parentClassFacade != null) {
        parentClass = (PCClass) parentClassFacade;
    }
    final HtmlInfoBuilder b = new HtmlInfoBuilder(OutputNameFormatting.piString(aClass, false));
    b.appendLineBreak();
    // Subclass cost - at the top to make choices easier
    if (isSubClass && aClass.getSafe(IntegerKey.COST) != 0) {
        //$NON-NLS-1$
        b.appendI18nElement("in_clInfoCost", String.valueOf(aClass.getSafe(IntegerKey.COST)));
        b.appendLineBreak();
    }
    // Type
    aString = aClass.getType();
    if (isSubClass && (aString.isEmpty())) {
        aString = parentClass.getType();
    }
    //$NON-NLS-1$
    b.appendI18nElement("in_clInfoType", aString);
    // Hit Die
    HitDie hitDie = aClass.getSafe(ObjectKey.LEVEL_HITDIE);
    if (isSubClass && HitDie.ZERO.equals(hitDie)) {
        hitDie = parentClass.getSafe(ObjectKey.LEVEL_HITDIE);
    }
    if (!HitDie.ZERO.equals(hitDie)) {
        b.appendSpacer();
        //$NON-NLS-1$  //$NON-NLS-2$
        b.appendI18nElement("in_clInfoHD", "d" + hitDie.getDie());
    }
    appendFacts(b, aClass);
    if (SettingsHandler.getGame().getTabShown(Tab.SPELLS)) {
        FactKey<String> fk = FactKey.valueOf("SpellType");
        aString = aClass.getResolved(fk);
        if (isSubClass && aString == null) {
            aString = parentClass.getSpellType();
        }
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_clInfoSpellType", aString);
        aString = aClass.getSpellBaseStat();
        /*
			 * CONSIDER This test here is the ONLY place where the "magical"
			 * value of null is tested for in getSpellBaseStat(). This is
			 * currently set by SubClass and SubstititionClass, so it IS
			 * used, but the question is: Is there a better method for
			 * identifying this special deferral to the "parentClass" other
			 * than null SpellBaseStat? - thpr 11/9/06
			 */
        if (isSubClass && ((aString == null) || (aString.isEmpty()))) {
            aString = parentClass.getSpellBaseStat();
        }
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_clInfoBaseStat", aString);
    }
    // Prereqs
    aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, aClass.getPrerequisiteList(), false);
    if (isSubClass && (aString.isEmpty())) {
        aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, parentClass.getPrerequisiteList(), false);
    }
    if (!aString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_requirements", aString);
    }
    //Description
    String desc = pc.getDescription(aClass);
    if (!desc.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nFormattedElement(//$NON-NLS-1$
        "in_InfoDescription", DescriptionFormatting.piWrapDesc(aClass, desc, false));
    }
    // Sub class extra info
    if (isSubClass) {
        int specialtySpells = aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY);
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_clSpecialtySpells", Delta.toString(specialtySpells));
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_clSpecialty", ((SubClass) aClass).getChoice());
    }
    // Source
    aString = aClass.getSource();
    if (isSubClass && (aString.isEmpty())) {
        aString = parentClass.getSource();
    }
    if (!aString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_source", aString);
    }
    return b.toString();
}
Also used : SubClass(pcgen.core.SubClass) HitDie(pcgen.cdom.content.HitDie) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder) PCClass(pcgen.core.PCClass)

Aggregations

SubClass (pcgen.core.SubClass)21 SubClassCategory (pcgen.cdom.enumeration.SubClassCategory)11 Test (org.junit.Test)9 PCClass (pcgen.core.PCClass)8 ArrayList (java.util.ArrayList)3 ClassSkillList (pcgen.cdom.list.ClassSkillList)3 SubstitutionClass (pcgen.core.SubstitutionClass)3 StringTokenizer (java.util.StringTokenizer)2 SpellProhibitor (pcgen.core.SpellProhibitor)2 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 HitDie (pcgen.cdom.content.HitDie)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 ClassSpellList (pcgen.cdom.list.ClassSpellList)1 DomainSpellList (pcgen.cdom.list.DomainSpellList)1 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)1 Domain (pcgen.core.Domain)1 PCTemplate (pcgen.core.PCTemplate)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1