use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreClassTest method testAnyLevelsTwoClasses.
public void testAnyLevelsTwoClasses() 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=1");
character.incrementClassLevel(1, pcClass);
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 PreClassTest method testFromParserCharWithMultipleSpellClasses.
/**
* Test to ensure that a character will fail a test
* if it does not have the correct number of levels
* in the class.
* @throws Exception
*/
public void testFromParserCharWithMultipleSpellClasses() throws Exception {
LoadContext context = Globals.getContext();
final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
final PCClass pcClass2 = context.getReferenceContext().constructCDOMObject(PCClass.class, "Other Class");
context.unconditionallyProcess(pcClass2, "SPELLSTAT", "INT");
BuildUtilities.setFact(pcClass2, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass2.getOriginalClassLevel(1), "CAST", "5,4");
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
context.loadCampaignFacets();
final PlayerCharacter character = getCharacter();
setPCStat(character, cha, 12);
setPCStat(character, intel, 12);
character.incrementClassLevel(1, pcClass);
character.incrementClassLevel(2, pcClass2);
final PreParserFactory factory = PreParserFactory.getInstance();
final Prerequisite prereq = factory.parse("PRECLASS:1,SPELLCASTER.ARCANE=3");
final PreClassTester test = new PreClassTester();
int passes = test.passes(prereq, character, null);
// Doens't pass - levels not summed...
assertEquals(0, passes);
character.incrementClassLevel(1, pcClass2);
passes = test.passes(prereq, character, null);
assertEquals(1, passes);
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class PreCampaignTest method testNestedTypeMatch.
/**
* Test matching by book type.
*
* @throws Exception the exception
*/
@Test
public void testNestedTypeMatch() 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,INCLUDESBOOKTYPE=Wild");
assertFalse("No typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
uris.add(camp6TypeParent.getSourceURI());
pmgr.setChosenCampaignSourcefiles(uris);
assertTrue("Nested typed campaign should be found", PrereqHandler.passes(preCamp1, null, sourceCamp));
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class DomainTokenTest method testUnparseSinglePre.
@Test
public void testUnparseSinglePre() throws PersistenceLayerException {
Domain wp1 = construct(primaryContext, "TestWP1");
CDOMDirectSingleRef<Domain> ref = CDOMDirectSingleRef.getRef(wp1);
PreParserFactory prereqParser = PreParserFactory.getInstance();
Prerequisite prereq = prereqParser.parse("PRERACE:1,Dwarf");
assertNotNull(prereq);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(ref, prereq);
primaryProf.addToListFor(ListKey.DOMAIN, qo);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue() + "|PRERACE:1,Dwarf");
}
use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.
the class DescriptionTest method testPreReqs.
/**
* Test PREREQs for Desc
* @throws Exception
*/
public void testPreReqs() throws Exception {
final Ability dummy = TestHelper.makeAbility("dummy", AbilityCategory.FEAT, "Foo");
final String simpleDesc = "This is a test";
final Description desc = new Description(simpleDesc);
final PreParserFactory factory = PreParserFactory.getInstance();
final Prerequisite prereqNE = factory.parse("PRETEMPLATE:1,KEY_Natural Lycanthrope");
desc.addPrerequisite(prereqNE);
is(desc.getDescription(getCharacter(), Collections.singletonList(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, dummy))), strEq(""));
PCTemplate template = new PCTemplate();
template.setName("Natural Lycanthrope");
template.put(StringKey.KEY_NAME, "KEY_Natural Lycanthrope");
Globals.getContext().getReferenceContext().importObject(template);
getCharacter().addTemplate(template);
is(desc.getDescription(getCharacter(), Collections.singletonList(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, dummy))), strEq(simpleDesc));
}
Aggregations