use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreVisionParser method validateNotZero.
private static boolean validateNotZero(Prerequisite prereq) {
boolean returnValue = true;
if (prereq.getKind() != null && prereq.getKind().equalsIgnoreCase("VISION")) {
if ("0".equals(prereq.getOperand())) {
Logging.deprecationPrint("Found PREVISION that is invalid (vision=0 is always true)");
Logging.deprecationPrint(" You should use =1 or =ANY");
returnValue &= false;
}
}
for (Prerequisite element : prereq.getPrerequisites()) {
returnValue &= validateNotZero(element);
}
return returnValue;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class DomainsToken method unparse.
@Override
public String[] unparse(LoadContext context, Deity deity) {
CDOMReference<DomainList> dl = Deity.DOMAINLIST;
AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), deity, dl);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
if (changes.includesGlobalClear()) {
if (removedItems != null && !removedItems.isEmpty()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR);
} else if (removedItems != null && !removedItems.isEmpty()) {
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, ",.CLEAR.", true));
}
MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl != null && !mtl.isEmpty()) {
MapToList<Set<Prerequisite>, CDOMReference<Domain>> m = new HashMapToList<>();
for (CDOMReference<Domain> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
m.addToListFor(new HashSet<>(assoc.getPrerequisiteList()), ab);
}
}
Set<String> set = new TreeSet<>();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
Set<CDOMReference<Domain>> domainSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
domainSet.addAll(m.getListFor(prereqs));
StringBuilder sb = new StringBuilder(ReferenceUtilities.joinLstFormat(domainSet, Constants.COMMA, true));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
set.add(sb.toString());
}
list.addAll(set);
}
if (list.isEmpty()) {
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class DomainsToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Deity deity, String value) {
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
StringTokenizer commaTok = new StringTokenizer(pipeTok.nextToken(), Constants.COMMA);
CDOMReference<DomainList> dl = Deity.DOMAINLIST;
ArrayList<AssociatedPrereqObject> proList = new ArrayList<>();
boolean first = true;
boolean foundAll = false;
boolean foundOther = false;
boolean foundClear = false;
while (commaTok.hasMoreTokens()) {
String tokString = commaTok.nextToken();
if (looksLikeAPrerequisite(tokString)) {
return new ParseResult.Fail("Invalid " + getTokenName() + ": PRExxx was comma delimited : " + value, context);
}
if (Constants.LST_DOT_CLEAR.equals(tokString)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context);
}
context.getListContext().removeAllFromList(getTokenName(), deity, dl);
foundClear = true;
} else if (tokString.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
CDOMReference<Domain> ref;
String clearText = tokString.substring(7);
if (Constants.LST_ALL.equals(clearText) || Constants.LST_ANY.equals(clearText)) {
ref = context.getReferenceContext().getCDOMAllReference(DOMAIN_CLASS);
} else {
ref = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, clearText);
}
context.getListContext().removeFromList(getTokenName(), deity, dl, ref);
foundClear = true;
} else if (Constants.LST_ALL.equals(tokString) || Constants.LST_ANY.equals(tokString)) {
CDOMGroupRef<Domain> ref = context.getReferenceContext().getCDOMAllReference(DOMAIN_CLASS);
proList.add(context.getListContext().addToList(getTokenName(), deity, dl, ref));
foundAll = true;
} else {
CDOMSingleRef<Domain> ref = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tokString);
proList.add(context.getListContext().addToList(getTokenName(), deity, dl, ref));
foundOther = true;
}
first = false;
}
if (foundAll && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ALL and a specific reference: " + value, context);
}
while (pipeTok.hasMoreTokens()) {
if (foundClear) {
return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR or .CLEAR. in " + getTokenName(), context);
}
String tokString = pipeTok.nextToken();
Prerequisite prereq = getPrerequisite(tokString);
if (prereq == null) {
return new ParseResult.Fail(" (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
}
for (AssociatedPrereqObject ao : proList) {
ao.addPrerequisite(prereq);
}
}
return ParseResult.SUCCESS;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class ClassLevelDomainBracketToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
Logging.deprecationPrint(getMessage(level, 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(level, 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(level, ListKey.DOMAIN, qo);
first = false;
}
return ParseResult.SUCCESS;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreEquipBothWriter method specialCase.
@Override
public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false);
if (po == null) {
return false;
}
if (!po.equals(prereq.getOperator())) {
writer.write('!');
}
writer.write("PRE" + kindHandled().toUpperCase() + ':' + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(po.equals(PrerequisiteOperator.GTEQ) ? prereq.getOperand() : "1");
for (Prerequisite p : prereq.getPrerequisites()) {
writer.write(',');
writer.write(p.getKey());
}
return true;
}
Aggregations