Search in sources :

Example 1 with SubstitutionClass

use of pcgen.core.SubstitutionClass 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 2 with SubstitutionClass

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

the class ClassLoader method process.

@Override
public List<CDOMObject> process(StringBuilder sb, int line, String lineString, ConversionDecider decider) throws PersistenceLayerException, InterruptedException {
    List<CDOMObject> list = new ArrayList<>();
    String[] tokens = lineString.split(FIELD_SEPARATOR);
    if (tokens.length == 0) {
        return list;
    }
    String firstToken = tokens[0];
    sb.append(firstToken);
    Class<? extends CDOMObject> buildClass;
    Class<? extends CDOMObject> buildParent = null;
    if (firstToken.startsWith("SUBCLASS:")) {
        buildClass = SubClass.class;
    } else if (firstToken.startsWith("SUBCLASSLEVEL:")) {
        buildClass = PCClassLevel.class;
        buildParent = SubClass.class;
    } else if (firstToken.startsWith("SUBSTITUTIONCLASS:")) {
        buildClass = SubstitutionClass.class;
    } else if (firstToken.startsWith("SUBSTITUTIONLEVEL:")) {
        buildClass = PCClassLevel.class;
        buildParent = SubstitutionClass.class;
    } else if (firstToken.startsWith("CLASS:")) {
        buildClass = PCClass.class;
    } else {
        buildClass = PCClassLevel.class;
        buildParent = PCClass.class;
    }
    for (int tok = 1; tok < tokens.length; tok++) {
        String token = tokens[tok];
        sb.append(FIELD_SEPARATOR);
        if (token.isEmpty()) {
            continue;
        }
        CDOMObject obj = context.getReferenceContext().constructCDOMObject(buildClass, line + "Test" + tok);
        CDOMObject parent = null;
        if (obj instanceof PCClassLevel) {
            obj.put(IntegerKey.LEVEL, 1);
            parent = context.getReferenceContext().constructCDOMObject(buildParent, line + "Test" + tok);
            try {
                // Ensure processing against the PCClassLevel cannot cause side effects on the parent class
                obj.put(ObjectKey.TOKEN_PARENT, parent.clone());
            } catch (CloneNotSupportedException e) {
                Logging.errorPrint("Unable to preare a copy of " + parent);
            }
        }
        List<CDOMObject> injected = processToken(sb, firstToken, obj, parent, token, decider, line);
        if (injected != null) {
            list.addAll(injected);
        }
        context.purge(obj);
        if (parent != null) {
            context.purge(parent);
        }
        TokenConverter.clearConstants();
    }
    return list;
}
Also used : SubClass(pcgen.core.SubClass) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) PCClassLevel(pcgen.cdom.inst.PCClassLevel) SubstitutionClass(pcgen.core.SubstitutionClass)

Example 3 with SubstitutionClass

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

the class PCClassLoader method loadSubLines.

public void loadSubLines(LoadContext context) {
    Collection<PCClass> allClasses = context.getReferenceContext().getConstructedCDOMObjects(PCClass.class);
    for (PCClass cl : allClasses) {
        List<SubClass> subClasses = cl.getListFor(ListKey.SUB_CLASS);
        if (subClasses != null) {
            for (SubClass sc : subClasses) {
                sc.copyLevelsFrom(cl);
                processSubLevelLines(context, cl, sc);
            }
        }
        List<SubstitutionClass> substClasses = cl.getListFor(ListKey.SUBSTITUTION_CLASS);
        if (substClasses != null) {
            for (SubstitutionClass sc : substClasses) {
                processSubLevelLines(context, cl, sc);
            }
        }
    }
}
Also used : SubClass(pcgen.core.SubClass) PCClass(pcgen.core.PCClass) SubstitutionClass(pcgen.core.SubstitutionClass)

Example 4 with SubstitutionClass

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

the class SubstitutionClassApplication method buildSubstitutionClassChoiceList.

/**
	 * Build a list of Substitution Classes for the user to choose from. The
	 * list passed in will be populated.
	 * 
	 * @param choiceNames
	 *            The list of substitution classes to choose from.
	 * @param level
	 *            The class level to determine the choices for
	 * @param aPC
	 */
private static void buildSubstitutionClassChoiceList(PCClass cl, final List<PCClass> choiceList, final int level, final PlayerCharacter aPC) {
    for (SubstitutionClass sc : cl.getListFor(ListKey.SUBSTITUTION_CLASS)) {
        if (!PrereqHandler.passesAll(sc.getPrerequisiteList(), aPC, cl)) {
            continue;
        }
        if (!sc.hasOriginalClassLevel(level)) {
            continue;
        }
        if (!SubstitutionLevelSupport.qualifiesForSubstitutionLevel(cl, sc, aPC, level)) {
            continue;
        }
        choiceList.add(sc);
    }
    // sort the SubstitutionClass's
    Collections.sort(choiceList);
    // THEN add the base class as the first choice
    choiceList.add(0, cl);
}
Also used : SubstitutionClass(pcgen.core.SubstitutionClass)

Example 5 with SubstitutionClass

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

the class SubstitutionClassApplication method checkForSubstitutionClass.

public static void checkForSubstitutionClass(PCClass cl, final int aLevel, final PlayerCharacter aPC) {
    List<SubstitutionClass> substitutionClassList = cl.getListFor(ListKey.SUBSTITUTION_CLASS);
    if (substitutionClassList == null || substitutionClassList.isEmpty()) {
        return;
    }
    List<PCClass> choiceList = new ArrayList<>();
    buildSubstitutionClassChoiceList(cl, choiceList, aPC.getLevel(cl), aPC);
    if (choiceList.size() <= 1) {
        // This means the there are no classes for which
        return;
    // the pc meets the prerequisitions and thus the
    // base class is chosen.
    }
    CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
    LanguageBundle.getString("in_SubstLvlChoice"), //$NON-NLS-1$
    choiceList, new ArrayList<>(), 1);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
    ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
    List<PCClass> selectedList = chooserFacade.getFinalSelected();
    PCClass selected = null;
    if (!selectedList.isEmpty()) {
        selected = selectedList.get(0);
    }
    if ((!selectedList.isEmpty()) && selected instanceof SubstitutionClass) {
        SubstitutionClass sc = (SubstitutionClass) selected;
        SubstitutionLevelSupport.applyLevelArrayModsToLevel(sc, cl, aLevel, aPC);
        aPC.setSubstitutionClassName(aPC.getActiveClassLevel(cl, aLevel), sc.getKeyName());
        return;
    } else {
        /*
			 * the original code has the below line.. however, it appears to not
			 * be needed. I say this because if the original
			 * buildSubstitutionClassChoiceList method returned an empty list,
			 * it returned right away without calling this method.
			 */
        aPC.removeSubstitutionClassName(aPC.getActiveClassLevel(cl, aLevel));
        return;
    }
}
Also used : Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SubstitutionClass(pcgen.core.SubstitutionClass)

Aggregations

SubstitutionClass (pcgen.core.SubstitutionClass)6 PCClass (pcgen.core.PCClass)3 SubClass (pcgen.core.SubClass)3 ArrayList (java.util.ArrayList)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 PCStat (pcgen.core.PCStat)1 SpecialAbility (pcgen.core.SpecialAbility)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1 Gui2InfoFactory (pcgen.gui2.facade.Gui2InfoFactory)1 DeferredLine (pcgen.persistence.lst.utils.DeferredLine)1