From: <jfr...@us...> - 2007-11-23 17:29:38
|
Revision: 4574 http://pcgen.svn.sourceforge.net/pcgen/?rev=4574&view=rev Author: jfrazierjr Date: 2007-11-23 09:29:40 -0800 (Fri, 23 Nov 2007) Log Message: ----------- Output of JEP values in output sheet un-intuitive Issue#: 1756983 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2007-11-23 09:16:02 UTC (rev 4573) +++ Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2007-11-23 17:29:40 UTC (rev 4574) @@ -2474,8 +2474,10 @@ } //Leave - else if (((testString.indexOf('(') >= 0) - || (testString.indexOf('+') >= 0) + else if (( + //(testString.indexOf('(') >= 0) + //|| + (testString.indexOf('+') >= 0) || (testString.indexOf('-') >= 0) || (testString.indexOf(".INTVAL") >= 0) || (testString.indexOf(".SIGN") >= 0) Modified: Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-11-23 09:16:02 UTC (rev 4573) +++ Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-11-23 17:29:40 UTC (rev 4574) @@ -313,13 +313,40 @@ Ability dummyFeat2 = new Ability(); dummyFeat2.setName("DummyFeat2"); dummyFeat2.addBonusList("VAR|NegLevels|7"); + + Ability dummyFeat3 = new Ability(); + dummyFeat3.setName("DummyFeat3"); + dummyFeat3.setCategory("Maneuver"); + + Ability dummyFeat4 = new Ability(); + dummyFeat4.setName("DummyFeat4"); + dummyFeat4.setCategory("Maneuver(Special)"); + pc.addFeat(dummyFeat, null); pc.addFeat(dummyFeat2, null); - + pc.addFeat(dummyFeat3, null); + pc.addFeat(dummyFeat4, null); + assertEquals("Unsigned output", "7", evaluateToken( "VAR.NegLevels.INTVAL", pc)); assertEquals("Signed output", "+7", evaluateToken( "VAR.NegLevels.INTVAL.SIGN", pc)); + + String tok =""; + + tok = "count(\"ABILITIES\", \"CATEGORY=Maneuver\")"; + // if this evaluates math wise, the values should be string "1.0" + assertFalse("Token: |" + tok + "| != 1.0: ", evaluateToken(tok, pc).equals("1.0")); + + tok = "VAR.count(\"ABILITIES\", \"CATEGORY=Maneuver\")"; + assertTrue("Token: |" + tok + "| == 1.0: ", evaluateToken(tok, pc).equals("1.0")); + + tok ="COUNT[\"ABILITIES\", \"CATEGORY=Maneuver\"]"; + assertFalse("Token: |" + tok + "| != 1.0: ", evaluateToken(tok, pc).equals("1.0")); + + tok = "count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")"; + assertFalse("Token: |" + tok + "| != 1.0 ", evaluateToken(tok, pc).equals("1.0")); + } private String evaluateToken(String token, PlayerCharacter pc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2007-12-07 15:15:07
|
Revision: 4681 http://pcgen.svn.sourceforge.net/pcgen/?rev=4681&view=rev Author: jfrazierjr Date: 2007-12-07 07:15:12 -0800 (Fri, 07 Dec 2007) Log Message: ----------- PREPCLEVEL tag for prereqs of non monster class levels Issue#: 1844124 Added Paths: ----------- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PrePCLevelParser.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PrePCLevelTester.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PrePCLevelTest.java Added: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PrePCLevelParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PrePCLevelParser.java (rev 0) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PrePCLevelParser.java 2007-12-07 15:15:12 UTC (rev 4681) @@ -0,0 +1,135 @@ +/* + * PrePCLevelParser.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 2007-12-07 + * + */ +package plugin.pretokens.parser; + +import java.util.StringTokenizer; + +import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteOperator; +import pcgen.persistence.PersistenceLayerException; +import pcgen.persistence.lst.prereq.AbstractPrerequisiteParser; +import pcgen.persistence.lst.prereq.PrerequisiteParserInterface; +import pcgen.util.Logging; + +/** + * @author jfrazierjr + * + */ +public class PrePCLevelParser extends AbstractPrerequisiteParser implements + PrerequisiteParserInterface +{ + + //TODO created tests + //TODO create writer + //TODO create prereqparser + + /* + * (non-Javadoc) + * + * @see pcgen.persistence.lst.prereq.PrerequisiteParserInterface#kindsHandled() + */ + public String[] kindsHandled() + { + return new String[] + { "PCLEVEL" }; + } + + public Prerequisite parse(String kind, String formula, + boolean invertResult, boolean overrideQualify) + throws PersistenceLayerException + { + Prerequisite prereq = super.parse(kind, formula, invertResult, + overrideQualify); + + if (formula.contains("MIN") || formula.contains("MAX")) + { + StringTokenizer tok = new StringTokenizer(formula, ","); + Prerequisite maxPrereq = new Prerequisite(); + Prerequisite minPrereq = new Prerequisite(); + boolean hasMin = false; + boolean hasMax = false; + while (tok.hasMoreTokens()) + { + String value = tok.nextToken(); + String[] vals = value.split("="); + if (vals.length != 2) + { + throw new PersistenceLayerException( + "PREPCLEVEL must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + "' is not valid. "); + + } + String token = vals[0]; + String hdVal = vals[1]; + try + { + Integer.parseInt(hdVal); + } + catch (NumberFormatException nfe) + { + throw new PersistenceLayerException( + "PREPCLEVEL must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + + "' is not valid: " + + hdVal + + " is not an integer"); + } + if (token.equals("MIN")) + { + minPrereq.setKind("pclevel"); + minPrereq.setOperator(PrerequisiteOperator.GTEQ); + minPrereq.setOperand(hdVal); + + hasMin = true; + + } + if (token.equals("MAX")) + { + maxPrereq.setKind("pclevel"); + maxPrereq.setOperator(PrerequisiteOperator.LTEQ); + maxPrereq.setOperand(hdVal); + hasMax = true; + } + } + if (hasMin && hasMax) + { + prereq.setKind(null); // PREMULT + prereq.setOperand("2"); + prereq.addPrerequisite(minPrereq); + prereq.addPrerequisite(maxPrereq); + } + else if (hasMin) + { + prereq = minPrereq; + } + else if (hasMax) + { + prereq = maxPrereq; + } + + } + if (invertResult) + { + prereq.setOperator(prereq.getOperator().invert()); + } + return prereq; + } +} \ No newline at end of file Added: Trunk/pcgen/code/src/java/plugin/pretokens/test/PrePCLevelTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PrePCLevelTester.java (rev 0) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PrePCLevelTester.java 2007-12-07 15:15:12 UTC (rev 4681) @@ -0,0 +1,58 @@ +/* + * PrePCLevelTester.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 2007-12-07 + * + */ +package plugin.pretokens.test; + +import pcgen.core.PlayerCharacter; +import pcgen.core.prereq.AbstractPrerequisiteTest; +import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteTest; + +/** + * @author jfrazierjr + * + */ +public class PrePCLevelTester extends AbstractPrerequisiteTest implements + PrerequisiteTest +{ + + /* (non-Javadoc) + * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter) + */ + @Override + public int passes(final Prerequisite prereq, final PlayerCharacter character) + { + + final int requiredLevel = Integer.parseInt(prereq.getOperand()); + final int runningTotal = + prereq.getOperator().compare(character.getTotalPlayerLevels(), + requiredLevel); + return countedTotal(prereq, runningTotal); + } + + /* (non-Javadoc) + * @see pcgen.core.prereq.PrerequisiteTest#kindsHandled() + */ + public String kindHandled() + { + return "PCLEVEL"; //$NON-NLS-1$ + } + +} Added: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java (rev 0) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java 2007-12-07 15:15:12 UTC (rev 4681) @@ -0,0 +1,139 @@ +/* + * PrePCLevelWriter.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 2007-12-07 + * + */ +package plugin.pretokens.writer; + +import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteOperator; +import pcgen.persistence.PersistenceLayerException; +import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; +import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; + +import java.io.IOException; +import java.io.Writer; +import java.util.List; + +public class PrePCLevelWriter extends AbstractPrerequisiteWriter implements + PrerequisiteWriterInterface +{ + + /* (non-Javadoc) + * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#kindHandled() + */ + public String kindHandled() + { + return "pclevel"; + } + + /* (non-Javadoc) + * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#operatorsHandled() + */ + public PrerequisiteOperator[] operatorsHandled() + { + return new PrerequisiteOperator[]{PrerequisiteOperator.GTEQ, + PrerequisiteOperator.LT, PrerequisiteOperator.LTEQ,PrerequisiteOperator.GT}; + } + + /* (non-Javadoc) + * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite) + */ + public void write(Writer writer, Prerequisite prereq) + throws PersistenceLayerException + { + checkValidOperator(prereq, operatorsHandled()); + + try + { + if (prereq.getOperator().equals(PrerequisiteOperator.LT)) + { + writer.write('!'); + writer.write("PREPCLEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); + writer.write(prereq.getOperand()); + } + else if(prereq.getOperator().equals(PrerequisiteOperator.GT)) + { + writer.write('!'); + writer.write("PREPCLEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); + writer.write(prereq.getOperand()); + } + else if (prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) + { + writer.write("PREPCLEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); + writer.write(prereq.getOperand()); + } + else if(prereq.getOperator().equals(PrerequisiteOperator.LTEQ)) + { + writer.write("PREPCLEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); + writer.write(prereq.getOperand()); + } + + } + catch (IOException e) + { + throw new PersistenceLayerException(e.getMessage()); + } + } + /* (non-Javadoc) + * @see pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter#specialCase(java.io.Writer writer, pcgen.core.prereq.Prerequisite prereq) + */ + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + // + // ...with exactly 2 entries... + // + List<Prerequisite> prereqList = prereq.getPrerequisites(); + if (prereqList.size() == 2) + { + // + // ...both of which are PREHD. The first must specify >= and the second <= + // + final Prerequisite elementGTEQ = prereqList.get(0); + final Prerequisite elementLTEQ = prereqList.get(1); + if ("level".equalsIgnoreCase(elementGTEQ.getKind()) + && elementGTEQ.getOperator().equals( + PrerequisiteOperator.GTEQ) + && "level".equalsIgnoreCase(elementLTEQ.getKind()) + && elementLTEQ.getOperator().equals( + PrerequisiteOperator.LTEQ)) + { + if (prereq.getOperator().equals(PrerequisiteOperator.LT)) + { + writer.write('!'); + } + writer.write("PREPCLEVEL:" + (prereq.isOverrideQualify() ? "Q:":"")); + writer.write("MIN="); + writer.write(elementGTEQ.getOperand()); + writer.write(",MAX="); + writer.write(elementLTEQ.getOperand()); + return true; + } + } + } + return false; + } + +} Added: Trunk/pcgen/code/src/test/pcgen/core/prereq/PrePCLevelTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PrePCLevelTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PrePCLevelTest.java 2007-12-07 15:15:12 UTC (rev 4681) @@ -0,0 +1,242 @@ +/* + * PrePCLevelTest.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + */ +package pcgen.core.prereq; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Globals; +import pcgen.core.PCClass; +import pcgen.core.PlayerCharacter; +import pcgen.core.Race; +import pcgen.core.bonus.Bonus; +import pcgen.core.bonus.BonusObj; +import pcgen.persistence.lst.prereq.PreParserFactory; + +/** + * <code>PREPCLEVELTest</code> tests that the PREPCLEVEL tag is + * working correctly. + * + * Last Editor: $Author: $ + * Last Edited: $Date: 2007-11-21 09:50:01 -0500 (Wed, 21 Nov 2007) $ + * + * @author Aaron Divinsky <boo...@ya...> + * @version $Revision: 4557 $ + */ +public class PrePCLevelTest extends AbstractCharacterTestCase +{ + private PCClass myClass = new PCClass(); + private Race race = new Race(); + + public static void main(final String[] args) + { + TestRunner.run(PrePCLevelTest.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PrePCLevelTest.class); + } + + /** + * Test that Level works + * @throws Exception + */ + public void testLevel() throws Exception + { + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(1, myClass, true); + + myClass = character.getClassKeyed("MY_CLASS"); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PREPCLEVEL:MIN=2"); + assertFalse("Character is not 2nd level", PrereqHandler.passes(prereq, + character, null)); + + character.incrementClassLevel(1, myClass, true); + + assertTrue("Character has 2 levels", PrereqHandler.passes(prereq, + character, null)); + + character.incrementClassLevel(1, myClass, true); + prereq = factory.parse("PREPCLEVEL:MIN=2,MAX=3"); + assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + character.incrementClassLevel(1, myClass, true); + assertFalse("Character is not 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=2,MAX=3"); + assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=4"); + assertFalse("Character is 4 or higher level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MAX=3"); + assertTrue("Character is 3rd or higher level", PrereqHandler.passes(prereq, + character, null)); + + + + + + + + } + + /** + * Test that HD are counted + * @throws Exception + */ + public void testHD() throws Exception + { + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(2, myClass, true); + + myClass = character.getClassKeyed("MY_CLASS"); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + + prereq = factory.parse("PREPCLEVEL:MIN=4"); + assertFalse("Character doesn't have 4 levels", PrereqHandler.passes( + prereq, character, null)); + + character.setRace(race); + + assertFalse("Character has 4 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=5"); + assertTrue("Character doesn't have 5 or more levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=3"); + assertTrue("Character doesn't have 5 or more levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("!PREPCLEVEL:MAX=3"); + assertFalse("Character doesn't have 3 or more levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=6,MAX=7"); + assertTrue("Character doesn't have between 6 and 7 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PREPCLEVEL:MIN=4,MAX=6"); + assertFalse("Character doesn't have 4-6 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PREPCLEVEL:MIN=6,MAX=7"); + assertFalse("Character doesn't have 6-7 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PREPCLEVEL:MAX=7"); + assertTrue("Character has no more than 5 levels", PrereqHandler.passes( + prereq, character, null)); + + character.incrementClassLevel(4, myClass, true); + prereq = factory.parse("PREPCLEVEL:MAX=6"); + assertTrue("Character has no more than 6 levels", PrereqHandler.passes( + prereq, character, null)); + + + } + + /** + * Make sure BONUS:PCLEVEL is not counted + * @throws Exception + */ + public void testPCLevel() throws Exception + { + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(2, myClass, true); + + myClass = character.getClassKeyed("MY_CLASS"); + + character.setRace(race); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + + prereq = factory.parse("PREPCLEVEL:MIN=6"); + + final BonusObj levelBonus = Bonus.newBonus("PCLEVEL|MY_CLASS|2"); + levelBonus.setCreatorObject(myClass); + myClass.addBonusList(levelBonus); + character.calcActiveBonuses(); + + assertFalse("Character has only 4 levels", PrereqHandler.passes(prereq, + character, null)); + + + prereq = factory.parse("PREPCLEVEL:MAX=6"); + assertTrue("Character has more than 6 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MAX=6"); + assertFalse("Character is less than 6 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=5"); + assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("PREPCLEVEL:MIN=4,MAX=6"); + assertFalse("Character does not have 4-6 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("PREPCLEVEL:MIN=6,MAX=8"); + assertFalse("Character does not have 6-8 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PREPCLEVEL:MIN=6,MAX=8"); + assertTrue("Character is not 6-8 levels", PrereqHandler.passes(prereq, + character, null)); + + + } + + protected void setUp() throws Exception + { + super.setUp(); + + race.setName("Gnoll"); + race.setHitDice(2); + + myClass.setName("My Class"); + myClass.setKeyName("MY_CLASS"); + myClass.setAbbrev("Myc"); + myClass.setSkillPointFormula("3"); + Globals.getClassList().add(myClass); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2007-12-07 16:02:34
|
Revision: 4682 http://pcgen.svn.sourceforge.net/pcgen/?rev=4682&view=rev Author: jfrazierjr Date: 2007-12-07 08:02:38 -0800 (Fri, 07 Dec 2007) Log Message: ----------- Fixed writer to output the proper tags and added test cases to writertest suite. Issue#: 1844124 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java 2007-12-07 15:15:12 UTC (rev 4681) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePCLevelWriter.java 2007-12-07 16:02:38 UTC (rev 4682) @@ -113,10 +113,10 @@ // final Prerequisite elementGTEQ = prereqList.get(0); final Prerequisite elementLTEQ = prereqList.get(1); - if ("level".equalsIgnoreCase(elementGTEQ.getKind()) + if ("pclevel".equalsIgnoreCase(elementGTEQ.getKind()) && elementGTEQ.getOperator().equals( PrerequisiteOperator.GTEQ) - && "level".equalsIgnoreCase(elementLTEQ.getKind()) + && "pclevel".equalsIgnoreCase(elementLTEQ.getKind()) && elementLTEQ.getOperator().equals( PrerequisiteOperator.LTEQ)) { Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-12-07 15:15:12 UTC (rev 4681) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-12-07 16:02:38 UTC (rev 4682) @@ -149,6 +149,11 @@ "PRELEVEL:MAX=5", "PRELEVEL:MAX=5", "PRELEVEL:MIN=4,MAX=5", "PRELEVEL:MIN=4,MAX=5", "PRELEVELMAX:10", "PRELEVELMAX:10", + + "PREPCLEVEL:MIN=5", "PREPCLEVEL:MIN=5", + "PREPCLEVEL:MAX=5", "PREPCLEVEL:MAX=5", + "PREPCLEVEL:MIN=4,MAX=5", "PREPCLEVEL:MIN=4,MAX=5", + "PREMOVE:Walk=30,Fly=20", "PREMULT:1,[PREMOVE:1,Walk=30],[PREMOVE:1,Fly=20]", "PREMOVE:Swim=10", "PREMOVE:1,Swim=10", "PREMULT:1,[PRERACE:Gnome],[PRECLASS:1,Cleric=1]", "PREMULT:1,[PRERACE:Gnome],[PRECLASS:1,Cleric=1]", @@ -286,6 +291,10 @@ "!PRELEVEL:MIN=4", "!PRELEVEL:MIN=4", "!PRELEVEL:MAX=4", "!PRELEVEL:MAX=4", "!PRELEVEL:MIN=4,MAX=6", "!PRELEVEL:MIN=4,MAX=6", + + "!PREPCLEVEL:MIN=4", "!PREPCLEVEL:MIN=4", + "!PREPCLEVEL:MAX=4", "!PREPCLEVEL:MAX=4", + "!PREPCLEVEL:MIN=4,MAX=6", "!PREPCLEVEL:MIN=4,MAX=6", "!PREREGION:Slithe", "!PREREGION:Slithe", "!PRERULE:SYS_WTPSK", "!PRERULE:1,SYS_WTPSK", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-12-08 06:23:28
|
Revision: 4695 http://pcgen.svn.sourceforge.net/pcgen/?rev=4695&view=rev Author: jdempsey Date: 2007-12-07 22:23:32 -0800 (Fri, 07 Dec 2007) Log Message: ----------- FRwq: Remove/Override Nonabilities Issue#: 1471354 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/Race.java Trunk/pcgen/code/src/java/pcgen/core/StatList.java Trunk/pcgen/code/src/test/pcgen/core/PCTemplateTest.java Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/RaceTest.java Trunk/pcgen/code/src/test/pcgen/core/StatListTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -445,7 +445,8 @@ /** * Takes an integer input which it uses to access Games mode's "statlist" * array. If that stat has been locked at 10 then it is considered a - * non-ability. XXX This is insanely bad design, it's completely arse about + * non-ability. + * XXX This is insanely bad design, it's completely arse about * face. What should have been done was find a way to mark a stat as a * non-ability and then have the stat checking code interpret that as "no * bonus or penalty - treat like it was locked at 10". Doing it this way @@ -467,8 +468,46 @@ return true; } - final String aStat = "|LOCK." + statList.get(statIdx).getAbb() + "|10"; + // An unlock will always override a lock, so check it first + if (isUnlocked(statIdx)) + { + return false; + } + + String aStat = "|LOCK." + statList.get(statIdx).getAbb() + "|10"; + for (int i = 0, x = getVariableCount(); i < x; ++i) + { + final String varString = getVariableDefinition(i); + if (varString.endsWith(aStat)) + { + return true; + } + } + + return false; + } + + /** + * Takes an integer input which it uses to access Games mode's "statlist" + * array. Test if that stat has been unlocked via a DEFINE|UNLOCK + * + * @param statIdx + * index number of the stat in question + * + * @return Whether this has been unlocked + */ + public boolean isUnlocked(final int statIdx) + { + final List<PCStat> statList = SettingsHandler.getGame() + .getUnmodifiableStatList(); + + if ((statIdx < 0) || (statIdx >= statList.size())) + { + return false; + } + + String aStat = "|UNLOCK." + statList.get(statIdx).getAbb() + "|"; for (int i = 0, x = getVariableCount(); i < x; ++i) { final String varString = getVariableDefinition(i); Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -6018,8 +6018,28 @@ return null; } + /** + * Checks if the stat is a non ability. + * + * @param i the index of the stat + * + * @return true, if is non ability + */ public boolean isNonAbility(final int i) { + //Unlocked overrides any lock to a non ability so check for it first + if (race.isUnlocked(i)) + { + return false; + } + for (PCTemplate template : templateList) + { + if (template.isUnlocked(i)) + { + return false; + } + } + if (race.isNonAbility(i)) { return true; Modified: Trunk/pcgen/code/src/java/pcgen/core/Race.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Race.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/java/pcgen/core/Race.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -532,6 +532,12 @@ return true; } + // An unlock will always override a lock, so check it first + if (isUnlocked(statIdx)) + { + return false; + } + final String aStat = "|LOCK." + statList.get(statIdx).getAbb() + "|10"; for (int i = 0, x = getVariableCount(); i < x; ++i) @@ -547,6 +553,40 @@ return false; } + /** + * Takes an integer input which it uses to access Games mode's + * "statlist" array. Test if that stat has been unlocked via a + * DEFINE|UNLOCK + * + * @param statIdx + * index number of the stat in question + * + * @return Whether this has been unlocked + */ + public boolean isUnlocked(final int statIdx) + { + final List<PCStat> statList = SettingsHandler.getGame() + .getUnmodifiableStatList(); + + if ((statIdx < 0) || (statIdx >= statList.size())) + { + return false; + } + + String aStat = "|UNLOCK." + statList.get(statIdx).getAbb() + "|"; + for (int i = 0, x = getVariableCount(); i < x; ++i) + { + final String varString = getVariableDefinition(i); + + if (varString.endsWith(aStat)) + { + return true; + } + } + + return false; + } + public int getNumberOfHitDiceAdvancements() { return (hitDiceAdvancement != null) ? hitDiceAdvancement.length : 0; Modified: Trunk/pcgen/code/src/java/pcgen/core/StatList.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/StatList.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/java/pcgen/core/StatList.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -60,15 +60,18 @@ final PCStat stat = stats.get(x); final PlayerCharacter aPC = ownerPC; - int z = aPC.getVariableValue("LOCK." + stat.getAbb(), "").intValue(); - - if ((z != 0) || ((z == 0) && aPC.hasVariable("LOCK." + stat.getAbb()))) + // Only check for a lock if the stat hasn't been unlocked + if (!aPC.hasVariable("UNLOCK." + stat.getAbb())) { - return z; + int z = aPC.getVariableValue("LOCK." + stat.getAbb(), "").intValue(); + if ((z != 0) || ((z == 0) && aPC.hasVariable("LOCK." + stat.getAbb()))) + { + return z; + } } + + int z = aPC.getVariableValue("BASE." + stat.getAbb(), "").intValue(); - z = aPC.getVariableValue("BASE." + stat.getAbb(), "").intValue(); - if (z != 0) { return z; @@ -204,11 +207,14 @@ final PCStat stat = stats.get(x); final PlayerCharacter aPC = ownerPC; - x = aPC.getVariableValue("LOCK." + stat.getAbb(), "").intValue(); - - if ((x != 0) || ((x == 0) && aPC.hasVariable("LOCK." + stat.getAbb()))) + // Only check for a lock if the stat hasn't been unlocked + if (!aPC.hasVariable("UNLOCK." + stat.getAbb())) { - return x; + x = aPC.getVariableValue("LOCK." + stat.getAbb(), "").intValue(); + if ((x != 0) || ((x == 0) && aPC.hasVariable("LOCK." + stat.getAbb()))) + { + return x; + } } y += aPC.getTotalBonusTo("STAT", stat.getAbb()); Modified: Trunk/pcgen/code/src/test/pcgen/core/PCTemplateTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/PCTemplateTest.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/test/pcgen/core/PCTemplateTest.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -327,6 +327,39 @@ } /** + * Test the isUnlocked method of PCTemplate. + */ + public void testIsUnlocked() + { + PCTemplate template = new PCTemplate(); + template.setName("Test Template"); + int index = getCharacter().getStatList().getIndexOfStatFor("STR"); + assertEquals("Template has not been unlocked", false, template.isUnlocked(index)); + template.addVariable(-9, "LOCK.STR", "12"); + assertEquals("Template has not been unlocked", false, template.isUnlocked(index)); + template.addVariable(-9, "UNLOCK.STR", ""); + assertEquals("Template has been unlocked", true, template.isUnlocked(index)); + } + + /** + * Test the isNonAbility method of PCTemplate. + */ + public void testIsNonAbility() + { + PCTemplate template = new PCTemplate(); + template.setName("Test Template"); + int index = getCharacter().getStatList().getIndexOfStatFor("STR"); + assertEquals("Template has not been locked to a nonability", false, template.isNonAbility(index)); + template.addVariable(-9, "LOCK.STR", "12"); + assertEquals("Template has been locked to an ability", false, template.isNonAbility(index)); + template.addVariable(-9, "LOCK.STR", "10"); + assertEquals("Template has been locked to a nonability", true, template.isNonAbility(index)); + template.addVariable(-9, "UNLOCK.STR", ""); + assertEquals("Template has been unlocked", false, template.isNonAbility(index)); + } + + + /** * @see pcgen.AbstractCharacterTestCase#setUp() */ @Override Modified: Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-12-08 06:18:09 UTC (rev 4694) +++ Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -866,4 +866,41 @@ Logging.errorPrint("Real abilities: " + pc.getRealAbilitiesList(ac).size()); } + + public void testIsNonAbility() + { + PlayerCharacter pc = getCharacter(); + int index = pc.getStatList().getIndexOfStatFor("STR"); + + //Base + assertEquals("Initially character should not have a locked ability", false, pc.isNonAbility(index)); + + // With template lock + PCTemplate nonAbilityLocker = new PCTemplate(); + nonAbilityLocker.setName("locker"); + nonAbilityLocker.addVariable(-9, "LOCK.STR", "10"); + pc.addTemplate(nonAbilityLocker); + assertEquals("STR now locked to non ability", true, pc.isNonAbility(index)); + pc.removeTemplate(nonAbilityLocker); + assertEquals("STR no longer locked to non ability", false, pc.isNonAbility(index)); + + // With race lock + Race nonAbilityLockerRace = new Race(); + nonAbilityLockerRace.setName("locker"); + nonAbilityLockerRace.addVariable(-9, "LOCK.STR", "10"); + pc.setRace(nonAbilityLockerRace); + assertEquals("STR now locked to non ability", true, pc.isNonAbility(index)); + + // With template unlock + nonAbilityLocker.addVariable(-9, "UNLOCK.STR", ""); + pc.addTemplate(nonAbilityLocker); + assertEquals("STR now unlocked from a non ability by template", false, pc.isNonAbility(index)); + pc.removeTemplate(nonAbilityLocker); + assertEquals("STR no longer locked to non ability", true, pc.isNonAbility(index)); + + // With race unlock + nonAbilityLockerRace.addVariable(-9, "UNLOCK.STR", ""); + pc.setRace(nonAbilityLockerRace); + assertEquals("STR now unlocked from a non ability by race", false, pc.isNonAbility(index)); + } } Added: Trunk/pcgen/code/src/test/pcgen/core/RaceTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/RaceTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/RaceTest.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -0,0 +1,70 @@ +/* + * RaceTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 8/12/2007 + * + * $Id$ + */ +package pcgen.core; + +import pcgen.AbstractCharacterTestCase; + +/** + * <code>RaceTest</code> tests the function of the Race class. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class RaceTest extends AbstractCharacterTestCase +{ + + /** + * Test the isUnlocked method of Race. + */ + public void testIsUnlocked() + { + Race race = new Race(); + race.setName("Test Race"); + int index = getCharacter().getStatList().getIndexOfStatFor("STR"); + assertEquals("Template has not been unlocked", false, race.isUnlocked(index)); + race.addVariable(-9, "LOCK.STR", "12"); + assertEquals("Template has not been unlocked", false, race.isUnlocked(index)); + race.addVariable(-9, "UNLOCK.STR", ""); + assertEquals("Template has been unlocked", true, race.isUnlocked(index)); + } + + /** + * Test the isNonAbility method of Race. + */ + public void testIsNonAbility() + { + Race race = new Race(); + race.setName("Test Race"); + int index = getCharacter().getStatList().getIndexOfStatFor("STR"); + assertEquals("Template has not been locked to a nonability", false, race.isNonAbility(index)); + race.addVariable(-9, "LOCK.STR", "12"); + assertEquals("Template has been locked to an ability", false, race.isNonAbility(index)); + race.addVariable(-9, "LOCK.STR", "10"); + assertEquals("Template has been locked to a nonability", true, race.isNonAbility(index)); + race.addVariable(-9, "UNLOCK.STR", ""); + assertEquals("Template has been unlocked", false, race.isNonAbility(index)); + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/RaceTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native Added: Trunk/pcgen/code/src/test/pcgen/core/StatListTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/StatListTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/StatListTest.java 2007-12-08 06:23:32 UTC (rev 4695) @@ -0,0 +1,109 @@ +/* + * StatListTest.java + * Copyright 2007 (C) James Dempsey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 08/12/2007 + * + * $Id$ + */ + +package pcgen.core; + +import org.junit.Test; + +import pcgen.AbstractCharacterTestCase; +import pcgen.util.TestHelper; + +/** + * <code>StatListTest</code> checks the function of the + * StatList class. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class StatListTest extends AbstractCharacterTestCase +{ + PCTemplate locker; + PCTemplate unlocker; + Ability bonus; + + /* (non-Javadoc) + * @see pcgen.AbstractCharacterTestCase#setUp() + */ + @Override + protected void setUp() throws Exception + { + super.setUp(); + locker = new PCTemplate(); + locker.setName("locker"); + locker.addVariable(-9, "LOCK.STR", "12"); + unlocker = new PCTemplate(); + unlocker.setName("unlocker"); + unlocker.addVariable(-9, "UNLOCK.STR", ""); + bonus = TestHelper.makeAbility("Bonus", "FEAT", "General.Fighter"); + bonus.addBonusList("STAT|STR|7|TYPE=Enhancement"); + + PlayerCharacter pc = getCharacter(); + setPCStat(pc, "STR", 6); + } + + /** + * Test method for {@link pcgen.core.StatList#getBaseStatFor(java.lang.String)}. + */ + @Test + public void testGetBaseStatFor() + { + PlayerCharacter pc = getCharacter(); + assertEquals("Starting STR should be 6", 6, pc.getStatList().getBaseStatFor("STR")); + + // Bonus should not affect base stat + pc.addAbility(AbilityCategory.FEAT, bonus, null); + pc.calcActiveBonuses(); + assertEquals("Stat should still be locked", 6, pc.getStatList().getBaseStatFor("STR")); + + pc.addTemplate(locker); + assertEquals("Stat should now be locked", 12, pc.getStatList().getBaseStatFor("STR")); + + pc.addTemplate(unlocker); + assertEquals("Stat should now be unlocked", 6, pc.getStatList().getBaseStatFor("STR")); + } + + /** + * Test method for {@link pcgen.core.StatList#getTotalStatFor(java.lang.String)}. + */ + @Test + public void testGetTotalStatFor() + { + PlayerCharacter pc = getCharacter(); + assertEquals("Starting STR should be 6", 6, pc.getStatList().getTotalStatFor("STR")); + + // Bonus should affect total stat + pc.addAbility(AbilityCategory.FEAT, bonus, null); + pc.calcActiveBonuses(); + assertEquals("Stat should have bonus", 13, pc.getStatList().getTotalStatFor("STR")); + + pc.addTemplate(locker); + assertEquals("Stat should now be locked", 12, pc.getStatList().getTotalStatFor("STR")); + + pc.addTemplate(unlocker); + assertEquals("Stat should now be unlocked", 13, pc.getStatList().getTotalStatFor("STR")); + } + +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/StatListTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-12-14 21:23:11
|
Revision: 4720 http://pcgen.svn.sourceforge.net/pcgen/?rev=4720&view=rev Author: jdempsey Date: 2007-12-14 13:23:06 -0800 (Fri, 14 Dec 2007) Log Message: ----------- Tighten DEFINE parsing and add testing of special UNLOCK case. Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/lsttokens/DefineLst.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/PObjectLoaderTest.java Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/DefineLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/DefineLst.java 2007-12-14 14:53:07 UTC (rev 4719) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/DefineLst.java 2007-12-14 21:23:06 UTC (rev 4720) @@ -8,6 +8,7 @@ import pcgen.core.PObject; import pcgen.persistence.lst.GlobalLstToken; +import pcgen.util.Logging; /** * @author djones4 @@ -27,7 +28,30 @@ try { String varName = tok.nextToken(); - String defineFormula = tok.hasMoreTokens() ? tok.nextToken() : ""; + String defineFormula; + if (varName.startsWith("UNLOCK.")) + { + if (tok.hasMoreTokens()) + { + Logging + .log(Logging.LST_ERROR, + "Cannot provide a value with DEFINE:UNLOCK. : " + + value); + return false; + } + defineFormula = ""; + } + else if (!tok.hasMoreTokens()) + { + Logging.log(Logging.LST_ERROR, + "Non UNLOCK DEFINE missing value. Fomrat should be DEFINE:var|value : " + + value); + return false; + } + else + { + defineFormula = tok.nextToken(); + } obj.addVariable(anInt, varName, defineFormula); } catch (Exception e) Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/PObjectLoaderTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/PObjectLoaderTest.java 2007-12-14 14:53:07 UTC (rev 4719) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/PObjectLoaderTest.java 2007-12-14 21:23:06 UTC (rev 4720) @@ -91,6 +91,30 @@ } } + public void testUnlockDefine() throws Exception + { + PluginLoader ploader = PluginLoader.inst(); + ploader.startSystemPlugins(Constants.s_SYSTEM_TOKENS); + Ability feat = new Ability(); + + is(PObjectLoader.parseTag(feat, "DEFINE:UNLOCK.INT"), eq(true), + "Parse fails for unlock"); + + Variable var = feat.getVariable(0); + assertEquals("UNLOCK.INT", var.getName()); + assertEquals("", var.getValue()); + } + + public void testBadUnlockDefine() throws Exception + { + PluginLoader ploader = PluginLoader.inst(); + ploader.startSystemPlugins(Constants.s_SYSTEM_TOKENS); + Ability feat = new Ability(); + + is(PObjectLoader.parseTag(feat, "DEFINE:UNLOCK.INT|0"), eq(false), + "Parse fails to catch bad unlock define"); + } + public void testParseSA() throws Exception { PluginLoader ploader = PluginLoader.inst(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-01-05 02:04:46
|
Revision: 4825 http://pcgen.svn.sourceforge.net/pcgen/?rev=4825&view=rev Author: jdempsey Date: 2008-01-04 18:04:44 -0800 (Fri, 04 Jan 2008) Log Message: ----------- Data installer for out of cycle data releases - Correct feat pool processing bug introduced by this change. Issue#: 1859541 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2008-01-04 18:42:46 UTC (rev 4824) +++ Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2008-01-05 02:04:44 UTC (rev 4825) @@ -5262,7 +5262,7 @@ */ protected int compareVersionTo(int inVer[]) { - return CoreUtility.compareVersions(inVer, pcgenVersion); + return CoreUtility.compareVersions(pcgenVersion, inVer); } /** Modified: Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java 2008-01-04 18:42:46 UTC (rev 4824) +++ Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java 2008-01-05 02:04:44 UTC (rev 4825) @@ -193,4 +193,17 @@ assertEquals(3, version.length); } + + public void testCompareVersionTo() throws PCGParseException + { + PCGVer2Parser parser = new PCGVer2Parser(null); + + parser.parseVersionLine("VERSION:5.13.6"); + assertEquals("Check of a matching version", 0, parser + .compareVersionTo(new int[]{5, 13, 6})); + assertEquals("Check of an earlier version", -1, parser + .compareVersionTo(new int[]{5, 13, 7})); + assertEquals("Check of a later version", 1, parser + .compareVersionTo(new int[]{5, 13, 5})); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-01-12 07:53:36
|
Revision: 4866 http://pcgen.svn.sourceforge.net/pcgen/?rev=4866&view=rev Author: jdempsey Date: 2008-01-11 23:53:41 -0800 (Fri, 11 Jan 2008) Log Message: ----------- Fix bug: Feat benefits from same feat in different pool not stacking Also fix Weapon spec not finding non-feat weapon focus entries Issue#: 1836470 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/chooser/FeatChoiceManager.java Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2008-01-12 07:47:51 UTC (rev 4865) +++ Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2008-01-12 07:53:41 UTC (rev 4866) @@ -454,7 +454,7 @@ { abilityCount -= ability.getCost(aPC); } - else + else if (category == AbilityCategory.FEAT) { int listSize = ability.getAssociatedCount(); Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-01-12 07:47:51 UTC (rev 4865) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-01-12 07:53:41 UTC (rev 4866) @@ -50,6 +50,7 @@ import java.util.TreeMap; import java.util.TreeSet; +import pcgen.core.Ability.Nature; import pcgen.core.bonus.Bonus; import pcgen.core.bonus.BonusObj; import pcgen.core.character.CharacterSpell; @@ -11611,35 +11612,6 @@ return bonus; } - /** - * Returns the Feat definition searching by key (not name), as contained in - * the specified list - * - * @param featName - * String key of the feat to check for. - * @param afeatList - * @return the Feat (not the CharacterFeat) searched for, <code>null</code> - * if not found. - */ - private Ability getFeatKeyed(final String featName, - final List<Ability> afeatList) - { - if (afeatList.isEmpty()) - { - return null; - } - - for (Ability feat : afeatList) - { - if (feat.getKeyName().equalsIgnoreCase(featName)) - { - return feat; - } - } - - return null; - } - private String getFullDisplayClassName() { if (classList.isEmpty()) @@ -12795,7 +12767,7 @@ } // Feats and abilities (virtual feats, auto feats) - Set<Ability> abilities = getFullAbilitySet(); + List<Ability> abilities = getFullAbilityList(); results.addAll(abilities); // Race @@ -16835,17 +16807,12 @@ */ public Ability getFeatKeyed(final String featName) { - return getFeatKeyed(featName, aggregateFeatList()); + return getAbilityKeyed(AbilityCategory.FEAT, featName); } public Ability getAbilityKeyed(final AbilityCategory aCategory, final String aKey) { - if (aCategory == AbilityCategory.FEAT) - { - return getFeatKeyed(aKey); - } - final List<Ability> abilities = getAggregateAbilityList(aCategory); for (final Ability ability : abilities) { @@ -17236,6 +17203,28 @@ return abilitySet; } + + /** + * Return a list of all abilities no matter what category or + * nature that the PC has. Note: This method allows duplicates, + * such as when the same ability has been added by different + * categories. + * @return List of all abilities. + */ + public List<Ability> getFullAbilityList() + { + GameMode gm = SettingsHandler.getGame(); + Set<AbilityCategory> catSet = new HashSet<AbilityCategory>(); + catSet.addAll(gm.getAllAbilityCategories()); + List<Ability> abilityList = new ArrayList<Ability>(); + + for (AbilityCategory cat: catSet) + { + abilityList.addAll(this.getAggregateAbilityList(cat)); + } + + return abilityList; + } public List<Ability> getVirtualAbilityList(final AbilityCategory aCategory) { @@ -17690,6 +17679,33 @@ } + /** + * Gets a list of feats matching the supplied name no matter what category + * they were added in. + * + * @param featName the feat name + * + * @return the list of matching feats + */ + public List<Ability> getFeatNamedAnyCat(String featName) + { + List<Ability> feats = new ArrayList<Ability>(); + for (AbilityCategory cat : SettingsHandler.getGame() + .getAllAbilityCategories()) + { + Ability tempFeat = + AbilityUtilities.getAbilityFromList( + getAggregateAbilityList(cat), Constants.FEAT_CATEGORY, + featName, Nature.ANY); + if (tempFeat != null) + { + feats.add(tempFeat); + } + } + + return feats; + } + // public double getBonusValue(final String aBonusType, final String // aBonusName ) // { Modified: Trunk/pcgen/code/src/java/pcgen/core/chooser/FeatChoiceManager.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/chooser/FeatChoiceManager.java 2008-01-12 07:47:51 UTC (rev 4865) +++ Trunk/pcgen/code/src/java/pcgen/core/chooser/FeatChoiceManager.java 2008-01-12 07:53:41 UTC (rev 4866) @@ -29,6 +29,7 @@ import java.util.regex.Pattern; import pcgen.core.Ability; +import pcgen.core.AbilityCategory; import pcgen.core.AssociatedChoice; import pcgen.core.PObject; import pcgen.core.PlayerCharacter; @@ -80,11 +81,11 @@ final List<String> availableList, final List<String> selectedList) { - final Ability theFeat = aPc.getFeatNamed(choices.get(0)); - - if (theFeat != null) + // Grab a list of occurrences of the feat being chosen in any category + final List<Ability> theFeats = aPc.getFeatNamedAnyCat(choices.get(0)); + for (Ability ability : theFeats) { - for (AssociatedChoice<String> choice : theFeat.getAssociatedList()) + for (AssociatedChoice<String> choice : ability.getAssociatedList()) { availableList.add(choice.getDefaultChoice()); } Modified: Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2008-01-12 07:47:51 UTC (rev 4865) +++ Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2008-01-12 07:53:41 UTC (rev 4866) @@ -67,7 +67,9 @@ PCClass pcClass = null; PCClass classWarmind = null; Race human = null; - + Ability toughness = null; + AbilityCategory specialFeatCat; + /** * Run the tests. * @param args @@ -150,12 +152,13 @@ classWarmind.setAbbrev("WM"); Globals.getClassList().add(classWarmind); - Ability toughness = new Ability(); + toughness = new Ability(); toughness.setName("Toughness"); toughness.setMultiples("Y"); toughness.setStacks("Y"); toughness.setChoiceString("NOCHOICE"); toughness.setCategory("FEAT"); + toughness.addBonusList("HP|CURRENTMAX|3"); Globals.addAbility(toughness); Ability exoticWpnProf = @@ -190,6 +193,10 @@ pcClass.addAddList(1, "FEAT(KEY_Exotic Weapon Proficiency (Weapon A))"); pcClass.addAddList(2, "FEAT(KEY_Exotic Weapon Proficiency (Weapon B))"); pcClass.addAddList(3, "FEAT(KEY_Exotic Weapon Proficiency (Weapon C))"); + + specialFeatCat = new AbilityCategory("Special Feat"); + specialFeatCat.setAbilityCategory(AbilityCategory.FEAT.getKeyName()); + SettingsHandler.getGame().addAbilityCategory(specialFeatCat); } protected void tearDown() @@ -903,4 +910,40 @@ pc.setRace(nonAbilityLockerRace); assertEquals("STR now unlocked from a non ability by race", false, pc.isNonAbility(index)); } + + /** + * Test the stacking of the same ability added via different abiltiy + * categories. + */ + public void testStackDifferentAbiltyCat() + { + PlayerCharacter pc = getCharacter(); + double base = pc.getTotalBonusTo("HP", "CURRENTMAX"); + + assertEquals("Check repeatability of bonus", base, pc.getTotalBonusTo( + "HP", "CURRENTMAX")); + + try + { + AbilityUtilities.modFeat(pc, null, "Toughness", true, false); + //pc.calcActiveBonuses(); + assertEquals("Check application of single bonus", base+3, pc.getTotalBonusTo( + "HP", "CURRENTMAX")); + AbilityUtilities.modFeat(pc, null, "Toughness", true, false); + pc.calcActiveBonuses(); + assertEquals("Check application of second bonus", base+6, pc.getTotalBonusTo( + "HP", "CURRENTMAX")); + + AbilityUtilities.modAbility(pc, null, toughness, "Toughness", true, + specialFeatCat); + pc.calcActiveBonuses(); + assertEquals( + "Check application of third bonus in different catgeory", + base + 9, pc.getTotalBonusTo("HP", "CURRENTMAX")); + } + catch (HeadlessException e) + { + Logging.debugPrint("Ignoring Headless exception."); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2008-02-24 04:35:45
|
Revision: 5271 http://pcgen.svn.sourceforge.net/pcgen/?rev=5271&view=rev Author: jfrazierjr Date: 2008-02-23 20:35:43 -0800 (Sat, 23 Feb 2008) Log Message: ----------- SERVESAS Token Added first implementation object, more to come: SERVESAS:CLASS|x is now operational. Issue#: 1789856 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-02-23 19:59:31 UTC (rev 5270) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-02-24 04:35:43 UTC (rev 5271) @@ -162,6 +162,7 @@ private List<Description> theDescriptions = null; private DoubleKeyMap<Class, String, List<String>> qualifyKeys = null; + private List<Map<String,String>> servesAsList =null; private URI sourceURI = null; @@ -4258,6 +4259,8 @@ } private DoubleKeyMap<AbilityCategory, Ability.Nature, List<QualifiedObject<String>>> theAbilities = new DoubleKeyMap<AbilityCategory, Ability.Nature, List<QualifiedObject<String>>>(); + + public void addAbility(final AbilityCategory aCategory, final Ability.Nature aNature, final QualifiedObject<String> anAbility) { List<QualifiedObject<String>> abilities = theAbilities.get(aCategory, aNature); @@ -5163,6 +5166,42 @@ return chooseSelectCount; } + public void putServesAs( final String key, final String category) + { + if (servesAsList == null) + { + servesAsList = new ArrayList<Map<String,String>>(); + } + Map<String,String> aMap = new HashMap<String, String>(); + aMap.put(key,category); + servesAsList.add(aMap); + } + public void putServesAs( final List<Map<String,String>> sList ) + { + if (servesAsList == null) + { + servesAsList = new ArrayList<Map<String,String>>(); + } + else + { + servesAsList.addAll(sList); + } + } + public final void clearServesAs() + { + servesAsList =null; + } + + //TODO This exposes internal structure - be careful. + public final List<Map<String,String>> getServesAs() + { + if (servesAsList == null) + { + servesAsList = new ArrayList<Map<String,String>>(); + } + return servesAsList; + } + // public List<BonusObj> getActiveBonuses(final PlayerCharacter aPC, final String aBonusType, final String aBonusName) // { // if (!PrereqHandler.passesAll(this.getPreReqList(), aPC, this)) Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java 2008-02-23 19:59:31 UTC (rev 5270) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java 2008-02-24 04:35:43 UTC (rev 5271) @@ -68,11 +68,15 @@ key = st.nextToken(); } - while (true) { - obj.putQualifyString(c, category, key); - if (!st.hasMoreTokens()) { + while (true) + { + obj.putServesAs( key, category); + + if (!st.hasMoreTokens()) + { break; - } + } + key = st.nextToken(); } @@ -80,8 +84,10 @@ } public List<Class<? extends PObject>> getLegalTypes() { - return Arrays.asList(Ability.class, Deity.class, Domain.class, - Equipment.class, PCClass.class, Race.class, Skill.class, - Spell.class, PCTemplate.class, WeaponProf.class); + return Arrays.asList( + //Ability.class, Deity.class, Domain.class,Equipment.class, + PCClass.class, Ability.class + //Race.class, Skill.class,Spell.class, PCTemplate.class, WeaponProf.class + ); } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-02-23 19:59:31 UTC (rev 5270) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-02-24 04:35:43 UTC (rev 5271) @@ -6,6 +6,10 @@ */ package plugin.pretokens.test; +import java.util.List; +import java.util.Map; +import java.util.Set; + import pcgen.core.Equipment; import pcgen.core.PCClass; import pcgen.core.PlayerCharacter; @@ -122,7 +126,7 @@ } else { - final PCClass aClass = character.getClassKeyed(aString); + PCClass aClass = character.getClassKeyed(aString); if (aClass != null) { if (prereq.isCountMultiples()) @@ -137,6 +141,32 @@ runningTotal += aClass.getLevel(); } } + else + { + for(PCClass theClass: character.getClassList()) + { + List<Map<String,String>> theList = theClass.getServesAs(); + for(Map<String,String> aMap : theList) + { + Set<String> keys = aMap.keySet(); + for(String theString: keys) + { + if (theString.equalsIgnoreCase(aString)) + if (prereq.isCountMultiples()) + { + if (theClass.getLevel() >= preClass) + { + countedTotal++; + } + } + else + { + runningTotal += theClass.getLevel(); + } + } + } + } + } } runningTotal = prereq.getOperator().compare(runningTotal, preClass); return countedTotal(prereq, prereq.isCountMultiples() ? countedTotal : runningTotal); Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-02-23 19:59:31 UTC (rev 5270) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-02-24 04:35:43 UTC (rev 5271) @@ -86,7 +86,35 @@ final int passes = test.passes(prereq, character); assertEquals(1, passes); } + /** + * Test to ensure that a character with a ServeAs class can be found + * @throws Exception + */ + public void testNamedClassServesAs() throws Exception + { + final PCClass pcClass = new PCClass(); + pcClass.setName("MyClass"); + pcClass.setAbbrev("My"); + pcClass.putServesAs("Warrior", null); // the second parameter is for ability categories only + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(3, pcClass); + + final Prerequisite prereq = new Prerequisite(); + prereq.setKind("class"); + prereq.setKey("Warrior"); + prereq.setOperand("1"); + prereq.setOperator(PrerequisiteOperator.GTEQ); + + final PreClassTester test = new PreClassTester(); + final int passes = test.passes(prereq, character); + assertEquals(1, passes); + } + + + + + /** * Test to ensure that a character will fail a test * if it does not have the correct number of levels This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-02-24 05:17:30
|
Revision: 5272 http://pcgen.svn.sourceforge.net/pcgen/?rev=5272&view=rev Author: jdempsey Date: 2008-02-23 21:17:35 -0800 (Sat, 23 Feb 2008) Log Message: ----------- FReq: SPELLS tag time unit enhancements Issue#: 1900267 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/GameMode.java Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java Trunk/pcgen/code/src/java/plugin/exporttokens/SpellMemToken.java Trunk/pcgen/code/src/java/plugin/lsttokens/SpellsLst.java Added Paths: ----------- Trunk/pcgen/code/src/java/pcgen/core/TimeUnit.java Trunk/pcgen/code/src/test/pcgen/core/TimeUnitTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/GameMode.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/GameMode.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/pcgen/core/GameMode.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -180,6 +180,9 @@ private int maxDieSize = 12; private int minDieSize = 4; + private TimeUnit defaultTimeUnit; + private List<TimeUnit> theTimeUnits = new ArrayList<TimeUnit>(); + /** * Creates a new instance of GameMode. * @@ -198,6 +201,8 @@ ti.tabName = aTab.label(); tInfo.put(aTab, ti); } + defaultTimeUnit = new TimeUnit("DAY", "Day"); + theTimeUnits.add(defaultTimeUnit); } /** @@ -3275,6 +3280,51 @@ return Collections.unmodifiableCollection(catList); } + /** + * Adds the time unit to the game mode's list. + * + * @param timeUnit the time unit + */ + public void addTimeUnit(final TimeUnit timeUnit) + { + theTimeUnits.add(timeUnit); + } + + /** + * Gets the time unit based on its key. + * + * @param aKey the key + * + * @return the time unit + */ + public TimeUnit getTimeUnit(final String aKey) + { + for (final TimeUnit unit : theTimeUnits) + { + if (unit.getKeyName().equalsIgnoreCase(aKey)) + { + return unit; + } + } + return null; + } + + /** + * @return the defaultTimeUnit + */ + public TimeUnit getDefaultTimeUnit() + { + return defaultTimeUnit; + } + + /** + * @param defaultTimeUnit the defaultTimeUnit to set + */ + public void setDefaultTimeUnit(TimeUnit defaultTimeUnit) + { + this.defaultTimeUnit = defaultTimeUnit; + } + public void setPreviewDir(final String aDir) { thePreviewDir = aDir; Modified: Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -1,5 +1,6 @@ package pcgen.core; +import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteUtilities; import java.util.List; @@ -21,6 +22,7 @@ private String timesPerDay = null; private String casterLevelFormula = null; private String dcFormula = null; + private TimeUnit timeUnit = null; public PCSpell() { super(); @@ -32,6 +34,10 @@ public String getPCCText() { final StringBuffer sBuff = new StringBuffer(); sBuff.append(spellbook); + if(timeUnit != null && !timeUnit.equals("")) { + sBuff.append("|TIMEUNIT="); + sBuff.append(timeUnit.getKeyName()); + } if(timesPerDay != null && !timesPerDay.equals("")) { sBuff.append("|TIMES="); sBuff.append(timesPerDay); @@ -47,7 +53,7 @@ sBuff.append(dcFormula); } - final List preReqs = getPreReqList(); + final List<Prerequisite> preReqs = getPreReqList(); sBuff .append(PrerequisiteUtilities.getPrerequisitePCCText(preReqs, "|")); @@ -75,6 +81,24 @@ } /** + * Sets the time unit. + * + * @param timeUnit the new time unit + */ + public void setTimeUnit(TimeUnit timeUnit) + { + this.timeUnit = timeUnit; + } + + /** + * @return the timeUnit + */ + public TimeUnit getTimeUnit() + { + return timeUnit; + } + + /** * Sets the timesPerDay. * * @param timesPerDay Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -12177,6 +12177,7 @@ int times = 1; int slotLevel = 0; owner = race; + TimeUnit timeUnit = pcSpell.getTimeUnit(); if (castCount == null || castCount.equals("")) { @@ -12221,7 +12222,9 @@ } final CharacterSpell cs = new CharacterSpell(owner, aSpell); - cs.addInfo(slotLevel, times, book); + SpellInfo si = cs.addInfo(slotLevel, times, book); + si.setTimeUnit(timeUnit); + addSpellBook(new SpellBook(book, SpellBook.TYPE_INNATE_SPELLS)); owner.getSpellSupport().addCharacterSpell(cs); } Added: Trunk/pcgen/code/src/java/pcgen/core/TimeUnit.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/TimeUnit.java (rev 0) +++ Trunk/pcgen/code/src/java/pcgen/core/TimeUnit.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -0,0 +1,231 @@ +/* + * TimeUnit.java + * Copyright 2008 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 24/02/2008 + * + * $Id$ + */ +package pcgen.core; + +import pcgen.util.PropertyFactory; + +/** + * <code>TimeUnit</code> stores and manages information about Time units. + * + * <p>Used for spells currently, the time unit describes a block of time. + * This is normally used to denote how often a spell of spell like ability + * may be used e.g a number of times per day or week. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + * @since 5.13.10 + */ +public class TimeUnit implements KeyedObject +{ + + /** The display name. */ + private String theDisplayName; + + /** The key name. */ + private String theKeyName; + + /** The sort order. */ + private int theOrder; + + /** A constant used to refer to the default time unit of DAY. */ + public static final TimeUnit DAY = new TimeUnit("DAY", "in_day"); //$NON-NLS-1$ //$NON-NLS-2$ + + static + { + DAY.theOrder = 1; //$NON-NLS-1$ + } + + /** + * Constructs a new <tt>TimeUnit</tt> with the specified key. + * + * <p>This method sets the display and plural names to the same value as + * the key name. + * + * @param aKeyName The name to use to reference this time unit. + */ + public TimeUnit(final String aKeyName) + { + theKeyName = aKeyName; + theDisplayName = aKeyName; + } + + /** + * Constructor takes a key name and display name for the Time Unit. + * + * @param aKeyName The name to use to reference this time unit. + * @param aDisplayName The resource key to use for the display name + */ + public TimeUnit(final String aKeyName, final String aDisplayName) + { + theKeyName = aKeyName; + setName(aDisplayName); + } + + /** + * Get the sorting order of this time unit. + * + * @return the order + */ + int getOrder() + { + return theOrder; + } + + /** + * Set the sorting order of this time unit. + * + * @param order the order to set + */ + void setOrder(int order) + { + this.theOrder = order; + } + + // ------------------------------------------- + // KeyedObject Support + // ------------------------------------------- + /** + * Gets the display name. + * + * @return the display name + * + * @see pcgen.core.KeyedObject#getDisplayName() + */ + public String getDisplayName() + { + return theDisplayName; + } + + /** + * Gets the key name. + * + * @return the key name + * + * @see pcgen.core.KeyedObject#getKeyName() + */ + public String getKeyName() + { + return theKeyName; + } + + /** + * Sets the key name. + * + * @param aKey the a key + * + * @see pcgen.core.KeyedObject#setKeyName(java.lang.String) + */ + public void setKeyName(final String aKey) + { + theKeyName = aKey; + } + + /** + * Sets the name. + * + * @param aName the a name + * + * @see pcgen.core.KeyedObject#setName(java.lang.String) + */ + public void setName(final String aName) + { + if (aName.startsWith("in_")) + { + theDisplayName = PropertyFactory.getString(aName); + } + else + { + theDisplayName = aName; + } + } + + /** + * Returns the display name for this category. + * + * @return the string + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return theDisplayName; + } + + /** + * Generates a hash code using the key, category and types. + * + * @return the int + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + final int PRIME = 31; + int result = 1; + result = + PRIME * result + + ((theKeyName == null) ? 0 : theKeyName.hashCode()); + return result; + } + + /** + * Equals. + * + * @param obj the obj + * + * @return true, if equals + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null || getClass() != obj.getClass()) + { + return false; + } + + final TimeUnit other = (TimeUnit) obj; + if (theKeyName == null) + { + if (other.theKeyName != null) + { + return false; + } + } + else if (!theKeyName.equals(other.theKeyName)) + { + return false; + } + return true; + } +} Property changes on: Trunk/pcgen/code/src/java/pcgen/core/TimeUnit.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native Modified: Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/pcgen/core/character/SpellInfo.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -26,6 +26,7 @@ package pcgen.core.character; import pcgen.core.Globals; +import pcgen.core.TimeUnit; import java.util.ArrayList; import java.util.List; @@ -43,11 +44,15 @@ */ public final class SpellInfo { + /** The special value for number of times per unit for 'At Will' spells. */ + public static int TIMES_AT_WILL = -1; + private CharacterSpell owner; private List<Ability> featList; // a List of Feat objects private String book = Globals.getDefaultSpellBook(); // name of book private int actualLevel = -1; private int times; // times the spell is in this list + private TimeUnit timeUnit; // the timeunit the times is for (day, week etc) private int actualPPCost = -1; private int numPages = 0; @@ -115,6 +120,22 @@ return times; } + /** + * @return the timeUnit + */ + public TimeUnit getTimeUnit() + { + return timeUnit; + } + + /** + * @param timeUnit the timeUnit to set + */ + public void setTimeUnit(TimeUnit timeUnit) + { + this.timeUnit = timeUnit; + } + public final int getNumPages() { return numPages; Modified: Trunk/pcgen/code/src/java/plugin/exporttokens/SpellMemToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/exporttokens/SpellMemToken.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/plugin/exporttokens/SpellMemToken.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -209,7 +209,7 @@ } else if ("TIMES".equals(aLabel)) { - if (si.getTimes() == -1) + if (si.getTimes() == SpellInfo.TIMES_AT_WILL) { retValue.append("At Will"); } @@ -218,6 +218,10 @@ retValue.append(String.valueOf(si.getTimes())); } } + else if ("TIMEUNIT".equals(aLabel)) + { + retValue.append(String.valueOf(si.getTimeUnit())); + } else // if (aSpell != null) can't be null { Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/SpellsLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/SpellsLst.java 2008-02-24 04:35:43 UTC (rev 5271) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/SpellsLst.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -6,6 +6,8 @@ import pcgen.core.Campaign; import pcgen.core.PObject; +import pcgen.core.SettingsHandler; +import pcgen.core.TimeUnit; import pcgen.core.prereq.Prerequisite; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.GlobalLstToken; @@ -60,6 +62,7 @@ String spellBook = tok.nextToken(); String casterLevel = null; String times = "1"; + TimeUnit timeUnit = SettingsHandler.getGame().getDefaultTimeUnit(); List<String> preParseSpellList = new ArrayList<String>(); List<Prerequisite> preList = new ArrayList<Prerequisite>(); while (tok.hasMoreTokens()) @@ -85,6 +88,24 @@ } times = token.substring(6); } + else if (token.startsWith("TIMEUNIT=")) + { + if (isPre) + { + Logging.errorPrint("Invalid " + getTokenName() + ": " + sourceLine); + Logging.errorPrint(" PRExxx must be at the END of the Token"); + isPre = false; + } + String timeUnitKey = token.substring(9); + // Retrieve the time unit by key + timeUnit = SettingsHandler.getGame().getTimeUnit(timeUnitKey); + if (timeUnit == null) + { + // For now we create a new one if it isn't already present + timeUnit = new TimeUnit(timeUnitKey); + SettingsHandler.getGame().addTimeUnit(timeUnit); + } + } else if (PreParserFactory.isPreReqString(token)) { isPre = true; @@ -126,6 +147,7 @@ spell.setSpellbook(spellBook); spell.setCasterLevelFormula(casterLevel); spell.setTimesPerDay(times); + spell.setTimeUnit(timeUnit); spell.setDcFormula(dcFormula); for (Prerequisite prereq : preList) { Added: Trunk/pcgen/code/src/test/pcgen/core/TimeUnitTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/TimeUnitTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/TimeUnitTest.java 2008-02-24 05:17:35 UTC (rev 5272) @@ -0,0 +1,81 @@ +/* + * TimeUnitTest.java + * Copyright 2008 (C) James Dempsey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 24/02/2008 + * + * $Id$ + */ + +package pcgen.core; + +import junit.framework.TestCase; + +/** + * <code>TimeUnitTest</code> validates the TimeUnit functionality + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class TimeUnitTest extends TestCase +{ + + private static final int TU_SORT_ORDER = 5; + private static final String TU_KEY = "T1"; + private static final String TU_TITLE = "Test of TUs"; + + /** + * Test method for TimeUnit two field constructor. + */ + public void testTimeUnitConstructor1() + { + TimeUnit test = new TimeUnit(TU_KEY); + assertEquals("Constructor did not set key", TU_KEY, test.getKeyName()); + assertEquals("Constructor did not set name", TU_KEY, test + .getDisplayName()); + } + + /** + * Test method for TimeUnit two field constructor. + */ + public void testTimeUnitConstructor2() + { + TimeUnit test = new TimeUnit(TU_KEY, TU_TITLE); + assertEquals("Constructor did not set key", TU_KEY, test.getKeyName()); + assertEquals("Constructor did not set name", TU_TITLE, test + .getDisplayName()); + } + + /** + * Test method for TimeUnit getters and setters. + */ + public void testTimeUnitGettersAndSetters() + { + TimeUnit test = new TimeUnit("foo"); + assertEquals("Constructor did not set key", "foo", test.getKeyName()); + test.setKeyName(TU_KEY); + assertEquals("Setter did not set key", TU_KEY, test.getKeyName()); + test.setName(TU_TITLE); + assertEquals("Setter did not set displayname", TU_TITLE, test.getDisplayName()); + test.setOrder(TU_SORT_ORDER); + assertEquals("Setter did not set sort order", TU_SORT_ORDER, test.getOrder()); + } + +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/TimeUnitTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2008-02-26 03:32:19
|
Revision: 5346 http://pcgen.svn.sourceforge.net/pcgen/?rev=5346&view=rev Author: jfrazierjr Date: 2008-02-25 19:32:18 -0800 (Mon, 25 Feb 2008) Log Message: ----------- 5.13.1 Substitution Level broken More work on this. Changed how data was stored. Issue#: 1786946 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-02-26 03:04:27 UTC (rev 5345) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-02-26 03:32:18 UTC (rev 5346) @@ -162,7 +162,7 @@ private List<Description> theDescriptions = null; private DoubleKeyMap<Class, String, List<String>> qualifyKeys = null; - private List<Map<String,String>> servesAsList =null; + private HashMap<String,String> servesAsList =null; private URI sourceURI = null; @@ -5170,22 +5170,18 @@ { if (servesAsList == null) { - servesAsList = new ArrayList<Map<String,String>>(); + servesAsList = new HashMap<String,String>(); } - Map<String,String> aMap = new HashMap<String, String>(); - aMap.put(key,category); - servesAsList.add(aMap); + servesAsList.put(key,category); } - public void putServesAs( final List<Map<String,String>> sList ) + public void putServesAs( final Map<String,String> ServersAs ) { if (servesAsList == null) { - servesAsList = new ArrayList<Map<String,String>>(); + servesAsList = new HashMap<String,String>(); + return; } - else - { - servesAsList.addAll(sList); - } + servesAsList = (HashMap<String, String>) ServersAs; } public final void clearServesAs() { @@ -5193,11 +5189,11 @@ } //TODO This exposes internal structure - be careful. - public final List<Map<String,String>> getServesAs() + public final Map<String,String> getServesAs() { if (servesAsList == null) { - servesAsList = new ArrayList<Map<String,String>>(); + servesAsList = new HashMap<String,String>(); } return servesAsList; } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-02-26 03:04:27 UTC (rev 5345) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-02-26 03:32:18 UTC (rev 5346) @@ -145,25 +145,22 @@ { for(PCClass theClass: character.getClassList()) { - List<Map<String,String>> theList = theClass.getServesAs(); - for(Map<String,String> aMap : theList) + Map<String,String> theList = theClass.getServesAs(); + Set<String> keys = theList.keySet(); + for(String aKey : keys) { - Set<String> keys = aMap.keySet(); - for(String theString: keys) - { - if (theString.equalsIgnoreCase(aString)) - if (prereq.isCountMultiples()) + if (aKey.equalsIgnoreCase(aString)) + if (prereq.isCountMultiples()) + { + if (theClass.getLevel() >= preClass) { - if (theClass.getLevel() >= preClass) - { - countedTotal++; - } + countedTotal++; } - else - { - runningTotal += theClass.getLevel(); - } - } + } + else + { + runningTotal += theClass.getLevel(); + } } } } Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-02-26 03:04:27 UTC (rev 5345) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-02-26 03:32:18 UTC (rev 5346) @@ -96,10 +96,11 @@ pcClass.setName("MyClass"); pcClass.setAbbrev("My"); pcClass.putServesAs("Warrior", null); // the second parameter is for ability categories only - + pcClass.putServesAs("Ranger", null); // the second parameter is for ability categories only + final PlayerCharacter character = getCharacter(); character.incrementClassLevel(3, pcClass); - + final Prerequisite prereq = new Prerequisite(); prereq.setKind("class"); prereq.setKey("Warrior"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-03-04 12:00:07
|
Revision: 5448 http://pcgen.svn.sourceforge.net/pcgen/?rev=5448&view=rev Author: jdempsey Date: 2008-03-04 04:00:13 -0800 (Tue, 04 Mar 2008) Log Message: ----------- Freq: UI Text Clean up request Issue#: 1814803 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/HTMLUtils.java Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoClasses.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoDomain.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoEquipping.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoRaces.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoResources.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSkills.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSummary.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTempMod.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTemplates.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityInfoPanel.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoSpellsSubTab.java Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java Trunk/pcgen/code/src/test/pcgen/gui/utils/InfoLabelTextBuilderTest.java Modified: Trunk/pcgen/code/src/java/pcgen/gui/HTMLUtils.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/HTMLUtils.java 2008-03-04 04:13:41 UTC (rev 5447) +++ Trunk/pcgen/code/src/java/pcgen/gui/HTMLUtils.java 2008-03-04 12:00:13 UTC (rev 5448) @@ -60,4 +60,7 @@ /** Constant for 2 spaces in HTML */ public static final String TWO_SPACES = " "; //$NON-NLS-1$ + + /** Constant for 3 spaces in HTML */ + public static final String THREE_SPACES = " "; //$NON-NLS-1$ } Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2008-03-04 04:13:41 UTC (rev 5447) +++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2008-03-04 12:00:13 UTC (rev 5448) @@ -990,6 +990,17 @@ in_irTodoTemplates= Select a template +in_irInfoRaceType=<b>Race Type:</b> {0} + +in_irInfoSubType=\ <b>Subtypes:</b> {0} + +in_irInfoType=\ <b>Type:</b> {0} + +in_InfoRequirements=<br/><b>Requirements:</b> {0} + +in_InfoSource=<br/><b>Source:</b> {0} + + in_various=Various in_Q=Q @@ -1038,6 +1049,14 @@ in_clInfo=Class Info +in_clInfoType=<b>Type:</b> {0} + +in_clInfoHD=\ <b>HD:</b> d{0} + +in_clInfoSpellType=\ <b>Spell Type:</b> {0} + +in_clInfoBaseStat=\ <b>Base Stat:</b> {0} + in_clEnterXP=Enter XP Adjustment in_clInvalidNum=Invalid number! @@ -1203,17 +1222,17 @@ in_deityAppearance=Appearance -in_deityFavWeap=Favored Weapon +in_deityFavWeap=<b>Favored Weapon:</b> {0} -in_deityHolyIt=Holy Item +in_deityHolyIt=<b>Holy Item:</b> {0} in_deityTitle=Title -in_deityWorshippers=Typical Worshippers +in_deityWorshippers=<b>Typical Worshippers:</b> {0} -in_domainGrant=Granted Power +in_domainGrant=<b>Granted Power:</b> {0} -in_domainRequirements=Deity Domain Requirements +in_domainRequirements=<b>Deity Domain Requirements:</b> {0} in_deityButTip=Select highlighted Deity @@ -1365,18 +1384,22 @@ in_iskHidden=Hidden -in_iskHtml_EXCLUSIVE=\ <b>EXCLUSIVE</b>\u003A +in_iskHtml_EXCLUSIVE=\ <b>Exclusive\u003A</b> -in_iskHtml_KEY_STAT=\ <b>KEY STAT</b>\u003A +in_iskHtml_KEY_STAT=\ <b>Key Stat\u003A</b> -in_iskHtml_MAXRANK=\ <b>MAXRANK</b>\u003A +in_iskHtml_MAXRANK=<b>Max Rank\u003A</b> -in_iskHtml_SOURCE=\ <b>SOURCE</b>\u003A +in_iskHtml_PcMod=<br/><b>PC Modifier\u003A</b> {0} -in_iskHtml_TYPE=\ <b>TYPE</b>\u003A +in_iskHtml_Ranks=<br/><b>PC Ranks\u003A</b> {0} -in_iskHtml_UNTRAINED=\ <b>UNTRAINED</b>\u003A +in_iskHtml_SOURCE=<br/><b>Source\u003A</b> +in_iskHtml_TYPE=<b>Type\u003A</b> + +in_iskHtml_UNTRAINED=\ <b>Untrained\u003A</b> + in_iskInclude_Skills=Include Skills\u003A in_iskInvalid_number=Invalid number\! @@ -2048,7 +2071,7 @@ in_ieInfoLabelTextWield=Wield -in_ieInfoLabelTextProficient=PROFICIENT +in_ieInfoLabelTextProficient=Proficient in_ieInfoLabelTextYes=Y @@ -2058,15 +2081,15 @@ in_ieInfoLabelTextProperties=Properties -in_ieInfoLabelTextWeight=WT +in_ieInfoLabelTextWeight=Wt in_ieInfoLabelTextAC=AC -in_ieInfoLabelTextMaxDex=MAXDEX +in_ieInfoLabelTextMaxDex=Max Dex -in_ieInfoLabelTextAcCheck=ACCHECK +in_ieInfoLabelTextAcCheck=AC Check -in_ieInfoLabelTextArcaneFailure=Arcane Failure +in_ieInfoLabelTextArcaneFailure=Arcane Failure in_ieInfoLabelTextMove=Move @@ -2074,23 +2097,23 @@ in_ieInfoLabelTextDamage=Damage -in_ieInfoLabelTextCritRange=Crit Range +in_ieInfoLabelTextCritRange=Crit Range -in_ieInfoLabelTextCritMult=Crit Mult +in_ieInfoLabelTextCritMult=Crit Mult in_ieInfoLabelTextRange=Range in_ieInfoLabelTextContainer=Container -in_ieInfoLabelTextCurrentlyContains=Currently Contains +in_ieInfoLabelTextCurrentlyContains=Currently Contains -in_ieInfoLabelTextContainedValue=Contained Value +in_ieInfoLabelTextContainedValue=Contained Value in_ieInfoLabelTextCharges=Charges in_ieInfoLabelTextCost=Cost -in_ieInfoLabelTextCostSource=SOURCE +in_ieInfoLabelTextCostSource=Source in_ieBonusEditorYes=Yes @@ -2110,15 +2133,15 @@ in_itmInfoLabelTextProperties=Properties -in_itmInfoLabelTextWeight=WT +in_itmInfoLabelTextWeight=Wt in_itmInfoLabelTextAC=AC -in_itmInfoLabelTextMaxDex=MAXDEX +in_itmInfoLabelTextMaxDex=Max Dex -in_itmInfoLabelTextAcCheck=ACCHECK +in_itmInfoLabelTextAcCheck=AC Check -in_itmInfoLabelTextArcaneFailure=Arcane Failure +in_itmInfoLabelTextArcaneFailure=Arcane Failure in_itmInfoLabelTextMove=Move @@ -2126,9 +2149,9 @@ in_itmInfoLabelTextDamage=Damage -in_itmInfoLabelTextCritMult=Crit Mult +in_itmInfoLabelTextCritMult=Crit Mult -in_itmInfoLabelTextCritRange=Crit Range +in_itmInfoLabelTextCritRange=Crit Range in_itmInfoLabelTextRange=Range @@ -2243,11 +2266,11 @@ in_igMoveItemMenuDesc=Move Item To -in_igInfoLabelTextType=TYPE +in_igInfoLabelTextType=Type in_igInfoLabelTextWield=Wield -in_igInfoLabelTextProficient=PROFICIENT +in_igInfoLabelTextProficient=Proficient in_igInfoLabelTextYes=Y @@ -2257,14 +2280,16 @@ in_igInfoLabelTextProp=Properties -in_igInfoLabelTextWeight=WT +in_igInfoLabelTextWeight=Wt -in_igInfoLabelTextMaxDex=MAXDEX +in_igInfoLabelTextMaxDex=Max Dex -in_igInfoLabelTextAcCheck=ACCHECK +in_igInfoLabelTextAcCheck=AC Check -in_igInfoLabelTextArcaneFailure=Arcane Failure +in_igInfoLabelTextAcBonus={0} Bonus +in_igInfoLabelTextArcaneFailure=Arcane Failure + in_igInfoLabelTextMove=Move in_igInfoLabelTextSize=Size @@ -2283,9 +2308,9 @@ in_igInfoLabelTextCharges=Charges -in_igInfoLabelTextQualities=QUALITIES +in_igInfoLabelTextQualities=Qualities -in_igInfoLabelTextSource=SOURCE +in_igInfoLabelTextSource=Source #0 - Name of the item in_igAdjBelongStillEquiped=You can not remove all of {0} as it is still present in at least one equipment set. @@ -2786,23 +2811,23 @@ in_sumBAB=BAB -in_sumBaseStat=Base Stat\u003A +in_sumBaseStat=Base Stat in_sumClass=Class\u003A in_sumCombat=COMBAT -in_sumFavoredClass=FAVORED CLASS: +in_sumFavoredClass=Favored Class in_sumFlatfooted=Flatfooted -in_sumHD=HD\u003A +in_sumHD=HD in_sumInit=Init -in_sumLevelAdj=LEVEL ADJ\u003A +in_sumLevelAdj=Level Adj -in_sumMove=MOVE\u003A +in_sumMove=Move in_sumRace=Race\u003A @@ -2810,15 +2835,13 @@ in_sumSaves=Saves -in_sumSize1=SIZE\u003A - in_sumSize=Size -in_sumSource1=SOURCE +in_sumSource1=Source -in_sumSpelltype=SPELLTYPE\u003A +in_sumSpelltype=Spelltype -in_sumStatAdj=STAT ADJ\u003A +in_sumStatAdj=Stat Adj in_sumTodoAlign=Select an alignment. @@ -2830,9 +2853,9 @@ in_sumTouch=Touch -in_sumTYPE=TYPE +in_sumTYPE=Type -in_sumVision=VISION\u003A +in_sumVision=Vision #Preference Dialog in_Prefs_title=PCGen Preferences @@ -3531,7 +3554,7 @@ InfoSpells.prohibited.school=Prohibited School\u003A -InfoSpells.source=SOURCE\u003A +InfoSpells.source=Source\u003A InfoSpells.can.not.delete.default.spellbook=You may not delete the default spellbook @@ -3564,14 +3587,8 @@ InfoSpells.rightclick.add.to.spellbooks=Right click to add spells to your spellbooks InfoSpells.remove.selected=Click to remove selected spell from this spellbook -InfoSpellsSubTab.UsedPages=Used Pages -InfoSpellsSubTab.NumSpells=Num Spells -InfoSpellsSubTab.PPCost= <b>PP Cost</b>: -InfoSpellsSubTab.Requirements= <b>Requirements</b>: -InfoSpellsSubTab.NumPages=Num Pages -InfoSpellsSubTab.UsedPages=Used Pages -InfoSpellsSubTab.PageUse=Page Use -InfoSpellsSubTab.NumSpells=Num Spells +InfoSpellsSubTab.PPCost= <b>PP Cost</b>: +InfoSpellsSubTab.Requirements=<br/><b>Requirements</b>: InfoSpellsSubTab.FindItem=Find item InfoSpellsSubTab.SearchItem=searchItem @@ -3610,8 +3627,14 @@ InfoSpells.add.with.metamagic=Add Spell with Metamagic Feats -InfoSpells.html.spell.details=\ <b>School\u003A</b> {0} <b>SubSchool\u003A</b> {1} <b>Descriptor\u003A</b> {2} <b>Components\u003A</b> {3} <b>Casting Time\u003A</b> {4} <b>Duration\u003A</b> {5} <b>Range\u003A</b> {6} <b>Target\u003A</b> {7} <b>Saving Throw\u003A</b> {8} <b>Spell Resistance\u003A</b> {9} <b>Description\u003A</b> {10} +InfoSpells.html.spell.details=\ <b>School\u003A</b> {0} <b>SubSchool\u003A</b> {1} <b>Descriptor\u003A</b> {2} <b>Components\u003A</b> {3} <b>Casting Time\u003A</b> {4} <b>Duration\u003A</b> {5} <b>Range\u003A</b> {6} <b>Target\u003A</b> {7} <b>Saving Throw\u003A</b> {8} <b>Spell Resistance\u003A</b> {9}<br/><b>Description\u003A</b> {10} +InfoSpells.html.spell.source=<br/><b>Source\u003A</b> {0} + +InfoSpells.html.spellbook.details=<b>Num Pages\u003A</b> {0} <b>Used Pages\u003A</b> {1} <b>Page Use\u003A</b> {2} <b>Used Spells\u003A</b> {3}<br/> + +in_InfoDescription=<b>Description\u003A</b> {0} + InfoSpells.select.metamagic=Select the Metamagic feats to memorize this spell with InfoSpells.select.output.sheet=Find and select your Spell output sheet @@ -4034,9 +4057,10 @@ TreeTable.Prompt.Search=Enter the name of the item to find -Ability.Info.Cost=Cost +Ability.Info.Cost= <b>Cost:</b> {0} Ability.Info.Multiple=Can be taken more than once Ability.Info.Stacks=Stacks +Ability.Info.Benefit=<b>Cost:</b> {0} InfoAbility.Title={0} Info InfoAbility.Remaining.Label=remaining: Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoClasses.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoClasses.java 2008-03-04 04:13:41 UTC (rev 5447) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoClasses.java 2008-03-04 12:00:13 UTC (rev 5448) @@ -381,71 +381,34 @@ if (aClass != null) { StringBuffer b = new StringBuffer(); - b.append("<html><b>").append(aClass.piSubString()).append("</b>"); + b.append("<html><font size=+1><b>").append(aClass.piSubString()).append( + "</b></font><br/>"); // // Type // aString = aClass.getType(); - if (isSubClass && (aString.length() == 0)) { aString = lastClass.getType(); } + b.append(PropertyFactory.getFormattedString( + "in_clInfoType", //$NON-NLS-1$ + aString)); - b.append(" <b>").append(PropertyFactory.getString("in_type")) - .append("</b>:").append(aString); - // - // Prereqs - // - aString = aClass.preReqHTMLStrings(pc, false); - - if (isSubClass && (aString.length() == 0)) - { - aString = lastClass.preReqHTMLStrings(pc, false); - } - - if (aString.length() > 0) - { - b.append(" <b>").append( - PropertyFactory.getString("in_requirements")).append( - "</b>:").append(aString); - } - - // - // Source - // - aString = aClass.getDefaultSourceString(); - - if (isSubClass && (aString.length() == 0)) - { - aString = lastClass.getDefaultSourceString(); - } - - if (aString.length() > 0) - { - b.append(" <b>").append( - PropertyFactory.getString("in_sourceLabel")) - .append("</b>:").append(aString); - } - - // aString = getBabTitle(); - // b.append(" <b>").append(aString).append(":</b>:").append(aClass.getAttackBonusType()); - - // // Hit Die // int hitDie = aClass.getBaseHitDie(); - if (isSubClass && (hitDie == 0)) { hitDie = lastClass.getBaseHitDie(); } - if (hitDie != 0) { - b.append(" <b>HD:</b>:1d").append(hitDie); + b.append(PropertyFactory.getFormattedString( + "in_clInfoHD", //$NON-NLS-1$ + hitDie)); } if (Globals.getGameModeShowSpellTab()) @@ -459,9 +422,9 @@ aString = lastClass.getSpellType(); } - b.append(" <b>").append( - PropertyFactory.getString("in_spellType")).append("</b>:") - .append(aString); + b.append(PropertyFactory.getFormattedString( + "in_clInfoSpellType", //$NON-NLS-1$ + aString)); aString = aClass.getSpellBaseStat(); @@ -479,11 +442,48 @@ aString = lastClass.getSpellBaseStat(); } - b.append(" <b>").append( - PropertyFactory.getString("in_baseStat")).append("</b>:") - .append(aString); + b.append(PropertyFactory.getFormattedString( + "in_clInfoBaseStat", //$NON-NLS-1$ + aString)); } + // + // Prereqs + // + aString = aClass.preReqHTMLStrings(pc, false); + + if (isSubClass && (aString.length() == 0)) + { + aString = lastClass.preReqHTMLStrings(pc, false); + } + + if (aString.length() > 0) + { + b.append(PropertyFactory.getFormattedString( + "in_InfoRequirements", //$NON-NLS-1$ + aString)); + } + + // + // Source + // + aString = aClass.getDefaultSourceString(); + + if (isSubClass && (aString.length() == 0)) + { + aString = lastClass.getDefaultSourceString(); + } + + if (aString.length() > 0) + { + b.append(PropertyFactory.getFormattedString( + "in_InfoSource", //$NON-NLS-1$ + aString)); + } + + // aString = getBabTitle(); + // b.append(" <b>").append(aString).append(":</b>:").append(aClass.getAttackBonusType()); + b.append("</html>"); infoLabel.setText(b.toString()); } Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoDomain.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoDomain.java 2008-03-04 04:13:41 UTC (rev 5447) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoDomain.java 2008-03-04 12:00:13 UTC (rev 5448) @@ -27,6 +27,8 @@ */ package pcgen.gui.tabs; +import static pcgen.gui.HTMLUtils.*; + import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; @@ -353,62 +355,70 @@ if (aDeity != null) { StringBuffer infoText = - new StringBuffer().append("<html><b>").append( - aDeity.piSubString()).append("</b>"); + new StringBuffer().append(HTML).append(FONT_PLUS_1).append(BOLD).append( + aDeity.piSubString()).append(END_BOLD).append(END_FONT); String aString = aDeity.getTitle(); if (aString.length() != 0) { - infoText.append(" (").append(aString).append(")"); + infoText.append(THREE_SPACES).append("(").append(aString).append(")"); } - infoText.append(" <b>").append( - PropertyFactory.getString("in_descrip")).append("</b>:") - .append(aDeity.piDescString(pc)); + infoText.append(BR); + infoText.append(PropertyFactory.getFormattedString( + "in_InfoDescription", //$NON-NLS-1$ + aDeity.piDescString(pc))); - aString = aDeity.preReqHTMLStrings(pc, false); - + aString = aDeity.getFavoredWeapon(); if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_requirements")).append( - "</b>:").append(aString); + infoText.append(THREE_SPACES); + infoText.append(PropertyFactory.getFormattedString( + "in_deityFavWeap", //$NON-NLS-1$ + aString)); } - aString = aDeity.getFavoredWeapon(); - + aString = aDeity.getHolyItem(); if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_deityFavWeap")).append( - "</b>:").append(aString); + infoText.append(THREE_SPACES); + infoText.append(PropertyFactory.getFormattedString( + "in_deityHolyIt", //$NON-NLS-1$ + aString)); } - aString = aDeity.getHolyItem(); - + aString = aDeity.getWorshippers(); if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_deityHolyIt")) - .append("</b>:").append(aString); + infoText.append(THREE_SPACES); + infoText.append(PropertyFactory.getFormattedString( + "in_deityWorshippers", //$NON-NLS-1$ + aString)); } - aString = aDeity.getWorshippers(); - + aString = aDeity.preReqHTMLStrings(pc, false); if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_deityWorshippers")).append( - "</b>:").append(aString); + infoText.append(PropertyFactory.getFormattedString( + "in_InfoRequirements", //$NON-NLS-1$ + aString)); } - infoText.append("</html>"); + aString = aDeity.getDefaultSourceString(); + if (aString.length() > 0) + { + infoText.append(PropertyFactory.getFormattedString( + "in_InfoSource", //$NON-NLS-1$ + aString)); + } + + infoText.append(END_HTML); deityInfo.setText(infoText.toString()); } else { - deityInfo.setText(); + deityInfo.setText(HTML + END_HTML); } } @@ -419,37 +429,46 @@ */ private void setDomainInfoText(Domain aDomain, List<Prerequisite> prereqs) { - StringBuffer infoText = new StringBuffer().append("<html>"); + StringBuffer infoText = new StringBuffer().append(HTML); if (aDomain != null) { - infoText.append("<b>").append(aDomain.piSubString()); + infoText.append(FONT_PLUS_1).append(BOLD).append( + aDomain.piSubString()).append(END_BOLD).append(END_FONT); String aString = aDomain.getDescription(getPc()); - if (aString.length() != 0) { - infoText.append(" ").append( - PropertyFactory.getString("in_domainGrant")) - .append("</b>:").append(aString); + infoText.append(BR); + infoText.append(PropertyFactory.getFormattedString( + "in_domainGrant", //$NON-NLS-1$ + aString)); } aString = aDomain.preReqHTMLStrings(pc, false); - if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_requirements")).append( - "</b>:").append(aString); + infoText.append(PropertyFactory.getFormattedString( + "in_InfoRequirements", //$NON-NLS-1$ + aString)); } aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, prereqs, false); if (aString.length() != 0) { - infoText.append(" <b>").append( - PropertyFactory.getString("in_domainRequirements")).append( - "</b>:").append(aString); + infoText.append(BR); + infoText.append(PropertyFactory.getFormattedString( + "in_domainRequirements", //$NON-NLS-1$ + aString)); } + + aString = aDomain.getDefaultSourceString(); + if (aString.length() > 0) + { + infoText.append(PropertyFactory.getFormattedString( + "in_InfoSource", //$NON-NLS-1$ + aString)); + } } Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoEquipping.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoEquipping.java 2008-03-04 04:13:41 UTC (rev 5447) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoEquipping.java 2008-03-04 12:00:13 UTC (rev 5448) @@ -116,6 +116,7 @@ import pcgen.gui.CharacterInfo; import pcgen.gui.CharacterInfoTab; import pcgen.gui.GuiConstants; +import pcgen.gui.HTMLUtils; import pcgen.gui.PCGen_Frame1; import pcgen.gui.TableColumnManager; import pcgen.gui.TableColumnManagerModel; @@ -126,6 +127,7 @@ import pcgen.gui.utils.AbstractTreeTableModel; import pcgen.gui.utils.ClickHandler; import pcgen.gui.utils.IconUtilitities; +import pcgen.gui.utils.InfoLabelTextBuilder; import pcgen.gui.utils.JComboBoxEx; import pcgen.gui.utils.JLabelPane; import pcgen.gui.utils.JTreeTable; @@ -612,17 +614,16 @@ if (eqI != null) { - //TODO:gorm optimize the initial capacity - StringBuffer b = new StringBuffer(300); - b.append("<html><font size=+1><b>").append(eqI.piSubString()) - .append("</b></font>"); - + StringBuffer title = new StringBuffer(40); + title.append(eqI.piSubString()); if (!eqI.longName().equals(eqI.getName())) { - b.append("(").append(eqI.longName()).append(")"); + title.append("(").append(eqI.longName()).append(")"); } + final InfoLabelTextBuilder b = new InfoLabelTextBuilder(title.toString()); - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextType")).append("</b>: ").append(eqI.getType()); + b.appendLineBreak(); + b.appendI18nElement("in_ieInfoLabelTextType",eqI.getType()); //$NON-NLS-1$ // // Should only be meaningful for weapons, but if included on some other piece of @@ -631,7 +632,8 @@ if (eqI.isWeapon() || eqI.hasWield()) { WieldCategory wCat = eqI.getEffectiveWieldCategory(pc); - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextWield")).append("</b>: ").append(wCat.getName()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextWield",wCat.getName()); //$NON-NLS-1$ } // @@ -639,51 +641,44 @@ // if (eqI.isWeapon() || eqI.isArmor() || eqI.isShield()) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextProficient")).append("</b>:").append( - ((pc.isProficientWith(eqI) && eqI.meetsPreReqs(pc)) ? PropertyFactory.getString("in_ieInfoLabelTextYes") - : (SettingsHandler.getPrereqFailColorAsHtmlStart() - + PropertyFactory.getString("in_ieInfoLabelTextNo") + SettingsHandler - .getPrereqFailColorAsHtmlEnd()))); + b.appendSpacer(); + b.appendI18nElement( + "in_ieInfoLabelTextProficient", + ((pc.isProficientWith(eqI) && eqI.meetsPreReqs(pc)) + ? PropertyFactory + .getString("in_ieInfoLabelTextYes") + : (SettingsHandler.getPrereqFailColorAsHtmlStart() + + PropertyFactory + .getString("in_ieInfoLabelTextNo") + SettingsHandler + .getPrereqFailColorAsHtmlEnd()))); } - final String cString = eqI.preReqHTMLStrings(pc, false); - - if (cString.length() > 0) - { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextRequirements")).append("</b>:").append(cString); - } - - String IDS = eqI.getInterestingDisplayString(pc); - - if (IDS.length() > 0) - { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextProperties")).append("</b>:").append( - eqI.getInterestingDisplayString(pc)); - } - String bString = Globals.getGameModeUnitSet().displayWeightInUnitSet( eqI.getWeight(pc).doubleValue()); - if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextWeight")).append("</b>:").append(bString).append( - Globals.getGameModeUnitSet().getWeightUnit()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextWeight",bString); //$NON-NLS-1$ + b.append(Globals.getGameModeUnitSet().getWeightUnit()); } Integer a = eqI.getACBonus(pc); - if (a.intValue() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextAC")).append("</b>:").append(a.toString()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextAC",a.toString()); //$NON-NLS-1$ } if (eqI.isArmor() || eqI.isShield()) { a = eqI.getMaxDex(pc); - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextMaxDex")).append("</b>:").append(a.toString()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextMaxDex",a.toString()); //$NON-NLS-1$ + a = eqI.acCheck(pc); - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextAcCheck")).append("</b>:").append(a.toString()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextAcCheck",a.toString()); //$NON-NLS-1$ } if (Globals.getGameModeShowSpellTab()) @@ -692,7 +687,8 @@ if (eqI.isArmor() || eqI.isShield() || (a.intValue() != 0)) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextArcaneFailure")).append("</b>:").append(a.toString()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextArcaneFailure",a.toString()); //$NON-NLS-1$ } } @@ -704,8 +700,8 @@ if (eqI.isArmor() || eqI.isShield() || (a.intValue() != 0)) { - b.append(" <b>").append(bString).append("</b>:").append( - a.toString()); + b.appendSpacer(); + b.appendElement(bString, a.toString()); } } @@ -713,21 +709,24 @@ if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextMove")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextMove",bString); //$NON-NLS-1$ } bString = eqI.getSize(); if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextSize")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextSize",bString); //$NON-NLS-1$ } bString = eqI.getDamage(pc); if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextDamage")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextDamage",bString); //$NON-NLS-1$ if (eqI.isDouble()) { @@ -739,7 +738,8 @@ if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCritRange")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextCritRange",bString); //$NON-NLS-1$ if (eqI.isDouble() && !eqI.getCritRange(pc).equals(eqI.getAltCritRange(pc))) @@ -752,7 +752,8 @@ if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCritMult")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextCritMult",bString); //$NON-NLS-1$ if (eqI.isDouble() && !(eqI.getCritMultiplier() == eqI.getAltCritMultiplier())) @@ -769,50 +770,67 @@ if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextRange")).append("</b>:").append(bString).append( - Globals.getGameModeUnitSet().getDistanceUnit()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextRange",bString); //$NON-NLS-1$ } } + final int charges = eqI.getRemainingCharges(); + + if (charges >= 0) + { + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextCharges",String.valueOf(charges)); //$NON-NLS-1$ + } + + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextCost",eqI.getCost(pc).toString()); //$NON-NLS-1$ + b.append(Globals.getCurrencyDisplay()); + + String IDS = eqI.getInterestingDisplayString(pc); + if (IDS.length() > 0) + { + b.appendLineBreak(); + b.appendI18nElement("in_ieInfoLabelTextProperties",IDS); //$NON-NLS-1$ + } + bString = eqI.getContainerCapacityString(); - if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextContainer")).append("</b>:").append(bString); + b.appendLineBreak(); + b.appendI18nElement("in_ieInfoLabelTextContainer",bString); //$NON-NLS-1$ } bString = eqI.getContainerContentsString(); - if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCurrentlyContains")).append("</b>:").append(bString); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextCurrentlyContains",bString); //$NON-NLS-1$ BigDecimal d = new BigDecimal(String .valueOf(eqI.getContainedValue(pc))); String aVal = BigDecimalHelper.formatBigDecimal(d, 2).toString(); - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextContainedValue")).append("</b>:").append(aVal).append( - Globals.getCurrencyDisplay()); + b.appendSpacer(); + b.appendI18nElement("in_ieInfoLabelTextContainedValue",aVal); //$NON-NLS-1$ + b.append(Globals.getCurrencyDisplay()); } - final int charges = eqI.getRemainingCharges(); - - if (charges >= 0) + final String cString = eqI.preReqHTMLStrings(pc, false); + if (cString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCharges")).append("</b>:").append(charges); + b.appendLineBreak(); + b.appendI18nElement("in_ieInfoLabelTextRequirements",cString); //$NON-NLS-1$ } - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCost")).append("</b>:").append(eqI.getCost(pc)); - bString = eqI.getDefaultSourceString(); - if (bString.length() > 0) { - b.append(" <b>").append(PropertyFactory.getString("in_ieInfoLabelTextCostSource")).append("</b>: ").append(bString); + b.appendLineBreak(); + b.appendI18nElement("in_ieInfoLabelTextCostSource",bString); //$... [truncated message content] |
From: <th...@us...> - 2008-03-07 03:53:16
|
Revision: 5479 http://pcgen.svn.sourceforge.net/pcgen/?rev=5479&view=rev Author: thpr Date: 2008-03-06 19:53:22 -0800 (Thu, 06 Mar 2008) Log Message: ----------- [ 1909249 ] PRESHIELDPROF Assumes count = 1 Issue#: 1909249 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreShieldProfWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreShieldProfRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreShieldProfWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreShieldProfWriter.java 2008-03-07 02:55:40 UTC (rev 5478) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreShieldProfWriter.java 2008-03-07 03:53:22 UTC (rev 5479) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; public class PreShieldProfWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface @@ -73,7 +74,10 @@ writer.write('!'); } - writer.write("PRESHIELDPROF:" + (prereq.isOverrideQualify() ? "Q:":"") + "1,"); + writer.write("PRESHIELDPROF:" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + writer.write(','); writer.write(prereq.getKey()); } catch (IOException e) @@ -82,4 +86,66 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + if (PrerequisiteOperator.LT.equals(prereq.getOperator())) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + for (Prerequisite p : prereqList) + { + writer.write(','); + writer.write(p.getKey()); + } + return true; + } + return false; + } + + } Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 02:55:40 UTC (rev 5478) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 03:53:22 UTC (rev 5479) @@ -164,7 +164,7 @@ "PREREGION:Slithe (Barrows)", "PREREGION:Slithe (Barrows)", "PRERULE:SYS_WTPSK", "PRERULE:1,SYS_WTPSK", "PRESA:1,Turn undead,Rebuke undead,Smite Evil", "PREMULT:1,[PRESA:1,Turn undead],[PRESA:1,Rebuke undead],[PRESA:1,Smite Evil]", - "PRESHIELDPROF:1,Buckler,Large Shield", "PREMULT:1,[PRESHIELDPROF:1,Buckler],[PRESHIELDPROF:1,Large Shield]", + "PRESHIELDPROF:1,Buckler,Large Shield", "PRESHIELDPROF:1,Buckler,Large Shield", "PREARMORPROF:1,TYPE.Tower", "PREARMORPROF:1,TYPE.Tower", "PRESIZEEQ:H", "PRESIZEEQ:H", "PRESKILL:1,Spot,Listen=10", "PREMULT:1,[PRESKILL:1,Spot=10],[PRESKILL:1,Listen=10]", Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreShieldProfRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreShieldProfRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreShieldProfRoundRobin.java 2008-03-07 03:53:22 UTC (rev 5479) @@ -0,0 +1,43 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreShieldProfParser; +import plugin.pretokens.writer.PreShieldProfWriter; + +public class PreShieldProfRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreShieldProfRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreShieldProfRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreShieldProfParser()); + TokenRegistration.register(new PreShieldProfWriter()); + } + + @Override + public String getBaseString() + { + return "SHIELDPROF"; + } + + @Override + public boolean isTypeAllowed() + { + return true; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-07 03:55:14
|
Revision: 5480 http://pcgen.svn.sourceforge.net/pcgen/?rev=5480&view=rev Author: thpr Date: 2008-03-06 19:55:19 -0800 (Thu, 06 Mar 2008) Log Message: ----------- [ 1909251 ] PREWEAPONPROF assumes count=1 Issue#: 1909251 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWeaponProfWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreWeaponProfRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWeaponProfWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWeaponProfWriter.java 2008-03-07 03:53:22 UTC (rev 5479) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWeaponProfWriter.java 2008-03-07 03:55:19 UTC (rev 5480) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; /** * Does the writing of the PREWEAPONPROF token @@ -76,8 +77,10 @@ writer.write('!'); } - writer.write("PREWEAPONPROF:" + (prereq.isOverrideQualify() ? "Q:":"") + "1,"); - // writer.write(prereq.getKey() + "=" + prereq.getOperand() ); + writer.write("PREWEAPONPROF:" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + writer.write(','); writer.write(prereq.getKey()); } catch (IOException e) @@ -86,4 +89,65 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + if (PrerequisiteOperator.LT.equals(prereq.getOperator())) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + for (Prerequisite p : prereqList) + { + writer.write(','); + writer.write(p.getKey()); + } + return true; + } + return false; + } + } Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 03:53:22 UTC (rev 5479) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 03:55:19 UTC (rev 5480) @@ -199,9 +199,9 @@ "PREVARGT:SneakAttack,5,Rage,4", "PREMULT:2,[PREVARGT:SneakAttack,5],[PREVARGT:Rage,4]", "PREVISION:2,Normal,Darkvision", "PREMULT:2,[PREVISION:1,Normal=1],[PREVISION:1,Darkvision=1]", "PREVISION:1,Blindsight,Darkvision=30", "PREMULT:1,[PREVISION:1,Blindsight=30],[PREVISION:1,Darkvision=30]", - "PREWEAPONPROF:2,Kama,Katana", "PREMULT:2,[PREWEAPONPROF:1,Kama],[PREWEAPONPROF:1,Katana]", + "PREWEAPONPROF:2,Kama,Katana", "PREWEAPONPROF:2,Kama,Katana", "PREWEAPONPROF:1,TYPE.Exotic", "PREWEAPONPROF:1,TYPE.Exotic", - "PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)", "PREMULT:1,[PREWEAPONPROF:1,TYPE.Martial],[PREWEAPONPROF:1,Chain (Spiked)]", + "PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)", "PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)", "PREWEAPONPROF:1,DEITYWEAPON", "PREWEAPONPROF:1,DEITYWEAPON", "PREWIELD:1,Light,OneHanded", "PREMULT:1,[PREWIELD:1,Light],[PREWIELD:1,OneHanded]", "PREWIELD:1,TwoHanded", "PREWIELD:1,TwoHanded", Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreWeaponProfRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreWeaponProfRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreWeaponProfRoundRobin.java 2008-03-07 03:55:19 UTC (rev 5480) @@ -0,0 +1,48 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreWeaponProfParser; +import plugin.pretokens.writer.PreWeaponProfWriter; + +public class PreWeaponProfRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreWeaponProfRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreWeaponProfRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreWeaponProfParser()); + TokenRegistration.register(new PreWeaponProfWriter()); + } + + @Override + public String getBaseString() + { + return "WEAPONPROF"; + } + + @Override + public boolean isTypeAllowed() + { + return true; + } + + public void testDeityWeapon() + { + this.runRoundRobin("PREWEAPONPROF:1,DEITYWEAPON"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-07 04:40:05
|
Revision: 5481 http://pcgen.svn.sourceforge.net/pcgen/?rev=5481&view=rev Author: thpr Date: 2008-03-06 20:40:11 -0800 (Thu, 06 Mar 2008) Log Message: ----------- Round Robin: PRETEMPLATE, PRETYPE, PREWIELD, PRETEXT, PREUATT Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTemplateWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTypeWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWieldWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreTemplateRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/PreTextRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/PreTypeRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/PreUnarmedAttackRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/PreWieldRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTemplateWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTemplateWriter.java 2008-03-07 03:55:19 UTC (rev 5480) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTemplateWriter.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; /** * Writes PRETEMPLATE token @@ -85,4 +86,64 @@ } } + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + if (PrerequisiteOperator.LT.equals(prereq.getOperator())) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + for (Prerequisite p : prereqList) + { + writer.write(','); + writer.write(p.getKey()); + } + return true; + } + return false; + } + } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTypeWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTypeWriter.java 2008-03-07 03:55:19 UTC (rev 5480) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTypeWriter.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; /** * Writes PRETYPE token @@ -85,4 +86,64 @@ } } + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + if (PrerequisiteOperator.LT.equals(prereq.getOperator())) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + for (Prerequisite p : prereqList) + { + writer.write(','); + writer.write(p.getKey()); + } + return true; + } + return false; + } + } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWieldWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWieldWriter.java 2008-03-07 03:55:19 UTC (rev 5480) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWieldWriter.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; /** * Performs the writing for the PREWIELD tag @@ -85,4 +86,65 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + if (PrerequisiteOperator.LT.equals(prereq.getOperator())) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + writer.write(prereq.getOperand()); + for (Prerequisite p : prereqList) + { + writer.write(','); + writer.write(p.getKey()); + } + return true; + } + return false; + } + } Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 03:55:19 UTC (rev 5480) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -189,10 +189,10 @@ "PRESTAT:1,STR=15,WIS=13", "PREMULT:1,[PRESTAT:1,STR=15],[PRESTAT:1,WIS=13]", "PRESTAT:2,STR=13,INT=10,CHA=13", "PREMULT:2,[PRESTAT:1,STR=13],[PRESTAT:1,INT=10],[PRESTAT:1,CHA=13]", "PRESUBCLASS:1,Evoker,Abjurer,Enchanter,Illusionist", "PREMULT:1,[PRESUBCLASS:1,Evoker],[PRESUBCLASS:1,Abjurer],[PRESUBCLASS:1,Enchanter],[PRESUBCLASS:1,Illusionist]", - "PRETEMPLATE:Celestial,Fiendish", "PREMULT:1,[PRETEMPLATE:1,Celestial],[PRETEMPLATE:1,Fiendish]", + "PRETEMPLATE:Celestial,Fiendish", "PRETEMPLATE:1,Celestial,Fiendish", "PRETEXT:Character must make a sacrifice of bananas to the Monkey God", "PRETEXT:Character must make a sacrifice of bananas to the Monkey God", - "PRETYPE:1,Elemental,Fey,Outsider", "PREMULT:1,[PRETYPE:1,Elemental],[PRETYPE:1,Fey],[PRETYPE:1,Outsider]", - "PRETYPE:2,Humanoid,Undead", "PREMULT:2,[PRETYPE:1,Humanoid],[PRETYPE:1,Undead]", + "PRETYPE:1,Elemental,Fey,Outsider", "PRETYPE:1,Elemental,Fey,Outsider", + "PRETYPE:2,Humanoid,Undead", "PRETYPE:2,Humanoid,Undead", "PREUATT:4", "PREUATT:4", "PREVARGT:Rage,4", "PREVARGT:Rage,4", "PREVARGT:SneakAttack,5", "PREVARGT:SneakAttack,5", @@ -203,7 +203,7 @@ "PREWEAPONPROF:1,TYPE.Exotic", "PREWEAPONPROF:1,TYPE.Exotic", "PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)", "PREWEAPONPROF:1,TYPE.Martial,Chain (Spiked)", "PREWEAPONPROF:1,DEITYWEAPON", "PREWEAPONPROF:1,DEITYWEAPON", - "PREWIELD:1,Light,OneHanded", "PREMULT:1,[PREWIELD:1,Light],[PREWIELD:1,OneHanded]", + "PREWIELD:1,Light,OneHanded", "PREWIELD:1,Light,OneHanded", "PREWIELD:1,TwoHanded", "PREWIELD:1,TwoHanded", "PREWIELD:Q:1,TwoHanded", "PREWIELD:Q:1,TwoHanded", @@ -372,8 +372,8 @@ "PREVAREQ:TL,CL", "PREVAREQ:TL,CL", "PREVAREQ:TL,(CL=Barbarian+CL=Ex Barbarian)", "PREVAREQ:TL,(CL=Barbarian+CL=Ex Barbarian)", "PREVARLT:ENCUMBERANCE,2", "PREVARLT:ENCUMBERANCE,2", - "PRETYPE:type1,type2|type3,[type4]", "PREMULT:3,[PRETYPE:1,type1],[PREMULT:1,[PRETYPE:1,type2],[PRETYPE:1,type3]],[!PRETYPE:1,type4]", - "PREMULT:3,[PRETYPE:1,type1],[PRETYPE:1,type2,type3],[!PRETYPE:1,type4]", "PREMULT:3,[PRETYPE:1,type1],[PREMULT:1,[PRETYPE:1,type2],[PRETYPE:1,type3]],[!PRETYPE:1,type4]", + "PRETYPE:type1,type2|type3,[type4]", "PREMULT:3,[PRETYPE:1,type1],[PRETYPE:1,type2,type3],[!PRETYPE:1,type4]", + "PREMULT:3,[PRETYPE:1,type1],[PRETYPE:1,type2,type3],[!PRETYPE:1,type4]", "PREMULT:3,[PRETYPE:1,type1],[PRETYPE:1,type2,type3],[!PRETYPE:1,type4]", "PRETYPE:1,Animal", "PRETYPE:1,Animal", "!PRETYPE:1,Animal", "!PRETYPE:1,Animal", // From PrerequisiteApplyWriterTest.java Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreTemplateRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreTemplateRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreTemplateRoundRobin.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -0,0 +1,44 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreTemplateParser; +import plugin.pretokens.writer.PreTemplateWriter; + +public class PreTemplateRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreTemplateRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreTemplateRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreTemplateParser()); + TokenRegistration.register(new PreTemplateWriter()); + } + + @Override + public String getBaseString() + { + return "TEMPLATE"; + } + + @Override + public boolean isTypeAllowed() + { + return false; + } + +} Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreTextRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreTextRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreTextRoundRobin.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -0,0 +1,39 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreTextParser; +import plugin.pretokens.writer.PreTextWriter; + +public class PreTextRoundRobin extends AbstractStringRoundRobin +{ + + public static void main(String args[]) + { + TestRunner.run(PreTextRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreTextRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreTextParser()); + TokenRegistration.register(new PreTextWriter()); + } + + @Override + public String getBaseString() + { + return "TEXT"; + } + +} Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreTypeRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreTypeRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreTypeRoundRobin.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -0,0 +1,43 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreTypeParser; +import plugin.pretokens.writer.PreTypeWriter; + +public class PreTypeRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreTypeRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreTypeRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreTypeParser()); + TokenRegistration.register(new PreTypeWriter()); + } + + @Override + public String getBaseString() + { + return "TYPE"; + } + + @Override + public boolean isTypeAllowed() + { + return false; + } +} Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreUnarmedAttackRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreUnarmedAttackRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreUnarmedAttackRoundRobin.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -0,0 +1,73 @@ +/* + * PreAbilityParserTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on January 23, 2006 + * + * Current Ver: $Revision: 1777 $ + * Last Editor: $Author: jdempsey $ + * Last Edited: $Date: 2006-12-17 15:36:01 +1100 (Sun, 17 Dec 2006) $ + * + */ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreUnarmedAttackParser; +import plugin.pretokens.writer.PreUnarmedAttackWriter; + +/** + * <code>PreAbilityParserTest</code> tests the function of the PREABILITY + * parser. + * + * Last Editor: $Author: jdempsey $ Last Edited: $Date: 2006-12-17 15:36:01 + * +1100 (Sun, 17 Dec 2006) $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: 1777 $ + */ +public class PreUnarmedAttackRoundRobin extends AbstractIntegerRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreUnarmedAttackRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreUnarmedAttackRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreUnarmedAttackParser()); + TokenRegistration.register(new PreUnarmedAttackWriter()); + } + + @Override + public String getBaseString() + { + return "UATT"; + } + +} \ No newline at end of file Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreWieldRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreWieldRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreWieldRoundRobin.java 2008-03-07 04:40:11 UTC (rev 5481) @@ -0,0 +1,43 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreWieldParser; +import plugin.pretokens.writer.PreWieldWriter; + +public class PreWieldRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreWieldRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreWieldRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreWieldParser()); + TokenRegistration.register(new PreWieldWriter()); + } + + @Override + public String getBaseString() + { + return "WIELD"; + } + + @Override + public boolean isTypeAllowed() + { + return false; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-07 22:26:14
|
Revision: 5492 http://pcgen.svn.sourceforge.net/pcgen/?rev=5492&view=rev Author: thpr Date: 2008-03-07 14:26:20 -0800 (Fri, 07 Mar 2008) Log Message: ----------- [ 1909834 ] PREEQUIP* assumes 1 [ 1909833 ] PREITEM assumes 1, [ 1909831 ] PREAMOR* assumes 1, Issue#: 1909834 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/persistence/lst/output/prereq/AbstractPrerequisiteWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLanguageParser.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorProfWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorTypeWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCSkillWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckBaseWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreClassWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityDomainWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDomainWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipBothWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipPrimaryWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipSecondaryWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipTwoWeaponWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreItemWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreLanguageWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreMoveWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreRaceWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreShieldProfWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSkillWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSpellDescriptorWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSpellSchoolSubWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSpellSchoolWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSpellTypeWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSpellWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreSubClassWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTemplateWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreTypeWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreVisionWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWeaponProfWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreWieldWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Trunk/pcgen/code/src/test/plugin/pretokens/AbstractBasicRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/AbstractPreRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/AbstractRankedRoundRobin.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/AbstractMinMaxRoundRobin.java Modified: Trunk/pcgen/code/src/java/pcgen/persistence/lst/output/prereq/AbstractPrerequisiteWriter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/persistence/lst/output/prereq/AbstractPrerequisiteWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/pcgen/persistence/lst/output/prereq/AbstractPrerequisiteWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -35,6 +35,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; /** * This class handles writing pre reqs for LST Tokens @@ -119,4 +120,69 @@ throw new IOException(); } } + + protected PrerequisiteOperator getConsolidateMethod(String handled, + Prerequisite prereq, boolean ranked) + { + // If this is NOT a PREMULT... fail + if (prereq.getKind() != null) + { + return null; + } + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!ranked && !"1".equals(p.getOperand())) + { + return null; + } + // + // ...with all PREARMORTYPE entries... + // + if (!handled.equalsIgnoreCase(p.getKind())) + { + return null; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return null; + } + } + } + String count = prereq.getOperand(); + if (PrerequisiteOperator.LT.equals(oper)) + { + try + { + int i = Integer.parseInt(count); + if (prereqList.size() != i) + { + return null; + } + } + catch (NumberFormatException e) + { + return null; + } + } + else if (!PrerequisiteOperator.GTEQ.equals(oper)) + { + // TODO Not sure whether these can be consolidated... + return null; + } + return oper; + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLanguageParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLanguageParser.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLanguageParser.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -29,7 +29,6 @@ package plugin.pretokens.parser; import pcgen.core.prereq.Prerequisite; -import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.prereq.AbstractPrerequisiteListParser; import pcgen.persistence.lst.prereq.PrerequisiteParserInterface; @@ -69,7 +68,6 @@ { for (Prerequisite element : prereq.getPrerequisites()) { - element.setOperator(PrerequisiteOperator.EQ); if (element.getKey().equalsIgnoreCase("ANY")) { element.setCountMultiples(true); Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorProfWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorProfWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorProfWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - /** * Writer for PREARMORPROF */ @@ -90,60 +89,26 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorTypeWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorTypeWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreArmorTypeWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - /** * Writer for PREARMORTYPE */ @@ -96,60 +95,26 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCSkillWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCSkillWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCSkillWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - public class PreCSkillWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -94,59 +93,25 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled().toUpperCase() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckBaseWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckBaseWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckBaseWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,15 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; - /** * Writer for PRECHECKBASE */ @@ -86,4 +86,32 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true); + 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()); + writer.write('='); + writer.write(p.getOperand()); + } + return true; + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreCheckWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,15 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; - /** * Writer for PRECHECK */ @@ -86,4 +86,32 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true); + 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()); + writer.write('='); + writer.write(p.getOperand()); + } + return true; + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreClassWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreClassWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreClassWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,15 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; - public class PreClassWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -84,4 +84,32 @@ } } + + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, true); + 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()); + writer.write('='); + writer.write(p.getOperand()); + } + return true; + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityDomainWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityDomainWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityDomainWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - public class PreDeityDomainWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -87,59 +86,25 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled().toUpperCase() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - public class PreDeityWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -55,9 +54,8 @@ */ public PrerequisiteOperator[] operatorsHandled() { - return new PrerequisiteOperator[]{PrerequisiteOperator.EQ, - PrerequisiteOperator.GTEQ, PrerequisiteOperator.LT, - PrerequisiteOperator.NEQ}; + return new PrerequisiteOperator[] { PrerequisiteOperator.GTEQ, + PrerequisiteOperator.LT }; } /* (non-Javadoc) @@ -92,59 +90,25 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled().toUpperCase() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDomainWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDomainWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDomainWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - public class PreDomainWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -92,59 +91,25 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled().toUpperCase() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipBothWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipBothWriter.java 2008-03-07 17:55:57 UTC (rev 5491) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipBothWriter.java 2008-03-07 22:26:20 UTC (rev 5492) @@ -28,16 +28,15 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; -import java.util.List; - public class PreEquipBothWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface { @@ -88,59 +87,25 @@ public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException { - // - // If this is a PREMULT... - // - if (prereq.getKind() == null) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - List<Prerequisite> prereqList = prereq.getPrerequisites(); - PrerequisiteOperator oper = null; - for (Prerequisite p : prereqList) - { - // - // ...testing one item... - // - if (!"1".equals(p.getOperand())) - { - return false; - } - // - // ...with all PREARMORTYPE entries... - // - if (!kindHandled().equalsIgnoreCase(p.getKind())) - { - return false; - } - // - // ...and the same operator... - // - if (oper == null) - { - oper = p.getOperator(); - } - else - { - if (!oper.equals(p.getOperator())) - { - return false; - } - } - } - if (PrerequisiteOperator.LT.equals(prereq.getOperator())) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PRE" + kindHandled().toUpperCase() + ":" - + (prereq.isOverrideQualify() ? "Q:" : "")); - writer.write(prereq.getOperand()); - for (Prerequisite p : prereqList) - { - writer.write(','); - writer.write(p.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreEquipPrimaryWriter.java ====... [truncated message content] |
From: <th...@us...> - 2008-03-08 00:38:18
|
Revision: 5502 http://pcgen.svn.sourceforge.net/pcgen/?rev=5502&view=rev Author: thpr Date: 2008-03-07 16:38:24 -0800 (Fri, 07 Mar 2008) Log Message: ----------- Additional PRExxx Round Robin tests Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreAlignWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityAlignWriter.java Trunk/pcgen/code/src/test/pcgen/AbstractCharacterTestCase.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Trunk/pcgen/code/src/test/plugin/pretokens/AbstractAlignRoundRobin.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreAlignRoundRobin.java Trunk/pcgen/code/src/test/plugin/pretokens/PreDeityAlignRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreAlignWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreAlignWriter.java 2008-03-08 00:05:07 UTC (rev 5501) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreAlignWriter.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; public class PreAlignWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface @@ -80,4 +81,86 @@ } } + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // If this is NOT a PREMULT... fail + if (prereq.getKind() != null) + { + return false; + } + List<Prerequisite> prereqList = prereq.getPrerequisites(); + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...testing one item... + // + if (!"1".equals(p.getOperand())) + { + return false; + } + // + // ...with all PREARMORTYPE entries... + // + if (!kindHandled().equalsIgnoreCase(p.getKind())) + { + return false; + } + // + // ...and the same operator... + // + if (oper == null) + { + oper = p.getOperator(); + } + else + { + if (!oper.equals(p.getOperator())) + { + return false; + } + } + } + String count = prereq.getOperand(); + if (PrerequisiteOperator.NEQ.equals(oper)) + { + try + { + int i = Integer.parseInt(count); + if (prereqList.size() != i) + { + return false; + } + } + catch (NumberFormatException e) + { + return false; + } + } + else if (!PrerequisiteOperator.EQ.equals(oper)) + { + return false; + } + if (!PrerequisiteOperator.GTEQ.equals(prereq.getOperator()) + ^ !PrerequisiteOperator.EQ.equals(oper)) + { + writer.write('!'); + } + + writer.write("PRE" + kindHandled().toUpperCase() + ":" + + (prereq.isOverrideQualify() ? "Q:" : "")); + boolean first = true; + for (Prerequisite p : prereq.getPrerequisites()) + { + if (!first) + { + writer.write(','); + } + writer.write(p.getKey()); + first = false; + } + return true; + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityAlignWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityAlignWriter.java 2008-03-08 00:05:07 UTC (rev 5501) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreDeityAlignWriter.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -96,7 +96,6 @@ PrerequisiteOperator oper = null; for (Prerequisite p : prereqList) { - System.err.println(p + " " + p.getKey()); // // ...with all PREARMORTYPE entries... // Modified: Trunk/pcgen/code/src/test/pcgen/AbstractCharacterTestCase.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/AbstractCharacterTestCase.java 2008-03-08 00:05:07 UTC (rev 5501) +++ Trunk/pcgen/code/src/test/pcgen/AbstractCharacterTestCase.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -122,7 +122,7 @@ super(name); } - private PCAlignment createAlignment(final String longName, + public static PCAlignment createAlignment(final String longName, final String shortName) { final PCAlignment align = new PCAlignment(); Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-08 00:05:07 UTC (rev 5501) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -79,9 +79,9 @@ // Examples from the PCGen documentation - note that there are two columns for each entry below // "PREABILITY:1,CATEGORY=Special Attack,Sneak Attack", "PREABILITY:1,CHECKMULT,CATEGORY=Special Attack,Sneak Attack", - "PREALIGN:LG,NG,CG", "PREMULT:1,[PREALIGN:LG],[PREALIGN:NG],[PREALIGN:CG]", - "PREALIGN:2,5,8", "PREMULT:1,[PREALIGN:LE],[PREALIGN:NE],[PREALIGN:CE]", - "PREALIGN:LG,Deity", "PREMULT:1,[PREALIGN:LG],[PREALIGN:Deity]", + "PREALIGN:LG,NG,CG", "PREALIGN:LG,NG,CG", + "PREALIGN:2,5,8", "PREALIGN:LE,NE,CE", + "PREALIGN:LG,Deity", "PREALIGN:LG,Deity", "PREAPPLY:ANYPC", "PREAPPLY:ANYPC", "PREAPPLY:PC", "PREAPPLY:PC", "PREAPPLY:Ranged;Melee", "PREAPPLY:Ranged;Melee", Modified: Trunk/pcgen/code/src/test/plugin/pretokens/AbstractAlignRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/AbstractAlignRoundRobin.java 2008-03-08 00:05:07 UTC (rev 5501) +++ Trunk/pcgen/code/src/test/plugin/pretokens/AbstractAlignRoundRobin.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -25,7 +25,6 @@ */ package plugin.pretokens; - /** * <code>PreAbilityParserTest</code> tests the function of the PREABILITY * parser. @@ -39,7 +38,7 @@ public abstract class AbstractAlignRoundRobin extends AbstractPreRoundRobin { public abstract String getBaseString(); - + public void testSimple() { runRoundRobin("PRE" + getBaseString() + ":LG"); @@ -52,12 +51,18 @@ public void testNumber() { - runRoundRobin("PRE" + getBaseString() + ":3"); + runSimpleRoundRobin("PRE" + getBaseString() + ":3", "PRE" + + getBaseString() + ":NG"); + runSimpleRoundRobin("!PRE" + getBaseString() + ":3", "!PRE" + + getBaseString() + ":NG"); } public void testNumberMultiple() { - runRoundRobin("PRE" + getBaseString() + ":3,4,5"); + runSimpleRoundRobin("PRE" + getBaseString() + ":3,4,5", "PRE" + + getBaseString() + ":NG,TN,NE"); + runSimpleRoundRobin("!PRE" + getBaseString() + ":3,4,5", "!PRE" + + getBaseString() + ":NG,TN,NE"); } } \ No newline at end of file Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreAlignRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreAlignRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreAlignRoundRobin.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -0,0 +1,104 @@ +/* + * PreAbilityParserTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on January 23, 2006 + * + * Current Ver: $Revision: 1777 $ + * Last Editor: $Author: jdempsey $ + * Last Edited: $Date: 2006-12-17 15:36:01 +1100 (Sun, 17 Dec 2006) $ + * + */ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.GameMode; +import pcgen.core.SettingsHandler; +import plugin.pretokens.parser.PreAlignParser; +import plugin.pretokens.writer.PreAlignWriter; + +/** + * <code>PreAbilityParserTest</code> tests the function of the PREABILITY + * parser. + * + * Last Editor: $Author: jdempsey $ Last Edited: $Date: 2006-12-17 15:36:01 + * +1100 (Sun, 17 Dec 2006) $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: 1777 $ + */ +public class PreAlignRoundRobin extends AbstractAlignRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreAlignRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreAlignRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreAlignParser()); + TokenRegistration.register(new PreAlignWriter()); + GameMode gamemode = SettingsHandler.getGame(); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Good", "LG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Neutral", "LN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Evil", "LE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Neutral Good", "NG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "True Neutral", "TN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Neutral Evil", "NE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Good", "CG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Neutral", "CN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Evil", "CE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "None", "NONE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Deity's", "Deity")); + } + + public void testDeity() + { + runRoundRobin("PRE" + getBaseString() + ":Deity"); + } + + @Override + public String getBaseString() + { + return "ALIGN"; + } + +} \ No newline at end of file Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreDeityAlignRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreDeityAlignRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreDeityAlignRoundRobin.java 2008-03-08 00:38:24 UTC (rev 5502) @@ -0,0 +1,99 @@ +/* + * PreAbilityParserTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on January 23, 2006 + * + * Current Ver: $Revision: 1777 $ + * Last Editor: $Author: jdempsey $ + * Last Edited: $Date: 2006-12-17 15:36:01 +1100 (Sun, 17 Dec 2006) $ + * + */ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.GameMode; +import pcgen.core.SettingsHandler; +import plugin.pretokens.parser.PreDeityAlignParser; +import plugin.pretokens.writer.PreDeityAlignWriter; + +/** + * <code>PreAbilityParserTest</code> tests the function of the PREABILITY + * parser. + * + * Last Editor: $Author: jdempsey $ Last Edited: $Date: 2006-12-17 15:36:01 + * +1100 (Sun, 17 Dec 2006) $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: 1777 $ + */ +public class PreDeityAlignRoundRobin extends AbstractAlignRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PreDeityAlignRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreDeityAlignRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreDeityAlignParser()); + TokenRegistration.register(new PreDeityAlignWriter()); + GameMode gamemode = SettingsHandler.getGame(); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Good", "LG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Neutral", "LN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Lawful Evil", "LE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Neutral Good", "NG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "True Neutral", "TN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Neutral Evil", "NE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Good", "CG")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Neutral", "CN")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Chaotic Evil", "CE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "None", "NONE")); + gamemode.addToAlignmentList(AbstractCharacterTestCase.createAlignment( + "Deity's", "Deity")); + } + + @Override + public String getBaseString() + { + return "DEITYALIGN"; + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2008-03-08 01:09:32
|
Revision: 5503 http://pcgen.svn.sourceforge.net/pcgen/?rev=5503&view=rev Author: jfrazierjr Date: 2008-03-07 17:09:33 -0800 (Fri, 07 Mar 2008) Log Message: ----------- SERVESAS Token Added some support for Skill testing using SERVESAS. Currently, this is limited to exact matching of the skill in in PRESKILL:x,blah=y. At this point, matching on wildcard or type is not supported. I will get to this at some point. Issue#: 1789856 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java 2008-03-08 00:38:24 UTC (rev 5502) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java 2008-03-08 01:09:33 UTC (rev 5503) @@ -26,16 +26,24 @@ */package plugin.pretokens.test; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.print.attribute.standard.Severity; + import pcgen.core.PlayerCharacter; import pcgen.core.Skill; import pcgen.core.prereq.AbstractPrerequisiteTest; import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteOperator; import pcgen.core.prereq.PrerequisiteTest; import pcgen.util.PropertyFactory; - -import pcgen.core.prereq.PrerequisiteOperator; - +import pcgen.core.Globals; +import plugin.lsttokens.ServesAsToken; /** * @author wardc * @@ -69,11 +77,18 @@ // Now locate all instances of this skillname and test them final int percentageSignPosition = skillKey.lastIndexOf('%'); + + HashMap<Skill,HashSet<Skill>> serveAsSkills = new HashMap<Skill, HashSet<Skill>>(); + Set<Skill> imitators = new HashSet<Skill>(); + this.getImitators(serveAsSkills, imitators, character); + + int runningTotal = 0; boolean foundMatch = false; boolean foundSkill = false; final List<Skill> skillList = new ArrayList<Skill>(character.getSkillList()); + for (Skill aSkill : skillList) { final String aSkillKey = aSkill.getKeyName().toUpperCase(); @@ -81,66 +96,27 @@ { if (percentageSignPosition >= 0) { - for (String type : aSkill.getTypeList(false)) - { - if (type.startsWith( - skillKey.substring(0, percentageSignPosition))) - { - foundMatch = true; - break; - } - } + foundMatch = matchesTypeWildCard(aSkillKey, percentageSignPosition, foundSkill, aSkill); + foundSkill = (foundMatch)? true: false; + runningTotal = getRunningTotal(aSkill, character + , prereq, foundMatch, runningTotal, requiredRanks); } else if (aSkill.isType(skillKey)) { foundMatch = true; + foundSkill = true; + runningTotal = getRunningTotal(aSkill, character + , prereq, foundMatch, runningTotal, requiredRanks); } - - if (foundMatch) - { - foundSkill = foundMatch; - if (prereq.isTotalValues()) - { - runningTotal += - aSkill.getTotalRank(character).intValue(); - } - else - { - if (prereq.getOperator().compare( - aSkill.getTotalRank(character).intValue(), - requiredRanks) > 0) - { - runningTotal++; - } - } - if (runningTotal == 0) - { - foundMatch = false; - } - } } else if (aSkillKey.equals(skillKey) || ((percentageSignPosition >= 0) && aSkillKey .startsWith(skillKey.substring(0, percentageSignPosition)))) { + foundMatch = true; foundSkill = true; - if (prereq.isTotalValues()) - { - runningTotal += aSkill.getTotalRank(character).intValue(); - } - else - { - if (prereq.getOperator().compare( - aSkill.getTotalRank(character).intValue(), - requiredRanks) > 0) - { - runningTotal++; - } - } - if (runningTotal > 0) - { - foundMatch = true; - } + runningTotal = getRunningTotal(aSkill, character + , prereq, foundMatch, runningTotal, requiredRanks); } if (prereq.isCountMultiples() || prereq.isTotalValues()) @@ -153,7 +129,38 @@ break; } } + if (isType) + { + if(percentageSignPosition >= 0) + { + + } + else + { + + } + } + else + { + for(Skill mock: serveAsSkills.keySet()) + { + HashSet<Skill> targets = serveAsSkills.get(mock); + for(Skill target: targets) + { + if(target.getDisplayName().equalsIgnoreCase(skillKey)) + { + foundSkill = true; + foundMatch = true; + int theTotal = getRunningTotal(mock, character, prereq, foundMatch + , runningTotal, requiredRanks); + runningTotal += theTotal; + System.out.println("Fakeas: " +target + "\nSkill:" +mock + " -> " + theTotal + " -> " +runningTotal ); + } + } + } + } + // If we are looking for a negative test i.e. !PRESKILL and the PC // doesn't have the skill we have to return a match if (foundSkill == false) @@ -166,6 +173,29 @@ return countedTotal(prereq, runningTotal); } + private void getImitators( + HashMap<Skill, HashSet<Skill>> serveAsSkills, Set<Skill> imitators, + PlayerCharacter character) + { + List<Skill> allSkills = Globals.getSkillList(); + for(Skill aSkill: allSkills) + { + Skill finalSkill = null ; + Set<Skill> servesAs = new HashSet<Skill>(); + for(String fakeSkill: aSkill.getServesAs().keySet()) + { + finalSkill = Globals.getSkillKeyed(fakeSkill); + servesAs.add(finalSkill); + } + + if(servesAs.size() > 0) + { + imitators.add(aSkill); + serveAsSkills.put(aSkill, (HashSet<Skill>) servesAs); + } + } + } + /* (non-Javadoc) * @see pcgen.core.prereq.PrerequisiteTest#kindsHandled() */ @@ -193,5 +223,55 @@ prereq.getOperand(), skillName}); return foo; } - + /** + * Mar 6, 2008 - Joe.Frazier + * @param skillKey + * @param percentageSignPosition + * @param foundMatch + * @param aSkill + * @return + */ + private boolean matchesTypeWildCard(final String skillKey, + final int percentageSignPosition, boolean found, Skill aSkill) + { + for (String type : aSkill.getTypeList(false)) + { + if (type.startsWith( + skillKey.substring(0, percentageSignPosition))) + { + found = true; + break; + } + } + return found; + } + private int getRunningTotal(Skill aSkill, PlayerCharacter character, Prerequisite prereq + , boolean foundMatch, int runningTotal, int requiredRanks ) + { + if (foundMatch) + { + if (prereq.isTotalValues()) + { + runningTotal += + aSkill.getTotalRank(character).intValue(); + } + else + { + System.out.println("PreReq: "+ prereq + + "\nSkill:" + aSkill + + "\nRanks:" + aSkill.getTotalRank(character).intValue()); + if (prereq.getOperator().compare( + aSkill.getTotalRank(character).intValue(), + requiredRanks) > 0) + { + runningTotal++; + } + } + if (runningTotal == 0) + { + foundMatch = false; + } + } + return runningTotal; + } } Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java 2008-03-08 00:38:24 UTC (rev 5502) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java 2008-03-08 01:09:33 UTC (rev 5503) @@ -32,6 +32,7 @@ import junit.framework.TestSuite; import junit.textui.TestRunner; import pcgen.AbstractCharacterTestCase; +import pcgen.core.Globals; import pcgen.core.PCClass; import pcgen.core.PlayerCharacter; import pcgen.core.Skill; @@ -56,6 +57,10 @@ Skill balance = null; Skill knowledge = null; Skill tumble = null; + Skill fake = null; + Skill fake2 = null; + Skill target = null; + Skill target2 = null; /* (non-Javadoc) * @see junit.framework.TestCase#setUp() @@ -74,6 +79,7 @@ knowledge.setTypeInfo("KNOWLEDGE.INT"); knowledge.modRanks(8.0, myClass, true, character); character.addSkill(knowledge); + Globals.getSkillList().add((Skill) knowledge); tumble = new Skill(); tumble.addClassList("My Class"); @@ -81,6 +87,7 @@ tumble.setTypeInfo("DEX"); tumble.modRanks(8.0, myClass, true, character); character.addSkill(tumble); + Globals.getSkillList().add((Skill) tumble); balance = new Skill(); balance.addClassList("My Class"); @@ -88,6 +95,38 @@ balance.setTypeInfo("DEX"); balance.modRanks(4.0, myClass, true, character); character.addSkill(balance); + Globals.getSkillList().add((Skill) balance); + + fake = new Skill(); + fake.addClassList("My Class"); + fake.setName("Fake"); + fake.setTypeInfo("INT"); + fake.modRanks(6.0, myClass, true, character); + character.addSkill(fake); + Globals.getSkillList().add((Skill) fake); + + fake2 = new Skill(); + fake2.addClassList("My Class"); + fake2.setName("Fake 2"); + fake2.setTypeInfo("INT"); + fake2.modRanks(8.0, myClass, true, character); + character.addSkill(fake2); + Globals.getSkillList().add((Skill) fake2); + + target = new Skill(); + target.addClassList("My Class"); + target.setName("Target"); + target.setTypeInfo("INT"); + Globals.getSkillList().add((Skill) target); + + target2 = new Skill(); + target2.addClassList("My Class"); + target2.setName("Target2"); + target2.setTypeInfo("INT"); + Globals.getSkillList().add((Skill) target2); + + fake.putServesAs(target.getDisplayName(), null); + fake.putServesAs(target2.getDisplayName(), null); } @@ -310,4 +349,24 @@ assertEquals(true, PrereqHandler.passes(prereq, character, null)); } + public void testServesAsExactMatch() throws Exception + { + final PlayerCharacter character = getCharacter(); + + final PreParserFactory factory = PreParserFactory.getInstance(); + Prerequisite prereq = factory.parse("PRESKILL:2,Target,Target2=4"); + assertEquals(true, PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESKILL:1,Target,Target2=5"); + assertEquals(true, PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESKILL:2,Target,Target2=7"); + assertEquals(false, PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESKILL:2,Target=4,Target2=7"); + assertEquals(false, PrereqHandler.passes(prereq, character, null)); + + + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-08 22:31:22
|
Revision: 5512 http://pcgen.svn.sourceforge.net/pcgen/?rev=5512&view=rev Author: thpr Date: 2008-03-08 14:26:24 -0800 (Sat, 08 Mar 2008) Log Message: ----------- More PRExxx round robin enhancements Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreRuleWriter.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreRuleRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreRuleWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreRuleWriter.java 2008-03-08 22:17:35 UTC (rev 5511) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreRuleWriter.java 2008-03-08 22:26:24 UTC (rev 5512) @@ -82,4 +82,30 @@ } } + @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; + } + } Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreRuleRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreRuleRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreRuleRoundRobin.java 2008-03-08 22:26:24 UTC (rev 5512) @@ -0,0 +1,45 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreRuleParser; +import plugin.pretokens.writer.PreRuleWriter; + +public class PreRuleRoundRobin extends AbstractBasicRoundRobin +{ + + public static void main(String args[]) + { + TestRunner.run(PreRuleRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreRuleRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreRuleParser()); + TokenRegistration.register(new PreRuleWriter()); + } + + @Override + public String getBaseString() + { + return "RULE"; + } + + @Override + public boolean isTypeAllowed() + { + return false; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-08 23:52:04
|
Revision: 5520 http://pcgen.svn.sourceforge.net/pcgen/?rev=5520&view=rev Author: thpr Date: 2008-03-08 15:52:10 -0800 (Sat, 08 Mar 2008) Log Message: ----------- [ 1901819 ] PREHD: no longer fully supported for write Issue#: 1901819 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PreHDRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java 2008-03-08 23:48:47 UTC (rev 5519) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java 2008-03-08 23:52:10 UTC (rev 5520) @@ -56,7 +56,7 @@ public PrerequisiteOperator[] operatorsHandled() { return new PrerequisiteOperator[]{PrerequisiteOperator.GTEQ, - PrerequisiteOperator.LT}; + PrerequisiteOperator.LT, PrerequisiteOperator.LTEQ,PrerequisiteOperator.GT}; } /* (non-Javadoc) @@ -67,33 +67,37 @@ { checkValidOperator(prereq, operatorsHandled()); - // Case of PREHD:<min>-<max> is handled in PREMULT writer. - // Only need to hand the PREHD:<min>+ version here - try { if (prereq.getOperator().equals(PrerequisiteOperator.LT)) { writer.write('!'); + writer.write("PREHD:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); + writer.write(prereq.getOperand()); } - if (prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) + else if(prereq.getOperator().equals(PrerequisiteOperator.GT)) { - writer.write("PREHD:MIN="); + writer.write('!'); + writer.write("PREHD:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); + writer.write(prereq.getOperand()); + } + else if (prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) + { + writer.write("PREHD:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); writer.write(prereq.getOperand()); } else if(prereq.getOperator().equals(PrerequisiteOperator.LTEQ)) { - writer.write("PREHD:MAX="); + writer.write("PREHD:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); writer.write(prereq.getOperand()); } - + } catch (IOException e) { throw new PersistenceLayerException(e.getMessage()); } } - /* (non-Javadoc) * @see pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter#specialCase(java.io.Writer writer, pcgen.core.prereq.Prerequisite prereq) */ Added: Trunk/pcgen/code/src/test/plugin/pretokens/PreHDRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreHDRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreHDRoundRobin.java 2008-03-08 23:52:10 UTC (rev 5520) @@ -0,0 +1,39 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PreHDParser; +import plugin.pretokens.writer.PreHDWriter; + +public class PreHDRoundRobin extends AbstractMinMaxRoundRobin +{ + + public static void main(String args[]) + { + TestRunner.run(PreHDRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreHDRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PreHDParser()); + TokenRegistration.register(new PreHDWriter()); + } + + @Override + public String getBaseString() + { + return "HD"; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2008-03-12 01:10:37
|
Revision: 5567 http://pcgen.svn.sourceforge.net/pcgen/?rev=5567&view=rev Author: thpr Date: 2008-03-11 18:10:44 -0700 (Tue, 11 Mar 2008) Log Message: ----------- Additional PRE changes Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePointBuyMethodWriter.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreVariableWriter.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Trunk/pcgen/code/src/test/plugin/pretokens/PreVarRoundRobin.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/pretokens/PrePointBuyMethodRoundRobin.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePointBuyMethodWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePointBuyMethodWriter.java 2008-03-12 01:02:45 UTC (rev 5566) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PrePointBuyMethodWriter.java 2008-03-12 01:10:44 UTC (rev 5567) @@ -89,31 +89,27 @@ */ @Override public boolean specialCase(Writer writer, Prerequisite prereq) - throws IOException + throws IOException { - // - // If this is a PREMULT with all PREPOINTBUYMETHODs ... - // - if (checkForPremultOfKind(prereq, kindHandled(), false)) + PrerequisiteOperator po = getConsolidateMethod(kindHandled(), prereq, false); + if (po == null) { - if (prereq.getOperator().equals(PrerequisiteOperator.LT)) - { - writer.write('!'); - } + return false; + } + if (!po.equals(prereq.getOperator())) + { + writer.write('!'); + } - writer.write("PREPOINTBUYMETHOD:" + (prereq.isOverrideQualify() ? "Q:":"")); - boolean needComma = false; - for (Prerequisite element : prereq.getPrerequisites()) - { - if (needComma) - { - writer.write(','); - } - needComma = true; - writer.write(element.getKey()); - } - return true; + 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 false; + return true; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreVariableWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreVariableWriter.java 2008-03-12 01:02:45 UTC (rev 5566) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreVariableWriter.java 2008-03-12 01:10:44 UTC (rev 5567) @@ -28,21 +28,26 @@ */ package plugin.pretokens.writer; +import java.io.IOException; +import java.io.Writer; +import java.util.List; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; +import pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter; import pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface; -import java.io.IOException; -import java.io.Writer; - /** * Writes out PREVAR token */ -public class PreVariableWriter implements PrerequisiteWriterInterface +public class PreVariableWriter extends AbstractPrerequisiteWriter implements + PrerequisiteWriterInterface { - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#kindHandled() */ public String kindHandled() @@ -50,7 +55,9 @@ return "var"; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#operatorsHandled() */ public PrerequisiteOperator[] operatorsHandled() @@ -59,28 +66,32 @@ return null; } - /* (non-Javadoc) - * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite) + /* + * (non-Javadoc) + * + * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, + * pcgen.core.prereq.Prerequisite) */ public void write(Writer writer, Prerequisite prereq) - throws PersistenceLayerException + throws PersistenceLayerException { try { writer.write("PREVAR"); writer.write(prereq.getOperator().toString().toUpperCase()); - writer.write(':' + (prereq.isOverrideQualify() ? "Q:":"")); + writer.write(':' + (prereq.isOverrideQualify() ? "Q:" : "")); writer.write(prereq.getKey()); writer.write(','); writer.write(prereq.getOperand()); - // for (Iterator iter = prereq.getPrerequisites().iterator(); iter.hasNext(); ) - // { - // final Prerequisite p = (Prerequisite) iter.next(); - // writer.write(','); - // writer.write(p.getKey()); - // writer.write(','); - // writer.write(p.getOperand()); - // } + // for (Iterator iter = prereq.getPrerequisites().iterator(); + // iter.hasNext(); ) + // { + // final Prerequisite p = (Prerequisite) iter.next(); + // writer.write(','); + // writer.write(p.getKey()); + // writer.write(','); + // writer.write(p.getOperand()); + // } } catch (IOException e) { @@ -88,4 +99,69 @@ } } + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + if (prereq.getKind() != null) + { + return false; + } + String handled = kindHandled(); + List<Prerequisite> prereqList = prereq.getPrerequisites(); + String count = prereq.getOperand(); + try + { + int i = Integer.parseInt(count); + if (prereqList.size() != i) + { + return false; + } + } + catch (NumberFormatException e) + { + return false; + } + PrerequisiteOperator oper = null; + for (Prerequisite p : prereqList) + { + // + // ...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"); + 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; + } } Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-12 01:02:45 UTC (rev 5566) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2008-03-12 01:10:44 UTC (rev 5567) @@ -196,7 +196,7 @@ "PREUATT:4", "PREUATT:4", "PREVARGT:Rage,4", "PREVARGT:Rage,4", "PREVARGT:SneakAttack,5", "PREVARGT:SneakAttack,5", - "PREVARGT:SneakAttack,5,Rage,4", "PREMULT:2,[PREVARGT:SneakAttack,5],[PREVARGT:Rage,4]", + "PREVARGT:SneakAttack,5,Rage,4", "PREVARGT:SneakAttack,5,Rage,4", "PREVISION:2,Normal,Darkvision", "PREVISION:2,Normal=1,Darkvision=1", "PREVISION:1,Blindsight,Darkvision=30", "PREVISION:1,Blindsight=30,Darkvision=30", "PREWEAPONPROF:2,Kama,Katana", "PREWEAPONPROF:2,Kama,Katana", @@ -217,8 +217,8 @@ "PREHD:MIN=3", "PREHD:MIN=3", "PREHD:MIN=3,MAX=12", "PREHD:MIN=3,MAX=12", "PREHP:12", "PREHP:12", - "PREPOINTBUYMETHOD:Standard", "PREPOINTBUYMETHOD:Standard", - "PREPOINTBUYMETHOD:Standard,High-powered", "PREPOINTBUYMETHOD:Standard,High-powered", + "PREPOINTBUYMETHOD:Standard", "PREPOINTBUYMETHOD:1,Standard", + "PREPOINTBUYMETHOD:Standard,High-powered", "PREPOINTBUYMETHOD:1,Standard,High-powered", // // Just for good measure @@ -320,7 +320,7 @@ "!PRESTATLTEQ:1,STR=18", "PRESTATGT:1,STR=18", "!PRESTATGT:1,STR=18", "PRESTATLTEQ:1,STR=18", "!PREVISION:1,Blindsight", "!PREVISION:1,Blindsight=1", - "!PREPOINTBUYMETHOD:Standard", "!PREPOINTBUYMETHOD:Standard", + "!PREPOINTBUYMETHOD:Standard", "!PREPOINTBUYMETHOD:1,Standard", "!PRESKILLTOT:Spot,Listen,Search=30", "!PRESKILLTOT:Spot,Listen,Search=30", "!PREFEAT:1,Dodge", "!PREFEAT:1,Dodge", "!PRESPELLDESCRIPTOR:Mind-Affecting,4,3", "!PRESPELLDESCRIPTOR:4,Mind-Affecting=3", @@ -336,7 +336,7 @@ "!PRESPELLSCHOOLSUB:3,Subshool1=2,Subshool2=4", "!PRESPELLSCHOOLSUB:3,Subshool1=2,Subshool2=4", "!PRESPELLDESCRIPTOR:4,Mind-Affecting=3,Fire=2", "!PRESPELLDESCRIPTOR:4,Mind-Affecting=3,Fire=2", "!PRESKILLTOT:TYPE.Knowledge=20", "!PRESKILLTOT:TYPE.Knowledge=20", - "!PREPOINTBUYMETHOD:Standard,High-powered", "!PREPOINTBUYMETHOD:Standard,High-powered", + "!PREPOINTBUYMETHOD:Standard,High-powered", "!PREPOINTBUYMETHOD:1,Standard,High-powered", // "PREALIGN:8", "PREALIGN:CE", Added: Trunk/pcgen/code/src/test/plugin/pretokens/PrePointBuyMethodRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PrePointBuyMethodRoundRobin.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PrePointBuyMethodRoundRobin.java 2008-03-12 01:10:44 UTC (rev 5567) @@ -0,0 +1,44 @@ +package plugin.pretokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import plugin.pretokens.parser.PrePointBuyMethodParser; +import plugin.pretokens.writer.PrePointBuyMethodWriter; + +public class PrePointBuyMethodRoundRobin extends AbstractBasicRoundRobin +{ + public static void main(String args[]) + { + TestRunner.run(PrePointBuyMethodRoundRobin.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PrePointBuyMethodRoundRobin.class); + } + + @Override + protected void setUp() throws Exception + { + super.setUp(); + TokenRegistration.register(new PrePointBuyMethodParser()); + TokenRegistration.register(new PrePointBuyMethodWriter()); + } + + @Override + public String getBaseString() + { + return "POINTBUYMETHOD"; + } + + @Override + public boolean isTypeAllowed() + { + return false; + } + +} Modified: Trunk/pcgen/code/src/test/plugin/pretokens/PreVarRoundRobin.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/pretokens/PreVarRoundRobin.java 2008-03-12 01:02:45 UTC (rev 5566) +++ Trunk/pcgen/code/src/test/plugin/pretokens/PreVarRoundRobin.java 2008-03-12 01:10:44 UTC (rev 5567) @@ -80,6 +80,39 @@ return "VAR"; } + public void testMultipleCompare() + { + runRoundRobin("abs(STR),4,abs(INT),3"); + } + + public void testDiffCompare() + { + runSimpleRoundRobin( + "PREMULT:2,[PREVARGT:abs(STR),4],[PREVARLT:abs(INT),3]", + "PREMULT:2,[PREVARGT:abs(STR),4],[PREVARLT:abs(INT),3]"); + } + + public void testCloseCompare() + { + runSimpleRoundRobin( + "PREMULT:2,[PREVARGT:abs(STR),4],[PREVARGTEQ:abs(INT),3]", + "PREMULT:2,[PREVARGT:abs(STR),4],[PREVARGTEQ:abs(INT),3]"); + } + + public void testCountOne() + { + runSimpleRoundRobin( + "PREMULT:1,[PREVARGT:abs(STR),4],[PREVARGT:abs(INT),3]", + "PREMULT:1,[PREVARGT:abs(STR),4],[PREVARGT:abs(INT),3]"); + } + + public void testFunConsolidation() + { + runSimpleRoundRobin( + "PREMULT:2,[PREVARGT:abs(STR),4],[!PREVARLTEQ:abs(INT),3]", + "PREVARGT:abs(STR),4,abs(INT),3"); + } + @Override public boolean isBaseAllowed() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2008-03-20 00:52:02
|
Revision: 5641 http://pcgen.svn.sourceforge.net/pcgen/?rev=5641&view=rev Author: jfrazierjr Date: 2008-03-19 17:52:05 -0700 (Wed, 19 Mar 2008) Log Message: ----------- (VAR.count("ABILITIES","CATEGORY=Spell Lists")+1)/2 For the fix, which works with both a stand alone tag AND inside a DFOR, I put in a case for an override string ${blah}. If this is encountered, blah is passed straight to pc.getvariablevalue. Issue#: 1916479 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2008-03-19 23:35:46 UTC (rev 5640) +++ Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2008-03-20 00:52:05 UTC (rev 5641) @@ -347,6 +347,11 @@ } strlenIndex = vString.indexOf("STRLEN[", strlenIndex + 1); } + if (varString.startsWith("${") && varString.endsWith("}")) + { + String jepString = varString.substring(2, varString.length()-1); + return aPC.getVariableValue(jepString.replace(';',','), "").intValue(); + } return aPC.getVariableValue(vString, "").intValue(); } @@ -1586,6 +1591,12 @@ return 0; } + if (aString.startsWith("${") && aString.endsWith("}")) + { + String jepString = aString.substring(2, aString.length()-1); + FileAccess.write(output, aPC.getVariableValue(jepString, "").toString()); + return aString.trim().length(); + } FileAccess.maxLength(-1); Modified: Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2008-03-19 23:35:46 UTC (rev 5640) +++ Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2008-03-20 00:52:05 UTC (rev 5641) @@ -32,6 +32,7 @@ import pcgen.AbstractCharacterTestCase; import pcgen.core.Ability; import pcgen.core.Equipment; +import pcgen.core.GameMode; import pcgen.core.Globals; import pcgen.core.LevelInfo; import pcgen.core.PCClass; @@ -41,6 +42,7 @@ import pcgen.core.SettingsHandler; import pcgen.core.Skill; import pcgen.core.character.EquipSet; +import pcgen.util.Logging; /** * <code>SkillTokenTest</code> contains tests to verify that the @@ -274,12 +276,72 @@ public void testFor() throws IOException { PlayerCharacter pc = getCharacter(); + Ability dummyFeat1 = new Ability(); + dummyFeat1.setName("1"); + dummyFeat1.setCategory("FEAT"); + + Ability dummyFeat2 = new Ability(); + dummyFeat2.setName("2"); + dummyFeat2.setCategory("FEAT"); + + Ability dummyFeat3 = new Ability(); + dummyFeat3.setName("3"); + dummyFeat3.setCategory("FEAT"); + + Ability dummyFeat4 = new Ability(); + dummyFeat4.setName("4"); + dummyFeat4.setCategory("FEAT"); + + Ability dummyFeat5 = new Ability(); + dummyFeat5.setName("5"); + dummyFeat5.setCategory("FEAT"); + + Ability dummyFeat6 = new Ability(); + dummyFeat6.setName("6"); + dummyFeat6.setCategory("FEAT"); + + Ability dummyFeat7 = new Ability(); + dummyFeat7.setName("7"); + dummyFeat7.setCategory("FEAT"); + + pc.addFeat(dummyFeat1, null); + pc.addFeat(dummyFeat2, null); + pc.addFeat(dummyFeat3, null); + pc.addFeat(dummyFeat4, null); + pc.addFeat(dummyFeat5, null); + pc.addFeat(dummyFeat6, null); + pc.addFeat(dummyFeat7, null); + assertEquals("Test for evaluates correctly", "----------------", evaluateToken( "FOR.1,((24-STRLEN[SKILL.0])).INTVAL,24,-,NONE,NONE,1", pc)); assertEquals("Test for evaluates correctly", " ", evaluateToken( "FOR.1,((24-STRLEN[SKILL.0])).INTVAL,24, ,NONE,NONE,1", pc)); + + String tok = "DFOR." + + "0" + + ",${((count(\"ABILITIES\";\"CATEGORY=FEAT\")+1)/2)}" + + ",1" + + ",${(count(\"ABILITIES\";\"CATEGORY=FEAT\")+1)}" + + ",${((count(\"ABILITIES\";\"CATEGORY=FEAT\")+1)/2)}" + + ", \\FEAT.%.NAME\\ " + + ",[" + + ",]" + + ",0"; + + + //Logging.errorPrint( "DFOR Test: " + evaluateToken(tok, pc)); + + + // Test DFOR with alternate syntax for jep passthrough. ie, anything + // surrounded by ${x} will tbe sent straight to be processed. We + // will assume that x is a well formed type of value. This was to get around + // the problems with DFOR not taking ((count("ABILITIES";"CATEGORY=FEAT")+1) + // since it could not figure out how to parse it to send to the right place. + assertEquals("Test for DFOR ","[ 1 5 ][ 2 6 ][ 3 7 ][ 4 ]", + evaluateToken(tok, pc) ); + } public void testForNoMoreItems() throws IOException @@ -347,6 +409,19 @@ tok = "count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")"; assertFalse("Token: |" + tok + "| != 1.0 ", evaluateToken(tok, pc).equals("1.0")); + tok = "${count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5}"; + assertFalse("Token: |" + tok + "| == 5.0 ", evaluateToken(tok, pc).equals("5.0")); + + tok = "${count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5}"; + assertTrue("Token: |" + tok + "| != 6.0 ", evaluateToken(tok, pc).equals("6.0")); + + tok = "${(count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5)/3}"; + assertFalse("Token: |" + tok + "| == 3.0 ", evaluateToken(tok, pc).equals("3.0")); + + tok = "${(count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5)/3}"; + assertTrue("Token: |" + tok + "| != 2.0 ", evaluateToken(tok, pc).equals("2.0")); + + } private String evaluateToken(String token, PlayerCharacter pc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-03-22 12:07:34
|
Revision: 5678 http://pcgen.svn.sourceforge.net/pcgen/?rev=5678&view=rev Author: jdempsey Date: 2008-03-22 05:07:39 -0700 (Sat, 22 Mar 2008) Log Message: ----------- FReq: SERVESAS Token - Refine ability handling to work for all categories and to cover type matches. Issue#: 1789856 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreAbilityTester.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -167,7 +167,7 @@ private List<Description> theDescriptions = null; private DoubleKeyMap<Class, String, List<String>> qualifyKeys = null; - private HashMap<String,String> servesAsList =null; + private HashMap<String,List<String>> servesAsList =null; private URI sourceURI = null; @@ -5226,34 +5226,43 @@ { if (servesAsList == null) { - servesAsList = new HashMap<String,String>(); + servesAsList = new HashMap<String,List<String>>(); } - servesAsList.put(key,category); - } - public void putServesAs( final Map<String,String> ServersAs ) - { - if (servesAsList == null) + List<String> list = servesAsList.get(category); + if (list == null) { - servesAsList = new HashMap<String,String>(); - return; + list = new ArrayList<String>(); + servesAsList.put(category, list); } - servesAsList = (HashMap<String, String>) ServersAs; + list.add(key); } + public final void clearServesAs() { servesAsList =null; } //TODO This exposes internal structure - be careful. - public final Map<String,String> getServesAs() + public final Map<String,List<String>> getServesAs() { if (servesAsList == null) { - servesAsList = new HashMap<String,String>(); + servesAsList = new HashMap<String,List<String>>(); } return servesAsList; } + public final List<String> getServesAs(String category) + { + if (servesAsList == null) + { + servesAsList = new HashMap<String,List<String>>(); + } + List<String> result = servesAsList.get(category); + return result == null ? new ArrayList<String>() : Collections + .unmodifiableList(result); + } + // public List<BonusObj> getActiveBonuses(final PlayerCharacter aPC, final String aBonusType, final String aBonusName) // { // if (!PrereqHandler.passesAll(this.getPreReqList(), aPC, this)) Modified: Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.StringTokenizer; import pcgen.core.Ability; @@ -401,6 +402,33 @@ } } } + + // Now scan for relevant SERVESAS occurrences + for (AbilityCategory aCat : allCats) + { + for (Ability ability : character.getAggregateAbilityList(aCat)) + { + final Map<String, List<String>> servesAsMap = ability.getServesAs(); + for (String cat : servesAsMap.keySet()) + { + if (categoryName == null || categoryName.equals(cat)) + { + for (String abilityKey : servesAsMap.get(cat)) + { + AbilityCategory saCat = + SettingsHandler.getGame() + .getAbilityCategory(cat); + Ability saAbility = + Globals.getAbilityKeyed(saCat, abilityKey); + if (saAbility != null) + { + abilityList.add(saAbility); + } + } + } + } + } + } } return abilityList; } Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/ServesAsToken.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -40,7 +40,7 @@ StringTokenizer st = new StringTokenizer(value, Constants.PIPE); String key = st.hasMoreTokens() ? st.nextToken() : ""; Class c; - String category = null; + String category = ""; int equalLoc = key.indexOf('='); if (equalLoc == -1) { if ("ABILITY".equals(key)) { Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreAbilityTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreAbilityTester.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreAbilityTester.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -25,26 +25,16 @@ */ package plugin.pretokens.test; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -import pcgen.core.Ability; import pcgen.core.AbilityCategory; import pcgen.core.Equipment; import pcgen.core.GameMode; import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; -import pcgen.core.Ability.Nature; import pcgen.core.prereq.AbstractPrerequisiteTest; import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteException; import pcgen.core.prereq.PrerequisiteTest; import pcgen.core.prereq.PrerequisiteUtilities; -import pcgen.util.Logging; import pcgen.util.PropertyFactory; /** @@ -97,68 +87,12 @@ String subKey = prereq.getSubKey(); String categoryName = prereq.getCategoryName(); AbilityCategory category = gameMode.getAbilityCategory(categoryName); - - Set<Ability> servesAsList = getServesAsList(character); - int runningTotal; - - runningTotal = PrerequisiteUtilities.passesAbilityTest(prereq, character, - countMults, number, key, subKey, categoryName, category); - if (runningTotal ==0) - { - for (Ability ability: servesAsList) - { - try - { - Prerequisite newPre = prereq.clone(); - String newCatName = ability.getCategory(); - AbilityCategory newCategory = gameMode.getAbilityCategory(newCatName); - String newKey = ability.getDisplayName(); - - newPre.setCategoryName(newCatName); - newPre.setKey(newKey); - runningTotal = PrerequisiteUtilities.passesAbilityTest(newPre, character, - countMults, number, newKey, subKey, newCatName, newCategory); - if (runningTotal > 0) - { - break; - } - } - catch (CloneNotSupportedException e) - { - Logging.debugPrint(""); - } - - - } - } + int runningTotal = + PrerequisiteUtilities.passesAbilityTest(prereq, character, + countMults, number, key, subKey, categoryName, category); return countedTotal(prereq, runningTotal); } - /** - * Returns a set for all the characters abilities that have - * a servesAs list. - * - * @param character - * @return Set<Ability> - */ - private Set<Ability> getServesAsList(final PlayerCharacter character) - { - Map<Nature, Set<Ability>> allAbilities = character.getAbilitiesSet(); - Set<Ability> theAbilitiesToCheck = new TreeSet<Ability>(); - for(Nature nature: allAbilities.keySet()) - { - Set<Ability> abilityItems = allAbilities.get(nature); - for (Ability ab: abilityItems) - { - if (ab.getServesAs().size() > 0) - { - theAbilitiesToCheck.add(ab); - } - } - } - return theAbilitiesToCheck; - } - @Override public String toHtmlString(final Prerequisite prereq) { Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -125,8 +125,7 @@ } else { - Map<String,String> theList =cl.getServesAs(); - Set<String> keys = theList.keySet(); + List<String> keys =cl.getServesAs(""); SERVESAS: for(String aKey : keys) { PCClass aClass = Globals.getClassKeyed(aKey); @@ -174,8 +173,7 @@ { CLASSLIST: for(PCClass theClass: character.getClassList()) { - Map<String,String> theList = theClass.getServesAs(); - Set<String> keys = theList.keySet(); + List<String> keys = theClass.getServesAs(""); for(String aKey : keys) { if (aKey.equalsIgnoreCase(aString)) Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreSkillTester.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -182,7 +182,7 @@ { Skill finalSkill = null ; Set<Skill> servesAs = new HashSet<Skill>(); - for(String fakeSkill: aSkill.getServesAs().keySet()) + for(String fakeSkill: aSkill.getServesAs("")) { finalSkill = Globals.getSkillKeyed(fakeSkill); servesAs.add(finalSkill); Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -80,7 +80,7 @@ } /** - * Test the function of the catgeory matching + * Test the function of the category matching * @throws PersistenceLayerException */ public void testCategoryMatch() throws PersistenceLayerException @@ -192,5 +192,126 @@ assertFalse("Test fighter type match with an ability.", PrereqHandler .passes(prereq3, character, null)); } + + /** + * Test the function of the SERVESAS token with direct key matching + * @throws PersistenceLayerException + */ + public void testKeyMatchWithServesAs() throws PersistenceLayerException + { + PlayerCharacter character = getCharacter(); + PreAbilityParser parser = new PreAbilityParser(); + Prerequisite prereq = + parser.parse("ability", "1,CATEGORY.ANY,KEY_Dancer", + false, false); + assertFalse("Test any match with no abilities.", PrereqHandler.passes( + prereq, character, null)); + Prerequisite prereq2 = + parser.parse("ability", "1,KEY_Alertness", + false, false); + assertFalse("Test bardic match with no abilities.", PrereqHandler.passes( + prereq2, character, null)); + Prerequisite prereq3 = + parser.parse("ability", "1,CATEGORY.FEAT,KEY_Dancer", + false, false); + assertFalse("Test feat match with no abilities.", PrereqHandler.passes( + prereq3, character, null)); + + TestHelper.makeAbility("Dancer", "FEAT", "General"); + Ability ab2 = + TestHelper.makeAbility("Dancer", "BARDIC", + "General.Bardic"); + ab2.putServesAs("KEY_Alertness", "FEAT"); + ab2.putServesAs("KEY_Dancer", "FEAT"); + ab2.setMultiples("NO"); + character.addAbility(TestHelper.getAbilityCategory(ab2), ab2, null); + + assertTrue("Test any match with an ability.", PrereqHandler.passes( + prereq, character, null)); + assertFalse("Servesas non existant ability should not cause match.", PrereqHandler.passes( + prereq2, character, null)); + assertTrue("Servesas should cause match.", PrereqHandler.passes( + prereq3, character, null)); + + } + + /** + * Test the function of the SERVESAS token with type matching + * @throws PersistenceLayerException + */ + public void testTypeMatchWithServesAs() throws PersistenceLayerException + { + PlayerCharacter character = getCharacter(); + PreAbilityParser parser = new PreAbilityParser(); + Prerequisite prereq = + parser.parse("ability", "1,CATEGORY.ANY,TYPE.General", false, + false); + assertFalse("Test general type match with no abilities.", PrereqHandler + .passes(prereq, character, null)); + Prerequisite prereq2 = + parser.parse("ability", "1,CATEGORY.ANY,TYPE.Bardic", false, + false); + assertFalse("Test bardic type match with no abilities.", PrereqHandler + .passes(prereq2, character, null)); + Prerequisite prereq3 = + parser.parse("ability", "1,TYPE.Fighter", false, false); + assertFalse("Test fighter type match with no abilities.", PrereqHandler + .passes(prereq3, character, null)); + + TestHelper.makeAbility("Power Attack", "FEAT", "Fighter"); + Ability ab2 = + TestHelper.makeAbility("Dancer", "BARDIC", "General.Bardic"); + ab2.setMultiples("NO"); + ab2.putServesAs("KEY_Power Attack", "FEAT"); + character.addAbility(TestHelper.getAbilityCategory(ab2), ab2, null); + + assertTrue("Test general type match with an ability.", PrereqHandler + .passes(prereq, character, null)); + assertTrue("Test bardic type match with an ability.", PrereqHandler + .passes(prereq2, character, null)); + assertTrue("Test fighter type match with SERVESAS ability.", PrereqHandler + .passes(prereq3, character, null)); + } + + /** + * Test the function of the category matching + * @throws PersistenceLayerException + */ + public void testCategoryMatchWithServesAs() throws PersistenceLayerException + { + PlayerCharacter character = getCharacter(); + PreAbilityParser parser = new PreAbilityParser(); + Prerequisite prereq = + parser.parse("ability", "1,CATEGORY.ANY,ANY", + false, false); + assertFalse("Test any match with no abilities.", PrereqHandler.passes( + prereq, character, null)); + Prerequisite prereq2 = + parser.parse("ability", "1,CATEGORY.BARDIC,ANY", + false, false); + assertFalse("Test bardic match with no abilities.", PrereqHandler.passes( + prereq2, character, null)); + Prerequisite prereq3 = + parser.parse("ability", "1,CATEGORY.FEAT,ANY", + false, false); + assertFalse("Test feat match with no abilities.", PrereqHandler.passes( + prereq3, character, null)); + + TestHelper.makeAbility("Fascinate", "BARDIC", "Normal"); + Ability ab2 = + TestHelper.makeAbility("Dancer", "FEAT", + "General.Bardic"); + ab2.putServesAs("KEY_Fascinate", "BARDIC"); + ab2.setMultiples("NO"); + character.addAbility(TestHelper.getAbilityCategory(ab2), ab2, null); + + assertTrue("Test any match with an ability.", PrereqHandler.passes( + prereq, character, null)); + assertTrue("Test bardic match with an ability.", PrereqHandler.passes( + prereq2, character, null)); + assertTrue("Test feat match with an ability.", PrereqHandler.passes( + prereq3, character, null)); + + } } Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -95,8 +95,8 @@ final PCClass pcClass = new PCClass(); pcClass.setName("MyClass"); pcClass.setAbbrev("My"); - pcClass.putServesAs("Warrior", null); // the second parameter is for ability categories only - pcClass.putServesAs("Ranger", null); // the second parameter is for ability categories only + pcClass.putServesAs("Warrior", ""); // the second parameter is for ability categories only + pcClass.putServesAs("Ranger", ""); // the second parameter is for ability categories only final PlayerCharacter character = getCharacter(); character.incrementClassLevel(3, pcClass); Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java 2008-03-22 12:03:05 UTC (rev 5677) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreSkillTest.java 2008-03-22 12:07:39 UTC (rev 5678) @@ -125,8 +125,8 @@ target2.setTypeInfo("INT"); Globals.getSkillList().add((Skill) target2); - fake.putServesAs(target.getDisplayName(), null); - fake.putServesAs(target2.getDisplayName(), null); + fake.putServesAs(target.getDisplayName(), ""); + fake.putServesAs(target2.getDisplayName(), ""); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-03-22 21:33:25
|
Revision: 5680 http://pcgen.svn.sourceforge.net/pcgen/?rev=5680&view=rev Author: jdempsey Date: 2008-03-22 14:33:27 -0700 (Sat, 22 Mar 2008) Log Message: ----------- Bug: PREARMORPROF & PRESHIELDPROF broken - Fix PREARMORPROF Issue#: 1913228 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreArmorProfTest.java Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2008-03-22 21:29:53 UTC (rev 5679) +++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2008-03-22 21:33:27 UTC (rev 5680) @@ -3392,6 +3392,8 @@ PreMult.toHtml={0} {1} of ( {2} ) +Prereq.error=Error in {0}\u003A {1} + PreSubClass.error.badly_formed=Badly formed PRESUBCLASS attribute\u003A {0} PreType.error.invalidComparison={0} is not a valid comparison for PRETYPE. Applicable comparators are 'eq' and 'neq'\u003A {1} Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java 2008-03-22 21:29:53 UTC (rev 5679) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java 2008-03-22 21:33:27 UTC (rev 5680) @@ -26,14 +26,21 @@ */ package plugin.pretokens.test; +import pcgen.core.ArmorProf; +import pcgen.core.Globals; import pcgen.core.PlayerCharacter; import pcgen.core.prereq.AbstractPrerequisiteTest; import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteException; import pcgen.core.prereq.PrerequisiteTest; +import pcgen.util.PropertyFactory; /** - * @author wardc + * <code>PreArmorProfTester</code> does the testing of armor proficiency + * prerequisites. * + * @author Chris Ward <fr...@pu...> + * @version $Revision$ */ public class PreArmorProfTester extends AbstractPrerequisiteTest implements PrerequisiteTest @@ -43,10 +50,23 @@ * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter) */ @Override - public int passes(final Prerequisite prereq, final PlayerCharacter character) + public int passes(final Prerequisite prereq, final PlayerCharacter character) throws PrerequisiteException { int runningTotal = 0; + final int number; + try + { + number = Integer.parseInt(prereq.getOperand()); + } + catch (NumberFormatException exceptn) + { + throw new PrerequisiteException(PropertyFactory.getFormattedString( + "Prereq.error", "PREARMOR", prereq.toString())); //$NON-NLS-1$ //$NON-NLS-2$ + } + + ArmorProf keyProf = Globals.getArmorProfKeyed(prereq.getKey()); + for (String profName : character.getArmorProfList()) { if (profName.equalsIgnoreCase(prereq.getKey())) @@ -60,17 +80,32 @@ } else if (profName.startsWith("ARMORTYPE")) { - if (profName.substring(5).equalsIgnoreCase(prereq.getKey())) + String profType = profName.substring(10); + if (profType.equalsIgnoreCase(prereq.getKey())) { runningTotal++; } - else if (profName.substring(10).equalsIgnoreCase(prereq.getKey())) + else if (prereq.getKey().length() > 5 + && profType.equalsIgnoreCase( + prereq.getKey().substring(5))) { runningTotal++; } + else if (keyProf != null) + { + for (String keyProfType : keyProf.getTypeList(false)) + { + if (profType.equalsIgnoreCase(keyProfType)) + { + runningTotal++; + break; + } + } + } } } + runningTotal = prereq.getOperator().compare(runningTotal, number); return countedTotal(prereq, runningTotal); } Added: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreArmorProfTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreArmorProfTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreArmorProfTest.java 2008-03-22 21:33:27 UTC (rev 5680) @@ -0,0 +1,321 @@ +/* + * PreArmorProfTest.java + * Copyright 2008 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 22/03/2008 + * + * $Id$ + */ +package pcgen.core.prereq; + + +import java.net.URI; +import java.net.URISyntaxException; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Ability; +import pcgen.core.AbilityUtilities; +import pcgen.core.ArmorProf; +import pcgen.core.Campaign; +import pcgen.core.Globals; +import pcgen.core.PlayerCharacter; +import pcgen.persistence.lst.CampaignSourceEntry; +import pcgen.persistence.lst.FeatLoader; +import pcgen.persistence.lst.prereq.PreParserFactory; +import pcgen.util.TestHelper; +import pcgen.util.UnreachableError; + +/** + * <code>PreArmorProfTest</code> tests that the PREARMORPROF tag is + * working correctly. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class PreArmorProfTest extends AbstractCharacterTestCase +{ + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(final String[] args) + { + TestRunner.run(PreArmorProfTest.class); + } + + /** + * Suite. + * + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreArmorProfTest.class); + } + + /** + * Test with a simple armor proficiency. + * + * @throws Exception the exception + */ + public void testOneOption() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PREARMORPROF:1,Chainmail"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addArmorProf("Chainmail"); + character.addArmorProf("Full Plate"); + + assertTrue("Character has the Chainmail proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:1,Leather"); + + assertFalse("Character does not have the Leather proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:1,Full Plate"); + + assertTrue("Character has the Full Plate proficiency.", + PrereqHandler.passes(prereq, character, null)); + } + + + /** + * Tests to see if a character has a certain number of weaponprofs from a list. + * + * @throws Exception the exception + */ + public void testMultiple() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PREARMORPROF:1,Chainmail,Full Plate"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addArmorProf("Chainmail"); + character.addArmorProf("Full Plate"); + + assertTrue("Character has one of Chainmail or Full Plate proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:2,Chainmail,Full Plate"); + + assertTrue("Character has both Chainmail and Full Plate proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:3,Chainmail,Full Plate,Leather"); + + assertFalse("Character has both Chainmail and Full Plate proficiency but not Leather", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test a preweaponprof that checks for a number of profs of a certain type. + * + * @throws Exception the exception + */ + public void testType() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PREARMORPROF:1,TYPE.Medium"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addArmorProf("ARMORTYPE=Medium"); + + assertTrue("Character has Medium Armor Proficiency", + PrereqHandler.passes(prereq, character, null)); + } + + /** + * Test with negation. + * + * @throws Exception the exception + */ + public void testInverse() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("!PREARMORPROF:1,Breastplate"); + + assertTrue("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addArmorProf("Breastplate"); + character.addArmorProf("Chainmail"); + + assertFalse("Character has the Breastplate proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("!PREARMORPROF:1,Leather"); + + assertTrue("Character does not have the Leather proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("!PREARMORPROF:1,Chainmail"); + + assertFalse("Character has the Chainmail proficiency.", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test the prearmorprof with armorprofs added by a AUTO:ARMORPROF tag + * This is probably more an integration test than a unit test + * + * @throws Exception the exception + */ + public void testArmorProfAddedWithAutoArmorProf() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PREARMORPROF:1,Breastplate"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + final Ability martialProf = + TestHelper.makeAbility("Armor Proficiency (Single)", "FEAT", "General"); + martialProf.addAutoArray("ARMORPROF", "ARMORTYPE.Medium"); + + AbilityUtilities.modFeat( + character, null, "KEY_Armor Proficiency (Single)", true, false); + + assertTrue("Character has the Breastplate proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:1,Chainmail"); + assertTrue("Character has the Chainmail proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:1,Leather"); + assertFalse("Character does not have the Leather proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PREARMORPROF:1,TYPE.Medium"); + assertTrue("Character has martial weaponprofs.", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test Preweaponprof with a feat that has a bonus tag + * This test was written to help find the source of bug 1699779. + * + * @throws Exception the exception + */ + public void testWithFeatThatGrantsBonus() throws Exception + { + final PlayerCharacter character = getCharacter(); + + final FeatLoader featLoader = new FeatLoader(); + + CampaignSourceEntry cse; + try + { + cse = new CampaignSourceEntry(new Campaign(), + new URI("file:/" + getClass().getName() + ".java")); + } + catch (URISyntaxException e) + { + throw new UnreachableError(e); + } + + int baseHp = character.hitPoints(); + + Ability bar = new Ability(); + final String barStr = + "Bar TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50"; + featLoader.parseLine(bar, barStr, cse); + character.addFeat(bar, null); + + assertEquals("Character should have 50 bonus hp added.", + baseHp+50, + character.hitPoints() + ); + + character.addArmorProf("Full Plate"); + + Ability foo = new Ability(); + final String fooStr = + "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PREARMORPROF:1,Full Plate"; + featLoader.parseLine(foo, fooStr, cse); + character.addFeat(foo, null); + + assertEquals("Character has the Full Plate proficiency so the bonus should be added", + baseHp+50+50, + character.hitPoints() + ); + + } + + /* (non-Javadoc) + * @see pcgen.AbstractCharacterTestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + ArmorProf leather = new ArmorProf(); + leather.setName("Leather"); + leather.setTypeInfo("Light"); + Globals.addArmorProf(leather); + + ArmorProf chainmail = new ArmorProf(); + chainmail.setName("Chainmail"); + chainmail.setTypeInfo("Medium"); + Globals.addArmorProf(chainmail); + + ArmorProf breastplate = new ArmorProf(); + breastplate.setName("Breastplate"); + breastplate.setTypeInfo("Medium"); + Globals.addArmorProf(breastplate); + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreArmorProfTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-03-22 23:41:23
|
Revision: 5682 http://pcgen.svn.sourceforge.net/pcgen/?rev=5682&view=rev Author: jdempsey Date: 2008-03-22 16:41:29 -0700 (Sat, 22 Mar 2008) Log Message: ----------- Bug: PREARMORPROF & PRESHIELDPROF broken - Fix PRESHIELDPROF Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java Trunk/pcgen/code/src/java/plugin/pretokens/test/PreShieldProfTester.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreShieldProfTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-03-22 23:12:29 UTC (rev 5681) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2008-03-22 23:41:29 UTC (rev 5682) @@ -2821,8 +2821,6 @@ */ public List<String> getShieldProfList() { - shieldProfList.clear(); - final List<String> autoShieldProfList = getAutoShieldProfList(); addShieldProfs(autoShieldProfList); Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java 2008-03-22 23:12:29 UTC (rev 5681) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreArmorProfTester.java 2008-03-22 23:41:29 UTC (rev 5682) @@ -66,6 +66,8 @@ } ArmorProf keyProf = Globals.getArmorProfKeyed(prereq.getKey()); + final boolean isType = + prereq.getKey().startsWith("TYPE") && prereq.getKey().length() > 5; for (String profName : character.getArmorProfList()) { @@ -73,7 +75,8 @@ { runningTotal++; } - else if (profName.substring(5).equalsIgnoreCase(prereq.getKey())) + else if (isType && profName.startsWith("TYPE") + && profName.substring(5).equalsIgnoreCase(prereq.getKey())) { // TYPE=Light equals TYPE.Light runningTotal++; @@ -85,9 +88,8 @@ { runningTotal++; } - else if (prereq.getKey().length() > 5 - && profType.equalsIgnoreCase( - prereq.getKey().substring(5))) + else if (isType + && profType.equalsIgnoreCase(prereq.getKey().substring(5))) { runningTotal++; } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreShieldProfTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreShieldProfTester.java 2008-03-22 23:12:29 UTC (rev 5681) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreShieldProfTester.java 2008-03-22 23:41:29 UTC (rev 5682) @@ -26,7 +26,9 @@ */ package plugin.pretokens.test; +import pcgen.core.Globals; import pcgen.core.PlayerCharacter; +import pcgen.core.ShieldProf; import pcgen.core.prereq.AbstractPrerequisiteTest; import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteTest; @@ -49,28 +51,43 @@ int runningTotal = 0; final String aString = prereq.getKey(); + final boolean isType = + aString.startsWith("TYPE") && aString.length() > 5; + ShieldProf keyProf = Globals.getShieldProfKeyed(aString); for (String profName : character.getShieldProfList()) { if (profName.equalsIgnoreCase(aString)) { runningTotal++; } - else if (profName.substring(5).equalsIgnoreCase( - aString.substring(5))) + else if (isType && profName.startsWith("TYPE") + && profName.substring(5).equalsIgnoreCase(aString.substring(5))) { runningTotal++; } else if (profName.startsWith("SHIELDTYPE")) { - if (profName.substring(6).equalsIgnoreCase(prereq.getKey())) + String profType = profName.substring(11); + if (profType.equalsIgnoreCase(prereq.getKey())) { runningTotal++; } - else if (profName.substring(11).equalsIgnoreCase( - prereq.getKey())) + else if (isType && profType.equalsIgnoreCase( + aString.substring(5))) { runningTotal++; } + else if (keyProf != null) + { + for (String keyProfType : keyProf.getTypeList(false)) + { + if (profType.equalsIgnoreCase(keyProfType)) + { + runningTotal++; + break; + } + } + } } } Added: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreShieldProfTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreShieldProfTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreShieldProfTest.java 2008-03-22 23:41:29 UTC (rev 5682) @@ -0,0 +1,320 @@ +/* + * PreShieldProfTest.java + * Copyright 2008 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 22/03/2008 + * + * $Id$ + */ +package pcgen.core.prereq; + + +import java.net.URI; +import java.net.URISyntaxException; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Ability; +import pcgen.core.AbilityUtilities; +import pcgen.core.ShieldProf; +import pcgen.core.Campaign; +import pcgen.core.Globals; +import pcgen.core.PlayerCharacter; +import pcgen.persistence.lst.CampaignSourceEntry; +import pcgen.persistence.lst.FeatLoader; +import pcgen.persistence.lst.prereq.PreParserFactory; +import pcgen.util.TestHelper; +import pcgen.util.UnreachableError; + +/** + * <code>PreShieldProfTest</code> tests that the PRESHIELDPROF tag is + * working correctly. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class PreShieldProfTest extends AbstractCharacterTestCase +{ + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(final String[] args) + { + TestRunner.run(PreShieldProfTest.class); + } + + /** + * Suite. + * + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreShieldProfTest.class); + } + + /** + * Test with a simple shield proficiency. + * + * @throws Exception the exception + */ + public void testOneOption() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PRESHIELDPROF:1,Heavy Wooden Shield"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addShieldProf("Heavy Wooden Shield"); + character.addShieldProf("Heavy Steel Sheild"); + + assertTrue("Character has the Heavy Wooden Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:1,Light Wooden Shield"); + + assertFalse("Character does not have the Light Wooden Shield proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:1,Heavy Steel Sheild"); + + assertTrue("Character has the Heavy Steel Sheild proficiency.", + PrereqHandler.passes(prereq, character, null)); + } + + + /** + * Tests to see if a character has a certain number of shieldprofs from a list. + * + * @throws Exception the exception + */ + public void testMultiple() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PRESHIELDPROF:1,Heavy Wooden Shield,Full Plate"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addShieldProf("Heavy Wooden Shield"); + character.addShieldProf("Full Plate"); + + assertTrue("Character has one of Heavy Wooden Shield or Full Plate proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:2,Heavy Wooden Shield,Full Plate"); + + assertTrue("Character has both Heavy Wooden Shield and Full Plate proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:3,Heavy Wooden Shield,Full Plate,Light Wooden Shield"); + + assertFalse("Character has both Heavy Wooden Shield and Full Plate proficiency but not Light Wooden Shield", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test a preshieldprof that checks for a number of profs of a certain type. + * + * @throws Exception the exception + */ + public void testType() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PRESHIELDPROF:1,TYPE.Medium"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addShieldProf("SHIELDTYPE=Medium"); + + assertTrue("Character has Medium Shield Proficiency", + PrereqHandler.passes(prereq, character, null)); + } + + /** + * Test with negation. + * + * @throws Exception the exception + */ + public void testInverse() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("!PRESHIELDPROF:1,Heavy Steel Shield"); + + assertTrue("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + character.addShieldProf("Heavy Steel Shield"); + character.addShieldProf("Heavy Wooden Shield"); + + assertFalse("Character has the Heavy Steel Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("!PRESHIELDPROF:1,Light Wooden Shield"); + + assertTrue("Character does not have the Light Wooden Shield proficiency", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("!PRESHIELDPROF:1,Heavy Wooden Shield"); + + assertFalse("Character has the Heavy Wooden Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test the preshieldprof with shieldprofs added by a AUTO:SHIELDPROF tag + * This is probably more an integration test than a unit test + * + * @throws Exception the exception + */ + public void testShieldProfAddedWithAutoShieldProf() throws Exception + { + final PlayerCharacter character = getCharacter(); + + Prerequisite prereq; + + final PreParserFactory factory = PreParserFactory.getInstance(); + prereq = factory.parse("PRESHIELDPROF:1,Heavy Steel Shield"); + + assertFalse("Character has no proficiencies", PrereqHandler.passes( + prereq, character, null)); + + final Ability martialProf = + TestHelper.makeAbility("Shield Proficiency (Single)", "FEAT", "General"); + martialProf.addAutoArray("SHIELDPROF", "SHIELDTYPE.Heavy"); + + AbilityUtilities.modFeat( + character, null, "KEY_Shield Proficiency (Single)", true, false); + + assertTrue("Character has the Heavy Steel Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:1,Heavy Wooden Shield"); + assertTrue("Character has the Heavy Wooden Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:1,Light Wooden Shield"); + assertFalse("Character does not have the Light Wooden Shield proficiency.", + PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("PRESHIELDPROF:1,TYPE.Heavy"); + assertTrue("Character has heavy shield prof.", + PrereqHandler.passes(prereq, character, null)); + + } + + /** + * Test PreShieldProf with a feat that has a bonus tag + * + * @throws Exception the exception + */ + public void testWithFeatThatGrantsBonus() throws Exception + { + final PlayerCharacter character = getCharacter(); + + final FeatLoader featLoader = new FeatLoader(); + + CampaignSourceEntry cse; + try + { + cse = new CampaignSourceEntry(new Campaign(), + new URI("file:/" + getClass().getName() + ".java")); + } + catch (URISyntaxException e) + { + throw new UnreachableError(e); + } + + int baseHp = character.hitPoints(); + + Ability bar = new Ability(); + final String barStr = + "Bar TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50"; + featLoader.parseLine(bar, barStr, cse); + character.addFeat(bar, null); + + assertEquals("Character should have 50 bonus hp added.", + baseHp+50, + character.hitPoints() + ); + + character.addShieldProf("Full Plate"); + + Ability foo = new Ability(); + final String fooStr = + "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PRESHIELDPROF:1,Full Plate"; + featLoader.parseLine(foo, fooStr, cse); + character.addFeat(foo, null); + + assertEquals("Character has the Full Plate proficiency so the bonus should be added", + baseHp+50+50, + character.hitPoints() + ); + + } + + /* (non-Javadoc) + * @see pcgen.AbstractCharacterTestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + ShieldProf lightWood = new ShieldProf(); + lightWood.setName("Light Wooden Shield"); + lightWood.setTypeInfo("Light"); + Globals.addShieldProf(lightWood); + + ShieldProf heavyWood = new ShieldProf(); + heavyWood.setName("Heavy Wooden Shield"); + heavyWood.setTypeInfo("Heavy"); + Globals.addShieldProf(heavyWood); + + ShieldProf heavySteel = new ShieldProf(); + heavySteel.setName("Heavy Steel Shield"); + heavySteel.setTypeInfo("Heavy"); + Globals.addShieldProf(heavySteel); + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreShieldProfTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2008-03-23 23:28:22
|
Revision: 5686 http://pcgen.svn.sourceforge.net/pcgen/?rev=5686&view=rev Author: jdempsey Date: 2008-03-23 15:14:22 -0700 (Sun, 23 Mar 2008) Log Message: ----------- Fix bug: PRE Req Feat sorting not well defined Issue#: 1734821 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PrereqObject.java Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityModel.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/gui/tabs/ Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/ Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/AbilityModelTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PrereqObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PrereqObject.java 2008-03-23 09:22:24 UTC (rev 5685) +++ Trunk/pcgen/code/src/java/pcgen/core/PrereqObject.java 2008-03-23 22:14:22 UTC (rev 5686) @@ -236,16 +236,9 @@ for (Prerequisite prereq : getPreReqList()) { - if (prereq != null) + if (PrerequisiteUtilities.hasPreReqKindOf(prereq, matchType)) { - if (matchType == null && prereq.getKind() == null) - { - return true; - } - if (matchType.equalsIgnoreCase(prereq.getKind())) - { - return true; - } + return true; } } Modified: Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java 2008-03-23 09:22:24 UTC (rev 5685) +++ Trunk/pcgen/code/src/java/pcgen/core/prereq/PrerequisiteUtilities.java 2008-03-23 22:14:22 UTC (rev 5686) @@ -571,5 +571,74 @@ } return returnTotal; } + + /** + * Identify if the prerequisite is itself of the supplied kind or has a + * descendant of the required kind. + * @param prereq Prerequisite to be checked + * @param matchKind Kind to be checked for. + * @return + */ + public static final boolean hasPreReqKindOf(final Prerequisite prereq, String matchKind) + { + if (prereq == null) + { + return false; + } + + if (matchKind == null && prereq.getKind() == null) + { + return true; + } + if (matchKind.equalsIgnoreCase(prereq.getKind())) + { + return true; + } + + for (Prerequisite childPrereq : prereq.getPrerequisites()) + { + if (hasPreReqKindOf(childPrereq, matchKind)) + { + return true; + } + } + return false; + } + + /** + * Identify if the prerequisite is itself of the supplied kind or has a + * descendant of the required kind. + * @param prereq Prerequisite to be checked + * @param matchKind Kind to be checked for. + * @return + */ + public static final boolean hasPreReqMatching(final Prerequisite prereq, String matchKind, String matchKey) + { + if (prereq == null) + { + return false; + } + + if ((matchKind == null && prereq.getKind() == null) + || (matchKind.equalsIgnoreCase(prereq.getKind()))) + { + if ((matchKey == null && prereq.getKey() == null) + || (matchKey.equalsIgnoreCase(prereq.getKey()))) + { + return true; + } + } + + for (Prerequisite childPrereq : prereq.getPrerequisites()) + { + if (hasPreReqMatching(childPrereq, matchKind, matchKey)) + { + return true; + } + } + + return false; + } + } Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityModel.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityModel.java 2008-03-23 09:22:24 UTC (rev 5685) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityModel.java 2008-03-23 22:14:22 UTC (rev 5686) @@ -39,6 +39,7 @@ import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteUtilities; import pcgen.core.utils.CoreUtility; import pcgen.gui.TableColumnManagerModel; import pcgen.gui.utils.AbstractTreeTableModel; @@ -533,8 +534,8 @@ { final Ability aFeat = fList.get(i); - // TODO - Change this when we have PRExxx tags for Ability - if (!aFeat.hasPreReqTypeOf("FEAT")) //$NON-NLS-1$ + if (!aFeat.hasPreReqTypeOf("FEAT") //$NON-NLS-1$ + && !aFeat.hasPreReqTypeOf("ABILITY")) //$NON-NLS-1$ { fList.remove(aFeat); aList.add(aFeat); @@ -552,36 +553,22 @@ for (int i = 0; i < aList.size(); ++i) { - final Ability ability = aList.get(i); - - directChildren[i] = new PObjectNode(); - directChildren[i].setItem(ability); - directChildren[i].setParent(rootAsPObjectNode); - - switch (ability.getFeatType()) - { - case AUTOMATIC: - directChildren[i].setColor(SettingsHandler - .getFeatAutoColor()); - break; - case VIRTUAL: - directChildren[i].setColor(SettingsHandler - .getFeatVirtualColor()); - break; - } + directChildren[i] = + createAbilityPObjectNode(rootAsPObjectNode, aList.get(i)); } rootAsPObjectNode.setChildren(directChildren); // fList now contains only those abilities that have prereqs on other // abilities. + final List<Ability> unmatchedList = new ArrayList<Ability>(fList); int loopmax = 6; // only go 6 levels... while ((fList.size() > 0) && (loopmax-- > 0)) { for (int i = 0; i < fList.size(); ++i) { final Ability ability = fList.get(i); - int placed = 0; + boolean placed = false; // Make a copy of the prereq // list so we don't destroy @@ -590,69 +577,136 @@ for (Prerequisite prereq : ability.getPreReqList()) { - // TODO - Fix this. See comment above. - if ((prereq.getKind() != null) - && prereq.getKind().equalsIgnoreCase("FEAT")) //$NON-NLS-1$ + if (PrerequisiteUtilities.hasPreReqKindOf(prereq, "FEAT") //$NON-NLS-1$ + || PrerequisiteUtilities.hasPreReqKindOf(prereq, + "ABILITY")) //$NON-NLS-1$ { preReqList.add(prereq); } } - // TODO - What should happen if an ability has multiple pres? + // Add ability in each location where it fits, we will tidy up duplicates later for (int j = 0; j < rootAsPObjectNode.getChildCount(); ++j) { final PObjectNode po = rootAsPObjectNode.getChild(j); - placed = placedThisFeatInThisTree(ability, po, preReqList); - - if (placed > 0) - { - break; - } + placed |= placedThisFeatInThisTree(ability, po, preReqList); } - // TODO - Make a constant for this? - if (placed == 2) // i.e. tree match + if (placed) { - fList.remove(ability); - --i; // since we're incrementing in the for loop + unmatchedList.remove(ability); } } } + pruneDuplicatesFromTree(rootAsPObjectNode); // These abilities have PREABILITY tags but we couldn't find a match - // for the ability. - // TODO - This shouldn't happen should it? - if (fList.size() > 0) + // for the ability. e.g. PREABILITY:1,TYPE.Metamagic + // Add them into the root like any other ability. + if (unmatchedList.size() > 0) { - PObjectNode po = new PObjectNode(); - po.setItem(PropertyFactory.getString("in_other")); //$NON-NLS-1$ - final PObjectNode[] cc = new PObjectNode[fList.size()]; + final PObjectNode[] cc = new PObjectNode[unmatchedList.size()]; - for (int i = 0; i < fList.size(); ++i) + for (int i = 0; i < unmatchedList.size(); ++i) { - final Ability ability = fList.get(i); + cc[i] = createAbilityPObjectNode(rootAsPObjectNode, unmatchedList.get(i)); + rootAsPObjectNode.addChild(cc[i], true); + } + } + } - cc[i] = new PObjectNode(); - cc[i].setItem(ability); - cc[i].setParent(po); + /** + * Ensure that each ability only occurs at the deepest level in a + * particular sub tree. So for Dodge/Mobility/Spring Attack, Spring Attack + * should only occur under mobility, and not also under dodge. We had to + * populate first and then remove to ensure that the ability is in all + * appropriate locations. + * @param parent The parent node to have duplicates pruned from. + */ + private void pruneDuplicatesFromTree(PObjectNode parent) + { + if (parent == null || parent.getChildCount() == 0) + { + return; + } - switch (ability.getFeatType()) + List<PObjectNode> deletions = new ArrayList<PObjectNode>(); + for (PObjectNode child : parent.getChildren()) + { + for (PObjectNode sibling : parent.getChildren()) + { + if (sibling != child) { - case AUTOMATIC: - cc[i].setColor(SettingsHandler.getFeatAutoColor()); + if (hasChild(sibling, child.getItem())) + { + deletions.add(child); break; - case VIRTUAL: - cc[i].setColor(SettingsHandler.getFeatVirtualColor()); - break; + } } } - po.setChildren(cc); - rootAsPObjectNode.addChild(po); + pruneDuplicatesFromTree(child); } + for (PObjectNode objectNode : deletions) + { + parent.getChildren().remove(objectNode); + } } /** + * Identify if a node has a child node with the specified item. + * @param node The node whose descendants will be scanned + * @param item The item we are looking for + * @return true if any descendant has the item, false if not. + */ + private boolean hasChild(PObjectNode node, Object item) + { + if (node == null || node.getChildCount() == 0) + { + return false; + } + + for (PObjectNode child : node.getChildren()) + { + if (item == child.getItem()) + { + return true; + } + if (hasChild(child, item)) + { + return true; + } + } + + return false; + } + + /** + * Create a PObjectNode for an ability + * @param parent The intended parent of the node. + * @param ability The ability the node will hold + * @return A new PObjectNode. + */ + private PObjectNode createAbilityPObjectNode(PObjectNode parent, + final Ability ability) + { + final PObjectNode newNode = new PObjectNode(); + newNode.setItem(ability); + newNode.setParent(parent); + + switch (ability.getFeatType()) + { + case AUTOMATIC: + newNode.setColor(SettingsHandler.getFeatAutoColor()); + break; + case VIRTUAL: + newNode.setColor(SettingsHandler.getFeatVirtualColor()); + break; + } + return newNode; + } + + /** * Populates the list of feats as a type->name tree. It sets the root * of the tree to <code>InfoFeats.typeRoot</code>, which contains * the types. It then iterates the feat list and adds each feat to @@ -804,61 +858,53 @@ } } - private int placedThisFeatInThisTree(final Ability anAbility, + private boolean placedThisFeatInThisTree(final Ability anAbility, final PObjectNode po, final List<Prerequisite> aList) { final Ability parentAbility = (Ability) po.getItem(); // must be a Feat - boolean trychildren = false; - boolean thisisit = false; + boolean placed = false; for (final Prerequisite prereq : aList) { - final String pString = prereq.getKey(); - - if (pString.equalsIgnoreCase(parentAbility.getKeyName())) + if ((PrerequisiteUtilities.hasPreReqMatching(prereq, "FEAT", + parentAbility.getKeyName()) + || PrerequisiteUtilities.hasPreReqMatching(prereq, "ABILITY", + parentAbility.getKeyName()))) { - thisisit = true; + boolean alreadyPresent = false; + if (po.getChildCount() > 0) + { + for (PObjectNode pnode : po.getChildren()) + { + if (anAbility.equals(pnode.getItem())) + { + alreadyPresent = true; + break; + } + } + } + if (!alreadyPresent) + { + final PObjectNode p = createAbilityPObjectNode(po, anAbility); + po.addChild(p); + + placed = true; // successfully added + } } - else - { - trychildren = true; // might be a child - } - if (thisisit) + for (int i = 0; i < po.getChildCount(); ++i) { - final PObjectNode p = new PObjectNode(); - p.setItem(anAbility); - p.setParent(po); - po.addChild(p); + boolean j = + placedThisFeatInThisTree(anAbility, po.getChild(i), + aList); - switch (anAbility.getFeatType()) + if (j) { - case AUTOMATIC: - p.setColor(SettingsHandler.getFeatAutoColor()); - break; - case VIRTUAL: - p.setColor(SettingsHandler.getFeatVirtualColor()); - break; + placed = true; } - - return 2; // successfully added } - else if (trychildren) - { - for (int i = 0; i < po.getChildCount(); ++i) - { - int j = - placedThisFeatInThisTree(anAbility, po.getChild(i), - aList); - - if (j == 2) - { - return 2; - } - } - } } - return 0; // not here + return placed; // not here } public void setCurrentAbilityCategory(AbilityCategory newCat) Added: Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/AbilityModelTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/AbilityModelTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/AbilityModelTest.java 2008-03-23 22:14:22 UTC (rev 5686) @@ -0,0 +1,115 @@ +/* + * AbilityModelTest.java + * Copyright 2008 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 23/03/2008 + * + * $Id$ + */ +package pcgen.gui.tabs.ability; + +import java.util.ArrayList; +import java.util.List; + +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Ability; +import pcgen.core.AbilityCategory; +import pcgen.core.PObject; +import pcgen.core.prereq.Prerequisite; +import pcgen.gui.utils.PObjectNode; +import pcgen.persistence.PersistenceLayerException; +import pcgen.persistence.lst.prereq.PreParserFactory; +import pcgen.util.TestHelper; + +/** + * <code>AbilityModelTest</code> verifies that the AbilityModel class + * is functioning correctly. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class AbilityModelTest extends AbstractCharacterTestCase +{ + + /** + * Test building the prereq tree. + * @throws PersistenceLayerException + */ + public void testBuildTreePrereqTree() throws PersistenceLayerException + { + final PreParserFactory factory = PreParserFactory.getInstance(); + List<Ability> abilityList = new ArrayList<Ability>(); + Ability dodge = TestHelper.makeAbility("Dodge", "FEAT", "General"); + Prerequisite prereq = factory.parse("PRESTAT:1,DEX=13"); + dodge.addPreReq(prereq); + abilityList.add(dodge); + + Ability mobility = TestHelper.makeAbility("Mobility", "FEAT", "General"); + prereq = factory.parse("PREFEAT:1,KEY_Dodge"); + mobility.addPreReq(prereq); + prereq = factory.parse("PRESTAT:1,DEX=13"); + mobility.addPreReq(prereq); + abilityList.add(mobility); + + Ability mountedCbt = TestHelper.makeAbility("Mounted Combat", "FEAT", "General"); + prereq = factory.parse("PRESKILL:1,Ride=1"); + mountedCbt.addPreReq(prereq); + abilityList.add(mountedCbt); + + Ability improvedFeint = TestHelper.makeAbility("Improved Feint", "FEAT", "General"); + prereq = factory.parse("PREFEAT:1,KEY_Combat Expertise"); + improvedFeint.addPreReq(prereq); + abilityList.add(improvedFeint); + + Ability springAttack = TestHelper.makeAbility("Spring Attack", "FEAT", "General"); + prereq = factory.parse("PREATT:4"); + springAttack.addPreReq(prereq); + prereq = factory.parse("PREFEAT:2,KEY_Dodge,KEY_Mobility"); + springAttack.addPreReq(prereq); + prereq = factory.parse("PRESTAT:1,DEX=13"); + springAttack.addPreReq(prereq); + abilityList.add(springAttack); + + AbilityModel am = + new AbilityModel(getCharacter(), abilityList, + AbilityCategory.FEAT, + AbilitySelectionPanel.ViewMode.PREREQTREE, "Unit test"); + PObjectNode root = (PObjectNode) am.getRoot(); + // Check root + assertNotNull(root); + + // Check first level + assertEquals("First level first entry", "KEY_Dodge", ((PObject)root.getChild(0).getItem()).getKeyName()); + assertEquals("First level second entry", "KEY_Improved Feint", ((PObject)root.getChild(1).getItem()).getKeyName()); + assertEquals("First level third entry", "KEY_Mounted Combat", ((PObject)root.getChild(2).getItem()).getKeyName()); + assertEquals(3, root.getChildCount()); + + // Check second level + PObjectNode secondLevelBase = root.getChild(0); + assertEquals("Second level first entry", "KEY_Mobility", ((PObject)secondLevelBase.getChild(0).getItem()).getKeyName()); + assertEquals(1, secondLevelBase.getChildCount()); + + // Check third level + PObjectNode thirdLevelBase = secondLevelBase.getChild(0); + assertEquals("Third level first entry", "KEY_Spring Attack", ((PObject)thirdLevelBase.getChild(0).getItem()).getKeyName()); + assertEquals(1, thirdLevelBase.getChildCount()); + } + +} Property changes on: Trunk/pcgen/code/src/test/pcgen/gui/tabs/ability/AbilityModelTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |