@Override public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { if (prereq.getKind() != null) { return false; } String handled = kindHandled(); String count = prereq.getOperand(); try { int i = Integer.parseInt(count); if (prereq.getPrerequisiteCount() != i) { return false; } } catch (NumberFormatException e) { return false; } PrerequisiteOperator oper = null; for (Prerequisite p : prereq.getPrerequisites()) { // // ...with all PREARMORTYPE entries... // if (!handled.equalsIgnoreCase(p.getKind())) { return false; } // // ...and the same operator... // if (oper == null) { oper = p.getOperator(); } else { if (!oper.equals(p.getOperator())) { return false; } } } writer.write("PREVAR"); if (prereq.getOperator() == PrerequisiteOperator.LT) { writer.write(oper.invert().toString().toUpperCase()); } else { writer.write(oper.toString().toUpperCase()); } writer.write(':' + (prereq.isOverrideQualify() ? "Q:" : "")); boolean first = true; for (Prerequisite p : prereq.getPrerequisites()) { if (!first) { writer.write(','); } writer.write(p.getKey()); writer.write(','); writer.write(p.getOperand()); first = false; } return true; }
/** * Process prereq keys wrapped in []. If the key is wrapped in [], the prereq will be negated to * check that the prereq is not passed, and the number of required matches is increased by the * number of negated tests. Can handle nested prereqs. * * @param prereq The prereq to be negated. */ private void negateCampaignChoice(Prerequisite prereq) { int modified = 0; for (Prerequisite p : prereq.getPrerequisites()) { if (p.getKind() == null) // PREMULT { negateCampaignChoice(p); } else { String preKey = p.getKey(); if (preKey.startsWith("[") && preKey.endsWith("]")) { preKey = preKey.substring(1, preKey.length() - 1); p.setKey(preKey); p.setOperator(p.getOperator().invert()); ++modified; } } } if (modified > 0) { String oper = prereq.getOperand(); try { oper = Integer.toString(Integer.parseInt(oper) + modified); } catch (NumberFormatException nfe) { oper = "(" + oper + ")+" + Integer.toString(modified); } prereq.setOperand(oper); } }