use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class DomainToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel pcl, String value) {
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
String tok = pipeTok.nextToken();
if (looksLikeAPrerequisite(tok)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
}
List<QualifiedObject<CDOMSingleRef<Domain>>> toAdd = new ArrayList<>();
boolean foundClear = false;
while (true) {
if (Constants.LST_DOT_CLEAR.equals(tok)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(pcl, ListKey.DOMAIN);
foundClear = true;
} else {
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tok);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
toAdd.add(qo);
context.getObjectContext().addToList(pcl, ListKey.DOMAIN, qo);
}
first = false;
if (!pipeTok.hasMoreTokens()) {
// No prereqs, so we're done
return ParseResult.SUCCESS;
}
tok = pipeTok.nextToken();
if (looksLikeAPrerequisite(tok)) {
break;
}
}
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
}
while (true) {
Prerequisite prereq = getPrerequisite(tok);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (PrereqObject pro : toAdd) {
pro.addPrerequisite(prereq);
}
if (!pipeTok.hasMoreTokens()) {
break;
}
tok = pipeTok.nextToken();
}
return ParseResult.SUCCESS;
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class VisionFacet method getActiveVision.
/**
* Returns a Vision object for the given VisionType for the Player Character
* identified by the given CharID.
*
* For a Player Character that is not changed between calls to this method,
* this method does not guarantee returning a Vision object of the same
* identity for the same given VisionType. While the two Vision objects will
* pass object equality (.equals()), they are not guaranteed to pass (or
* guaranteed to fail) instance identity (a == b). This allows VisionFacet
* to reserve the right to cache results, but does not require it.
*
* @param id
* The CharID identifying the Player Character for which the
* Vision of the given VisionType is to be returned
* @param type
* The VisionType for which the Vision is to be returned
* @return A Vision object for the given VisionType for the Player Character
* identified by the given CharID.
*/
public Vision getActiveVision(CharID id, VisionType type) {
Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
if (componentMap == null) {
return null;
}
Integer i = null;
for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
QualifiedObject<Vision> qo = me.getKey();
Vision v = qo.getRawObject();
VisionType visType = v.getType();
if (type.equals(visType)) {
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, qo, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
Formula distance = v.getDistance();
int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
if (i == null || i < a) {
i = a;
}
}
}
}
}
/*
* parse through the global list of vision tags and see if this PC has
* any BONUS:VISION tags which will create a new visionMap entry, and
* add any BONUS to existing entries in the map
*/
int a = (int) bonusCheckingFacet.getBonus(id, "VISION", type.toString());
if (a > 0) {
if (i == null || i < a) {
i = a;
}
}
if (i == null) {
return null;
}
return new Vision(type, FormulaFactory.getFormulaFor(i));
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class WieldCategoryLoader method parseLine.
/**
* Parse the WIELDCATEGORY line
*
* @param gameMode
* @param lstLine
* @throws PersistenceLayerException
*/
public void parseLine(GameMode gameMode, String lstLine, URI source) throws PersistenceLayerException {
LoadContext context = gameMode.getModeContext();
StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
WieldCategory cat = null;
String preKey = null;
CDOMSingleRef<WieldCategory> preVal = null;
while (colToken.hasMoreTokens()) {
final String colString = colToken.nextToken().trim();
final int idxColon = colString.indexOf(':');
String key = "";
try {
key = colString.substring(0, idxColon);
} catch (StringIndexOutOfBoundsException e) {
// TODO Deal with Exception
}
if (key.equals("WIELDCATEGORY")) {
final String value = colString.substring(idxColon + 1).trim();
cat = context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, value);
if (cat == null) {
cat = new WieldCategory();
cat.setName(value.intern());
gameMode.addWieldCategory(cat);
}
} else if (colString.startsWith("PREVAR")) {
//TODO ensure preKey is null
// a PREVARxx formula used to switch
// weapon categories based on size
preKey = colString;
} else if (key.equals("SWITCH")) {
//TODO ensure preVal is null
// If matches PRE, switch category to this
preVal = context.getReferenceContext().getCDOMReference(WieldCategory.class, colString.substring(7));
} else {
final String value = colString.substring(idxColon + 1).trim();
if (context.processToken(cat, key, value)) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
}
Logging.clearParseMessages();
}
}
//TODO Error checking if preVal w/o preKey, vice versa, etc.
if ((cat != null) && (preVal != null) && (preKey != null)) {
try {
QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(preVal);
qo.addPrerequisite(prereqParser.parse(preKey));
cat.addCategorySwitch(qo);
} catch (PersistenceLayerException ple) {
Logging.errorPrint("Error parsing Prerequisite in " + source + ": " + preKey + "\n " + ple.getMessage());
}
}
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class ClassDomainBracketToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
Logging.deprecationPrint(getMessage(pcc, value));
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
while (pipeTok.hasMoreTokens()) {
String tok = pipeTok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tok)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(pcc, ListKey.DOMAIN);
continue;
}
// Note: May contain PRExxx
String domainKey;
Prerequisite prereq = null;
int openBracketLoc = tok.indexOf('[');
if (openBracketLoc == -1) {
if (tok.indexOf(']') != -1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must have '[' if it contains a PREREQ tag", context);
}
domainKey = tok;
} else {
if (tok.lastIndexOf(']') != tok.length() - 1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must end with ']' if it contains a PREREQ tag", context);
}
domainKey = tok.substring(0, openBracketLoc);
String prereqString = tok.substring(openBracketLoc + 1, tok.length() - 1);
if (prereqString.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " cannot have empty prerequisite : " + value, context);
}
prereq = getPrerequisite(prereqString);
if (prereq == null) {
return new ParseResult.Fail(getTokenName() + " had invalid prerequisite : " + prereqString, context);
}
}
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, domainKey);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
if (prereq != null) {
qo.addPrerequisite(prereq);
}
context.getObjectContext().addToList(pcc, ListKey.DOMAIN, qo);
first = false;
}
return ParseResult.SUCCESS;
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class AutoLanguageFacet method dataAdded.
/**
* Processes CDOMObjects added to a Player Character to extract Languages
* granted to the Player Character through the AUTO:LANG: and LANGAUTO:
* tokens. The extracted languages are added to the Player Character.
*
* Triggered when one of the Facets to which AutoLanguageFacet listens fires
* a DataFacetChangeEvent to indicate a CDOMObjectwas 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, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
CharID id = dfce.getCharID();
// LANGAUTO
List<QualifiedObject<CDOMReference<Language>>> list = cdo.getSafeListFor(ListKey.AUTO_LANGUAGES);
if (list != null) {
separateAll(id, list, cdo);
}
// AUTO:LANG
list = cdo.getSafeListFor(ListKey.AUTO_LANGUAGE);
if (list != null) {
separateAll(id, list, cdo);
}
}
Aggregations