use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreCSkillTest method testCSkillServesAs.
public void testCSkillServesAs() throws Exception {
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, myClass, true);
myClass = character.getClassKeyed("My Class");
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
Skill bar = new Skill();
bar.setName("Bar");
bar.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(bar);
Skill foo = new Skill();
foo.setName("Foo");
foo.addToListFor(ListKey.SERVES_AS_SKILL, CDOMDirectSingleRef.getRef(bar));
foo.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
Globals.getContext().getReferenceContext().importObject(foo);
Skill baz = new Skill();
baz.setName("Baz");
baz.addToListFor(ListKey.TYPE, Type.getConstant("Baz"));
Globals.getContext().getReferenceContext().importObject(baz);
Skill fee = new Skill();
fee.setName("Fee");
fee.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(fee);
character.addLocalCost(myClass, fee, SkillCost.CLASS, myClass);
character.addLocalCost(myClass, foo, SkillCost.CLASS, myClass);
prereq = factory.parse("PRECSKILL:1,Bar");
assertTrue("Character has 1 Listen Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Bar,Fee");
assertTrue("Character has a Bar Skill and a Fee Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Baz,Fee");
assertFalse("Character does not have both Baz and Fee Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:1,TYPE=Bar");
assertTrue("Character has 1 Bar Type Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,TYPE=Bar");
assertTrue("Character has 2 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:3,TYPE=Bar");
assertFalse("Character has less than 3 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreCampaignTest method testTypeMatch.
/**
* Test matching by book type.
*
* @throws Exception the exception
*/
@Test
public void testTypeMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCamp1 = factory.parse("PRECAMPAIGN:1,BOOKTYPE=Wild");
assertFalse("No typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp6TypeParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertFalse("Nested typed campaign should not be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp4Wild.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreClassTest method testLevelsTwoClasses.
public void testLevelsTwoClasses() throws Exception {
final PCClass pcClass = new PCClass();
pcClass.setName("MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
final PCClass pcClass2 = new PCClass();
pcClass2.setName("MyClass2");
BuildUtilities.setFact(pcClass2, "SpellType", "Divine");
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, pcClass);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite prereq = factory.parse("PRECLASS:2,MyClass=1,MyClass2=2");
assertEquals(false, PrereqHandler.passes(prereq, character, null));
character.incrementClassLevel(1, pcClass2);
assertEquals(false, PrereqHandler.passes(prereq, character, null));
character.incrementClassLevel(1, pcClass2);
assertEquals(true, PrereqHandler.passes(prereq, character, null));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreArmorTypeTest method testType.
/**
* Test armor type tests
* @throws Exception
*/
public void testType() throws Exception {
final PlayerCharacter character = getCharacter();
final Equipment armor = new Equipment();
armor.setName("Chainmail");
character.addEquipment(armor);
armor.setIsEquipped(true, character);
character.doAfavorForAunitTestThatIgnoresEquippingRules();
Prerequisite prereq = new Prerequisite();
prereq.setKind("armortype");
prereq.setKey("TYPE=Medium");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.EQ);
assertFalse("Equipment has no type", PrereqHandler.passes(prereq, character, null));
armor.addType(Type.getConstant("ARMOR"));
armor.addType(Type.getConstant("MEDIUM"));
assertTrue("Armor is medium", PrereqHandler.passes(prereq, character, null));
prereq.setKey("TYPE.Heavy");
assertFalse("Armor is not heavy", PrereqHandler.passes(prereq, character, null));
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREARMORTYPE:2,TYPE=Medium,Full%");
assertFalse("Armor is not Full something", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREARMORTYPE:2,TYPE=Medium,Chain%");
assertTrue("Armor is medium and Chain", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreBaseSizeTest method testModBaseSize.
/**
* Test to make sure template SIZE: changes the base size.
* @throws Exception
*/
public void testModBaseSize() throws Exception {
final PlayerCharacter character = getCharacter();
character.setRace(race);
character.addTemplate(template);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREBASESIZEEQ:L");
assertTrue("Character's base size should be equal to Large", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELTEQ:L");
assertTrue("Character's base size should be <= to L", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGTEQ:L");
assertTrue("Character's base size should be >= to L", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:Small");
assertTrue("Character's base size should be > to Small", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:Huge");
assertTrue("Character's base size should be < to Large", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:L");
assertFalse("Character's base size should not be < to L", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:L");
assertFalse("Character's base size should not be > to Medium", PrereqHandler.passes(prereq, character, null));
}
Aggregations