Search in sources :

Example 1 with AgeSet

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

the class BioSetLoader method parseLine.

/**
	 * @see pcgen.persistence.lst.LstLineFileLoader#parseLine(LoadContext, String, URI)
	 */
@Override
public void parseLine(LoadContext context, String lstLine, URI sourceURI) {
    if (lstLine.startsWith("AGESET:")) {
        String line = lstLine.substring(7);
        int pipeLoc = line.indexOf('|');
        if (pipeLoc == -1) {
            Logging.errorPrint("Found invalid AGESET " + "in Bio Settings " + sourceURI + ", was expecting a |: " + lstLine);
            return;
        }
        String ageIndexString = line.substring(0, pipeLoc);
        try {
            currentAgeSetIndex = Integer.parseInt(ageIndexString);
            StringTokenizer colToken = new StringTokenizer(line.substring(pipeLoc + 1), SystemLoader.TAB_DELIM);
            AgeSet ageSet = new AgeSet(colToken.nextToken().intern(), currentAgeSetIndex);
            while (colToken.hasMoreTokens()) {
                parseTokens(context, ageSet, colToken);
            }
            ageSet = bioSet.addToAgeMap(regionName, ageSet, sourceURI);
            Integer oldIndex = bioSet.addToNameMap(ageSet);
            if (oldIndex != null && oldIndex != currentAgeSetIndex) {
                Logging.errorPrint("Incompatible Index for AGESET " + "in Bio Settings " + sourceURI + ": " + oldIndex + " and " + currentAgeSetIndex + " for " + ageSet.getName());
            }
        } catch (NumberFormatException e) {
            Logging.errorPrint("Illegal Index for AGESET " + "in Bio Settings " + sourceURI + ": " + ageIndexString + " was not an integer");
        }
    } else {
        final StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
        String colString;
        String raceName = "";
        List<String> preReqList = null;
        while (colToken.hasMoreTokens()) {
            colString = colToken.nextToken();
            if (colString.startsWith("RACENAME:")) {
                raceName = colString.substring(9);
            } else if (colString.startsWith("REGION:")) {
                regionName = colString.substring(7).intern();
            } else if (PreParserFactory.isPreReqString(colString)) {
                if (preReqList == null) {
                    preReqList = new ArrayList<>();
                }
                preReqList.add(colString);
            } else {
                String aString = colString;
                if (preReqList != null) {
                    final StringBuilder sBuf = new StringBuilder(100 + colString.length());
                    sBuf.append(colString);
                    for (String aPreReqList : preReqList) {
                        sBuf.append('[').append(aPreReqList).append(']');
                    }
                    aString = sBuf.toString();
                }
                bioSet.addToUserMap(regionName, raceName.intern(), aString.intern(), currentAgeSetIndex);
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) AgeSet(pcgen.core.AgeSet)

Example 2 with AgeSet

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

the class AgeSetFacet method update.

/**
	 * This method simply drives a global update of the active AgeSet of a
	 * PlayerCharacter. This is asserted to be simpler to comprehend than
	 * attempting to do a change-by-change matrix of possible moves between
	 * AgeSets (which would have to be built from the BioSet).
	 * 
	 * Since the processing to determine the AgeSet is reasonably simple, since
	 * this facet will only throw an event if the AgeSet actually changes, and
	 * since there are a disparate set of objects that can cause a change in the
	 * AgeSet (e.g. change of Race, change of Age, change of Region), the
	 * quantity of extra facets to listen to those changes in a unique fashion
	 * and the complex storage of AgeSets would seem an unreasonable trade in
	 * complexity vs. this global update.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            active AgeSet should be established (and updated if necessary)
	 */
private void update(CharID id) {
    Region region = Region.getConstant(regionFacet.getRegion(id));
    AgeSet ageSet = bioSetFacet.get(id).getAgeSet(region, getAgeSetIndex(id));
    if (ageSet == null) {
        remove(id);
    } else {
        set(id, ageSet);
    }
}
Also used : AgeSet(pcgen.core.AgeSet) Region(pcgen.cdom.enumeration.Region)

Example 3 with AgeSet

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

the class AgeSetKitFacet method dataAdded.

/**
	 * Drives the selection of the AgeSet Kit for a Player Character when
	 * relevant changes (change to an AgeSet) are made to a Player Character.
	 * 
	 * Triggered when one of the Facets to which AgeSetKitFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, Integer> dfce) {
    CharID id = dfce.getCharID();
    AgeSet ageSet = ageSetFacet.get(id);
    PlayerCharacter pc = trackingFacet.getPC(id);
    // TODO Is ageSet null check necessary?
    if (ageSet == null || pc.isImporting()) {
        return;
    }
    int ageSetIndex = ageSetFacet.getAgeSetIndex(id);
    /*
		 * TODO The method of storing what AgeSets have had kit selections made
		 * should be converted to store the actual AgeSet rather than the index,
		 * in order to reduce the number of calls to ageSetFacet.getAgeSetIndex.
		 * This (of course) drives the move of the AgeSets for which a kit
		 * selection has been made into a Facet. It is possible that the
		 * CacheInfo of AgeSetKitFacet is actually a good place to store that
		 * information (or it may be implicit with the information already
		 * stored there??)
		 */
    if (!pc.hasMadeKitSelectionForAgeSet(ageSetIndex)) {
        CacheInfo cache = getConstructingClassInfo(id);
        List<Kit> kits = cache.get(ageSet);
        if (kits != null) {
            // Need to do selection
            BioSet bioSet = bioSetFacet.get(id);
            for (TransitionChoice<Kit> kit : ageSet.getKits()) {
                Collection<? extends Kit> choice = kit.driveChoice(pc);
                cache.put(ageSet, choice);
                kit.act(choice, bioSet, pc);
            }
        }
        pc.setHasMadeKitSelectionForAgeSet(ageSetIndex, true);
    }
}
Also used : BioSet(pcgen.core.BioSet) PlayerCharacter(pcgen.core.PlayerCharacter) AgeSet(pcgen.core.AgeSet) Kit(pcgen.core.Kit) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

AgeSet (pcgen.core.AgeSet)3 StringTokenizer (java.util.StringTokenizer)1 CharID (pcgen.cdom.enumeration.CharID)1 Region (pcgen.cdom.enumeration.Region)1 BioSet (pcgen.core.BioSet)1 Kit (pcgen.core.Kit)1 PlayerCharacter (pcgen.core.PlayerCharacter)1