public boolean arePrerequisitesOK(Match match) { for (Prerequisite<?> p : this.prerequisites) { if (!p.isSatisfied(match)) { return false; } } return true; }
/** Ensure that a character with no templates correctly passes !PRETEMPLATE */ public void test990007_2() { final PlayerCharacter character = getCharacter(); final Prerequisite prereq = new Prerequisite(); prereq.setKind("template"); prereq.setKey("half-dragon"); prereq.setOperator(PrerequisiteOperator.LT); prereq.setOperand("1"); final boolean passes = PrereqHandler.passes(prereq, character, null); assertTrue(passes); }
/** Ensure a test with a non integer operand fails with a meaningfull error message */ public void testBadOperand() { final PlayerCharacter character = getCharacter(); final Prerequisite prereq = new Prerequisite(); prereq.setKind("template"); prereq.setKey("half%"); prereq.setOperator(PrerequisiteOperator.GTEQ); prereq.setOperand("One"); final boolean passes = PrereqHandler.passes(prereq, character, null); assertFalse(passes); }
/* (non-Javadoc) * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.prereq.Prerequisite, pcgen.core.Equipment) */ @Override public int passes(final Prerequisite prereq, final Equipment equipment, PlayerCharacter aPC) throws PrerequisiteException { int runningTotal = 0; final int targetNumber = Integer.parseInt(prereq.getOperand()); for (Prerequisite element : prereq.getPrerequisites()) { final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance(); final PrerequisiteTest test = factory.getTest(element.getKind()); runningTotal += test.passes(element, equipment, aPC); } runningTotal = prereq.getOperator().compare(runningTotal, targetNumber); return countedTotal(prereq, runningTotal); }
/** * Ensure that a character with templates, but not the required template correctly passes * !PRETEMPLATE */ public void test990007_3() { final PlayerCharacter character = getCharacter(); final PCTemplate template = new PCTemplate(); template.setName("Half-Celestial"); Globals.getContext().getReferenceContext().importObject(template); character.addTemplate(template); final Prerequisite prereq = new Prerequisite(); prereq.setKind("template"); prereq.setKey("half-dragon"); prereq.setOperator(PrerequisiteOperator.LT); prereq.setOperand("1"); final boolean passes = PrereqHandler.passes(prereq, character, null); assertTrue(passes); }
/* (non-Javadoc) * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter) */ @Override public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException { int runningTotal = 0; final int targetNumber = Integer.parseInt(prereq.getOperand()); for (Prerequisite element : prereq.getPrerequisites()) { final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance(); final PrerequisiteTest test = factory.getTest(element.getKind()); if (test != null) { runningTotal += test.passes(element, character, source); } else { Logging.errorPrintLocalised( "PreMult.cannot_find_subtest", element.getKind()); // $NON-NLS-1$ } } runningTotal = prereq.getOperator().compare(runningTotal, targetNumber); return countedTotal(prereq, runningTotal); }
/* (non-Javadoc) * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite) */ @Override public String toHtmlString(final Prerequisite prereq) { final PrerequisiteTestFactory factory = PrerequisiteTestFactory.getInstance(); StringBuilder str = new StringBuilder(250); String delimiter = ""; // $NON-NLS-1$ for (Prerequisite element : prereq.getPrerequisites()) { final PrerequisiteTest test = factory.getTest(element.getKind()); if (test == null) { Logging.errorPrintLocalised( "PreMult.cannot_find_subformatter", element.getKind()); // $NON-NLS-1$ } else { str.append(delimiter); if (test instanceof PreMult && !delimiter.equals("")) { str.append("##BR##"); } str.append(test.toHtmlString(element)); delimiter = LanguageBundle.getString("PreMult.html_delimiter"); // $NON-NLS-1$ } } // Handle some special cases - all required, one required or none required int numRequired = -1; if (StringUtils.isNumeric(prereq.getOperand())) { numRequired = Integer.parseInt(prereq.getOperand()); } if ((prereq.getOperator() == PrerequisiteOperator.GTEQ || prereq.getOperator() == PrerequisiteOperator.GT || prereq.getOperator() == PrerequisiteOperator.EQ) && numRequired == prereq.getPrerequisites().size()) { return LanguageBundle.getFormattedString( "PreMult.toHtmlAllOf", //$NON-NLS-1$ str.toString()); } if ((prereq.getOperator() == PrerequisiteOperator.GTEQ || prereq.getOperator() == PrerequisiteOperator.EQ) && numRequired == 1) { return LanguageBundle.getFormattedString( "PreMult.toHtmlEither", //$NON-NLS-1$ str.toString()); } if ((prereq.getOperator() == PrerequisiteOperator.LT && numRequired == 1) || ((prereq.getOperator() == PrerequisiteOperator.EQ || prereq.getOperator() == PrerequisiteOperator.LTEQ) && numRequired == 0)) { return LanguageBundle.getFormattedString( "PreMult.toHtmlNone", //$NON-NLS-1$ str.toString()); } return LanguageBundle.getFormattedString( "PreMult.toHtml", //$NON-NLS-1$ prereq.getOperator().toDisplayString(), prereq.getOperand(), str.toString()); }