use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreCampaignTest method testKeyMatch.
/**
* Test matching by key.
*
* @throws Exception the exception
*/
@Test
public void testKeyMatch() throws Exception {
// Setup campaigns
PersistenceManager pmgr = PersistenceManager.getInstance();
List<URI> uris = new ArrayList<>();
pmgr.setChosenCampaignSourcefiles(uris);
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite preCamp1 = factory.parse("PRECAMPAIGN:1,Camp1");
assertFalse("Nonpresent campaign should not be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris = new ArrayList<>();
uris.add(camp1.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Present campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp2KeyParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
Prerequisite preCamp3 = factory.parse("PRECAMPAIGN:1,Camp3");
assertFalse("Present but nested campaign should not be found", PrereqHandler.passes(preCamp3, null, sourceCamp));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreClassTest method testAnyTwoLevelsTwoClasses.
public void testAnyTwoLevelsTwoClasses() 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();
final PreParserFactory factory = PreParserFactory.getInstance();
Prerequisite prereq = factory.parse("PRECLASS:2,ANY=2");
character.incrementClassLevel(2, pcClass);
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 PreDRTest method testMultiOr.
/**
* Make sure or case works
* @throws Exception
*/
public void testMultiOr() throws Exception {
final PlayerCharacter character = getCharacter();
character.setRace(race);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREDR:1,+1=10,+2=5");
assertFalse("Character has no DR", PrereqHandler.passes(prereq, character, null));
race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus1);
//This weirdness is because we are altering the race after application (no-no at runtime)
character.setRace(null);
character.setRace(race);
assertFalse("Character DR not 10", PrereqHandler.passes(prereq, character, null));
DamageReduction drPlus2_5 = new DamageReduction(FormulaFactory.getFormulaFor(5), "+2");
race.addToListFor(ListKey.DAMAGE_REDUCTION, drPlus2_5);
//This weirdness is because we are altering the race after application (no-no at runtime)
character.setRace(null);
character.setRace(race);
assertTrue("Character has DR 5/+2", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreHDTest method testClassLevels.
/**
* Tests using monster class levels
* @throws Exception
*/
public void testClassLevels() throws Exception {
monClass.setName("Humanoid");
monClass.put(ObjectKey.IS_MONSTER, true);
Globals.getContext().getReferenceContext().importObject(monClass);
race1.setName("Bugbear");
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race1.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
race1.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(monClass), FormulaFactory.getFormulaFor(3)));
Globals.getContext().getReferenceContext().importObject(race1);
final PlayerCharacter character = new PlayerCharacter();
character.setRace(race1);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREHD:MIN=4");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3,MAX=6");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=4,MAX=7");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=2");
assertFalse("Character doesn't have 2 or less HD", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreHandsTest method testHands.
/**
* Test the PREHANDS code
* @throws Exception
*/
public void testHands() throws Exception {
final PlayerCharacter character = getCharacter();
Race race = new Race();
race.put(IntegerKey.CREATURE_HANDS, 2);
character.setRace(race);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREHANDSLT:2");
assertFalse("Character has more than 1 hand", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHANDSEQ:2");
assertTrue("Character has 2 hands", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHANDSGT:2");
assertFalse("Character does not have more than 2 hands", PrereqHandler.passes(prereq, character, null));
}
Aggregations