use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class MonskillToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass pcc, String value) {
BonusObj bon = Bonus.newBonus(context, "MONSKILLPTS|NUMBER|" + value);
if (bon == null) {
return new ParseResult.Fail(getTokenName() + " was given invalid bonus value: " + value, context);
}
Prerequisite prereq = getPrerequisite("PRELEVELMAX:1");
if (prereq == null) {
return new ParseResult.Fail("Internal Error: " + getTokenName() + " had invalid prerequisite", context);
}
bon.addPrerequisite(prereq);
bon.setTokenSource(getTokenName());
context.getObjectContext().addToList(pcc, ListKey.BONUS, bon);
return ParseResult.SUCCESS;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class ProhibitspellToken method subParse.
public SpellProhibitor subParse(String value) {
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
String token = tok.nextToken();
int dotLoc = token.indexOf(Constants.DOT);
if (dotLoc == -1) {
Logging.errorPrint(getTokenName() + " has no . separator for arguments: " + value);
return null;
}
String pstString = token.substring(0, dotLoc);
ProhibitedSpellType type;
try {
type = ProhibitedSpellType.valueOf(pstString);
} catch (IllegalArgumentException e) {
Logging.errorPrint(getTokenName() + " encountered an invalid Prohibited Spell Type: " + value);
Logging.errorPrint(" Legal values are: " + StringUtil.join(Arrays.asList(ProhibitedSpellType.values()), ", "));
return null;
}
SpellProhibitor spellProb = typeSafeParse(type, token.substring(dotLoc + 1));
if (spellProb == null) {
Logging.errorPrint(" entire token value was: " + value);
return null;
}
if (!tok.hasMoreTokens()) {
// No prereqs, so we're done
return spellProb;
}
token = tok.nextToken();
while (true) {
Prerequisite prereq = getPrerequisite(token);
if (prereq == null) {
Logging.errorPrint(" (Did you put more than one limit, or items after the " + "PRExxx tags in " + getTokenName() + ":?)");
return null;
}
spellProb.addPrerequisite(prereq);
if (!tok.hasMoreTokens()) {
break;
}
token = tok.nextToken();
}
return spellProb;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class DomainToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, 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(pcc, 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(pcc, 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.prereq.Prerequisite in project pcgen by PCGen.
the class AdddomainsToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), pcc, PCClass.ALLOWED_DOMAINS);
Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR");
return null;
}
MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl == null || mtl.isEmpty()) {
return null;
}
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
Set<String> set = new TreeSet<>();
Set<String> noPrereqSet = new TreeSet<>();
for (CDOMReference<Domain> domain : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
List<Prerequisite> prereqs = assoc.getPrerequisiteList();
if (prereqs == null || prereqs.isEmpty()) {
noPrereqSet.add(sb.toString());
continue;
}
for (Prerequisite prereq : prereqs) {
sb.append(Constants.PIPE);
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append(swriter.toString());
}
set.add(sb.toString());
}
}
if (!noPrereqSet.isEmpty()) {
set.add(StringUtil.join(noPrereqSet, Constants.PIPE));
}
return set.toArray(new String[set.size()]);
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class EquipBuyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Kit kit, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
if (looksLikeAPrerequisite(activeValue)) {
return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName(), context);
}
Formula f = FormulaFactory.getFormulaFor(activeValue);
if (!f.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString(), context);
}
List<Prerequisite> prereqs = new ArrayList<>();
while (sep.hasNext()) {
activeValue = sep.next();
Prerequisite prereq = getPrerequisite(activeValue);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
prereqs.add(prereq);
}
kit.put(ObjectKey.EQUIP_BUY, new QualifiedObject<>(f, prereqs));
return ParseResult.SUCCESS;
}
Aggregations