/* (non-Javadoc) * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter) */ @Override public int passes(final Prerequisite prereq, final PlayerCharacter aPC, CDOMObject source) throws PrerequisiteException { final int number; try { number = Integer.parseInt(prereq.getOperand()); } catch (NumberFormatException exceptn) { throw new PrerequisiteException( LanguageBundle.getFormattedString("PreFact.error", prereq.toString())); // $NON-NLS-1$ } String location = prereq.getCategoryName(); String[] locationElements = location.split("\\."); Iterable<Reducible> objModel = (Iterable<Reducible>) OutputDB.getIterable(aPC.getCharID(), locationElements); if (objModel == null) { throw new PrerequisiteException("Output System does not have model for: " + location); } String[] factinfo = prereq.getKey().split("="); FactKey<?> fk = FactKey.valueOf(factinfo[0]); Object targetVal = fk.getFormatManager().convertIndirect(factinfo[1]); int runningTotal = 0; for (Reducible r : objModel) { Indirect<?> cdoVal = r.getCDOMObject().get(fk); if (targetVal.equals(cdoVal)) { runningTotal++; } } runningTotal = prereq.getOperator().compare(runningTotal, number); return countedTotal(prereq, runningTotal); }
/** @throws Exception */ public void testFort3() throws Exception { PreCheckParser parser = new PreCheckParser(); Prerequisite prereq = parser.parse("CHECK", "1,Fortitude=3", false, false); assertEquals( "<prereq kind=\"check\" key=\"Fortitude\" operator=\"GTEQ\" operand=\"3\" >\n" + "</prereq>\n", prereq.toString()); }
/** @throws Exception */ public void testBaseWill7() throws Exception { PreCheckParser parser = new PreCheckParser(); Prerequisite prereq = parser.parse("CHECKBASE", "1,Will=7", false, false); assertEquals( "<prereq kind=\"checkbase\" key=\"Will\" operator=\"GTEQ\" operand=\"7\" >\n" + "</prereq>\n", prereq.toString()); }
/** @throws Exception */ public void testBaseFort4Will7() throws Exception { PreCheckParser parser = new PreCheckParser(); Prerequisite prereq = parser.parse("CHECKBASE", "1,Fortitude=4,Will=7", false, false); assertEquals( "<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"checkbase\" count-multiples=\"true\" key=\"Fortitude\" operator=\"GTEQ\" operand=\"4\" >\n" + "</prereq>\n" + "<prereq kind=\"checkbase\" count-multiples=\"true\" key=\"Will\" operator=\"GTEQ\" operand=\"7\" >\n" + "</prereq>\n" + "</prereq>\n", prereq.toString()); }
@Test public void testFeat1() throws Exception { PreMultParser parser = new PreMultParser(); Prerequisite prereq = parser.parse( "mult", "1,[PREPROFWITHARMOR:1,TYPE.Medium],[PREFEAT:1,Armor Proficiency (Medium)]", false, false); assertEquals( "<prereq operator=\"GTEQ\" operand=\"1\" >\n" + "<prereq kind=\"profwitharmor\" key=\"TYPE.Medium\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "<prereq kind=\"ability\" category=\"FEAT\" key=\"Armor Proficiency\" sub-key=\"Medium\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "</prereq>\n", prereq.toString()); }
// TODO Refactor this with all the equipment tests. @Override public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException { final int number; try { number = Integer.parseInt(prereq.getOperand()); } catch (NumberFormatException e) { throw new PrerequisiteException( LanguageBundle.getFormattedString( "PreItem.error.bad_operand", prereq.toString())); // $NON-NLS-1$ } int runningTotal = 0; if (display.hasEquipment()) { // Work out exactlywhat we are going to test. final String aString = prereq.getKey(); List<String> typeList = null; if (aString.startsWith(Constants.LST_TYPE_EQUAL) || aString.startsWith(Constants.LST_TYPE_DOT)) { String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE); typeList = CoreUtility.split(stripped, '.'); } for (Equipment eq : display.getEquipmentSet()) { if (typeList != null) { // Check to see if the equipment matches // all of the types in the requested list; boolean bMatches = true; for (int i = 0, x = typeList.size(); i < x; ++i) { if (!eq.isType(typeList.get(i))) { bMatches = false; break; } } if (bMatches) { runningTotal++; } } else { // not a TYPE string final String eqName = eq.getName().toUpperCase(); if (aString.indexOf('%') >= 0) { // handle wildcards (always assume // they end the line) final int percentPos = aString.indexOf('%'); final String substring = aString.substring(0, percentPos).toUpperCase(); if ((eqName.startsWith(substring))) { ++runningTotal; break; } } else if (eqName.equalsIgnoreCase(aString)) { // just a straight String compare ++runningTotal; break; } } } } runningTotal = prereq.getOperator().compare(runningTotal, number); return countedTotal(prereq, runningTotal); }