Search in sources :

Example 1 with SubClass

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

the class SubClassApplication method checkForSubClass.

public static void checkForSubClass(PlayerCharacter aPC, PCClass cl) {
    List<SubClass> subClassList = cl.getListFor(ListKey.SUB_CLASS);
    if (subClassList == null || subClassList.isEmpty()) {
        return;
    }
    List<PCClass> availableList = new ArrayList<>();
    String subClassKey = aPC.getSubClassName(cl);
    boolean subClassSelected = subClassKey != null && !subClassKey.equals(Constants.NONE) && !subClassKey.equals("");
    for (SubClass sc : subClassList) {
        if (!PrereqHandler.passesAll(sc.getPrerequisiteList(), aPC, cl)) {
            continue;
        }
        // If a subclass has already been selected, only add that one
        if (!subClassSelected || sc.getKeyName().equals(aPC.getSubClassName(cl))) {
            availableList.add(sc);
        }
    }
    // add base class to the chooser
    if (cl.getSafe(ObjectKey.ALLOWBASECLASS) && (!subClassSelected || cl.getKeyName().equals(aPC.getSubClassName(cl)))) {
        availableList.add(0, cl);
    }
    /*
		 * REFACTOR This makes an assumption that SubClasses are ONLY Schools, which may
		 * not be a fabulous assumption
		 */
    List<PCClass> selectedSubClasses;
    CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
    LanguageBundle.getString("in_schoolSpecChoice"), //$NON-NLS-1$
    availableList, new ArrayList<>(), 1);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
    if (availableList.size() == 1) {
        selectedSubClasses = availableList;
    } else if (availableList.isEmpty()) {
        if (Logging.isLoggable(Logging.WARNING)) {
            Logging.log(Logging.WARNING, "No subclass choices avaialble for " + cl);
        }
        return;
    } else {
        ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
        selectedSubClasses = chooserFacade.getFinalSelected();
    }
    if (!cl.getSafe(ObjectKey.ALLOWBASECLASS)) {
        while (selectedSubClasses.isEmpty()) {
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
        }
    }
    if (selectedSubClasses.isEmpty()) {
        return;
    }
    PCClass subselected = selectedSubClasses.get(0);
    if (subselected instanceof SubClass) {
        aPC.removeProhibitedSchools(cl);
        /*
			 * CONSIDER What happens to this reset during PCClass/PCClassLevel split
			 */
        aPC.removeAssoc(cl, AssociationKey.SPECIALTY);
        SubClass sc = (SubClass) subselected;
        availableList.clear();
        for (SubClass sub : subClassList) {
            if (sub.equals(sc)) {
                //Skip the selected specialist school
                continue;
            }
            if (!PrereqHandler.passesAll(sub.getPrerequisiteList(), aPC, cl)) {
                continue;
            }
            int displayedCost = sub.getProhibitCost();
            if (displayedCost == 0) {
                continue;
            }
            availableList.add(sub);
        }
        setSubClassKey(aPC, cl, sc.getKeyName());
        if (sc.get(ObjectKey.CHOICE) != null) {
            aPC.setAssoc(cl, AssociationKey.SPECIALTY, sc.getChoice());
        }
        if (sc.getSafe(IntegerKey.COST) != 0) {
            chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
            LanguageBundle.getString("in_schoolProhibitChoice"), availableList, new ArrayList<>(), sc.getSafe(IntegerKey.COST));
            chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
            chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
            chooserFacade.setRequireCompleteSelection(true);
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
            for (PCClass choice : chooserFacade.getFinalSelected()) {
                sc = (SubClass) choice;
                SpellProhibitor prohibSchool = new SpellProhibitor();
                prohibSchool.setType(ProhibitedSpellType.SCHOOL);
                prohibSchool.addValue(sc.getChoice());
                SpellProhibitor prohibSubSchool = new SpellProhibitor();
                prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
                prohibSubSchool.addValue(sc.getChoice());
                aPC.addProhibitedSchool(prohibSchool, cl);
                aPC.addProhibitedSchool(prohibSubSchool, cl);
            }
        }
    }
}
Also used : SubClass(pcgen.core.SubClass) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory)

Example 2 with SubClass

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

the class PCGVer2Parser method parseClassLine.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void parseClassLine(final String line) throws PCGParseException {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        /*
			 * Classes are critical for characters,
			 * need to stop the load process
			 *
			 * Thomas Behr 14-08-02
			 */
        throw new PCGParseException("parseClassLine", line, //$NON-NLS-1$
        pcgpex.getMessage());
    }
    PCClass aPCClass = null;
    String tag;
    PCGElement element;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the class key name!!!
    if (it.hasNext()) {
        element = it.next();
        String classKey = EntityEncoder.decode(element.getText());
        // First check for an existing class, say from a racial casting ability
        aPCClass = thePC.getClassKeyed(classKey);
        if (aPCClass == null) {
            aPCClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
            if (aPCClass != null) {
                // Icky: Need to redesign the way classes work!
                // Icky: Having to clone the class here is UGLY!
                aPCClass = aPCClass.clone();
            } else {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.CouldntAddClass", element.getText());
                warnings.add(msg);
                return;
            }
        }
    }
    int level = -1;
    int skillPool = -1;
    String subClassKey = Constants.NONE;
    while (it.hasNext()) {
        element = it.next();
        tag = element.getName();
        if (IOConstants.TAG_SUBCLASS.equals(tag)) {
            subClassKey = EntityEncoder.decode(element.getText());
            if ((!subClassKey.isEmpty()) && !subClassKey.equals(Constants.NONE)) {
                SubClass sc = aPCClass.getSubClassKeyed(subClassKey);
                if (sc == null) {
                    if (subClassKey.equals(aPCClass.getKeyName())) {
                        subClassKey = Constants.NONE;
                    } else {
                        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                        "Warnings.PCGenParser.InvalidSubclass", element.getText());
                        warnings.add(msg);
                    }
                }
            }
        }
        if (IOConstants.TAG_LEVEL.equals(tag)) {
            try {
                level = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.InvalidLevel", element.getText());
                warnings.add(msg);
            }
        } else if (IOConstants.TAG_SKILLPOOL.equals(tag)) {
            try {
                skillPool = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.InvalidSkillPool", element.getText());
                warnings.add(msg);
            }
        } else if (IOConstants.TAG_CANCASTPERDAY.equals(tag)) {
        // TODO
        } else if (IOConstants.TAG_SPELLBASE.equals(tag)) {
            final String spellBase = EntityEncoder.decode(element.getText());
            if (!Constants.NONE.equals(spellBase)) {
                Globals.getContext().unconditionallyProcess(aPCClass, "SPELLSTAT", spellBase);
            }
        } else if (IOConstants.TAG_PROHIBITED.equals(tag)) {
            String prohib = EntityEncoder.decode(element.getText());
            StringTokenizer st = new StringTokenizer(prohib, Constants.COMMA);
            while (st.hasMoreTokens()) {
                String choice = st.nextToken();
                if (!"None".equalsIgnoreCase(choice)) {
                    SpellProhibitor prohibSchool = new SpellProhibitor();
                    prohibSchool.setType(ProhibitedSpellType.SCHOOL);
                    prohibSchool.addValue(choice);
                    SpellProhibitor prohibSubSchool = new SpellProhibitor();
                    prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
                    prohibSubSchool.addValue(choice);
                    thePC.addProhibitedSchool(prohibSchool, aPCClass);
                    thePC.addProhibitedSchool(prohibSubSchool, aPCClass);
                }
            }
        }
    }
    if (level > -1) {
        thePC.addClass(aPCClass);
        if (StringUtils.isNotBlank(subClassKey) && !subClassKey.equals(Constants.NONE)) {
            SubClassApplication.setSubClassKey(thePC, aPCClass, subClassKey);
        }
        for (int i = 0; i < level; ++i) {
            PCLevelInfo levelInfo = thePC.addLevelInfo(aPCClass.getKeyName());
            aPCClass.addLevel(false, false, thePC, true);
        }
    }
    //Must process ADD after CLASS is added to the PC
    for (PCGElement e : new PCGTokenizer(line).getElements()) {
        tag = e.getName();
        if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
            parseAddTokenInfo(e, aPCClass);
        }
    }
    if (skillPool > -1) {
        thePC.setSkillPool(aPCClass, skillPool);
    }
}
Also used : SubClass(pcgen.core.SubClass) StringTokenizer(java.util.StringTokenizer) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 3 with SubClass

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

the class SubClassCategory method newInstance.

@Override
public SubClass newInstance() {
    SubClass sc = new SubClass();
    sc.setCDOMCategory(this);
    return sc;
}
Also used : SubClass(pcgen.core.SubClass)

Example 4 with SubClass

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

the class PCClassLoader method parseLine.

/**
	 * @see pcgen.persistence.lst.LstObjectFileLoader#parseLine(LoadContext, pcgen.cdom.base.CDOMObject, String, SourceEntry)
	 */
@Override
public PCClass parseLine(LoadContext context, PCClass target, String lstLine, SourceEntry source) throws PersistenceLayerException {
    if (lstLine.startsWith("SUBCLASS:") || lstLine.startsWith("SUBCLASSLEVEL:")) {
        if (target == null) {
            Logging.errorPrint("Ignoring line: " + lstLine + " as SUBCLASS* type line appeared before CLASS: line");
            return null;
        }
        SubClass subClass = null;
        if (lstLine.startsWith("SUBCLASS:")) {
            int tabLoc = lstLine.indexOf("\t");
            if (tabLoc == -1) {
                Logging.errorPrint("Expected SUBCLASS to have " + "additional Tags in " + source.getURI() + " (e.g. COST is a required Tag in a SUBCLASS)");
            }
            final String n = lstLine.substring(9, tabLoc);
            String restOfLine = lstLine.substring(tabLoc);
            subClass = target.getSubClassKeyed(n);
            if (subClass == null) {
                subClass = new SubClass();
                subClass.setName(n.intern());
                subClass.put(ObjectKey.SOURCE_CAMPAIGN, source.getCampaign());
                subClass.setSourceURI(source.getURI());
                target.addSubClass(subClass);
            }
            parseLineIntoClass(context, subClass, source, restOfLine);
        } else {
            List<SubClass> subClassList = target.getListFor(ListKey.SUB_CLASS);
            if (subClassList != null) {
                subClass = subClassList.get(subClassList.size() - 1);
                subClass.addToListFor(ListKey.SUB_CLASS_LEVEL, new DeferredLine(source, lstLine.substring(14).intern()));
            }
        }
        return target;
    }
    if (lstLine.startsWith("SUBSTITUTIONCLASS:") || lstLine.startsWith("SUBSTITUTIONLEVEL:")) {
        if (target == null) {
            Logging.errorPrint("Ignoring line: " + lstLine + " as SUBSTITUTIONCLASS* type line appeared before CLASS: line");
            return null;
        }
        SubstitutionClass substitutionClass = null;
        if (lstLine.startsWith("SUBSTITUTIONCLASS:")) {
            int tabLoc = lstLine.indexOf("\t");
            String name;
            String restOfLine;
            if (tabLoc > 0) {
                name = lstLine.substring(18, tabLoc);
                restOfLine = lstLine.substring(tabLoc);
            } else {
                name = lstLine.substring(18);
                restOfLine = null;
            }
            substitutionClass = target.getSubstitutionClassKeyed(name);
            if (substitutionClass == null) {
                substitutionClass = new SubstitutionClass();
                substitutionClass.setName(name.intern());
                substitutionClass.put(ObjectKey.SOURCE_CAMPAIGN, source.getCampaign());
                substitutionClass.setSourceURI(source.getURI());
                target.addSubstitutionClass(substitutionClass);
            }
            parseLineIntoClass(context, substitutionClass, source, restOfLine);
        } else {
            if (lstLine.indexOf('\t') == -1) {
                Logging.errorPrint("Ignoring line: " + lstLine + " as SUBSTITUTIONLEVEL line was empty");
                return null;
            }
            List<SubstitutionClass> substitutionClassList = target.getListFor(ListKey.SUBSTITUTION_CLASS);
            if (substitutionClassList != null && !substitutionClassList.isEmpty() && lstLine.length() > 18) {
                substitutionClass = substitutionClassList.get(substitutionClassList.size() - 1);
                substitutionClass.addToListFor(ListKey.SUB_CLASS_LEVEL, new DeferredLine(source, lstLine.substring(18).intern()));
            }
        }
        return target;
    }
    return parseClassLine(context, lstLine, source, target);
}
Also used : SubClass(pcgen.core.SubClass) DeferredLine(pcgen.persistence.lst.utils.DeferredLine) SubstitutionClass(pcgen.core.SubstitutionClass)

Example 5 with SubClass

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

the class ClassSkillListFacet method dataAdded.

@Override
public void dataAdded(ScopeFacetChangeEvent<CharID, PCClass, String> dfce) {
    PCClass cl = dfce.getScope();
    String subClassKey = dfce.getCDOMObject();
    SubClass subclass = cl.getSubClassKeyed(subClassKey);
    if (subclass != null) {
        ClassSkillList scl = subclass.get(ObjectKey.CLASS_SKILLLIST);
        defaultClassSkillListFacet.add(dfce.getCharID(), cl, scl, subclass);
    }
}
Also used : SubClass(pcgen.core.SubClass) PCClass(pcgen.core.PCClass) ClassSkillList(pcgen.cdom.list.ClassSkillList)

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