Search in sources :

Example 31 with PreParserFactory

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));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) PCClass(pcgen.core.PCClass)

Example 32 with PreParserFactory

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);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) PreClassTester(plugin.pretokens.test.PreClassTester) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass)

Example 33 with PreParserFactory

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));
}
Also used : PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) PersistenceManager(pcgen.persistence.PersistenceManager) ArrayList(java.util.ArrayList) URI(java.net.URI) Test(org.junit.Test)

Example 34 with PreParserFactory

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");
}
Also used : PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) QualifiedObject(pcgen.core.QualifiedObject) Domain(pcgen.core.Domain) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Prerequisite(pcgen.core.prereq.Prerequisite) Test(org.junit.Test)

Example 35 with PreParserFactory

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));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)107 PlayerCharacter (pcgen.core.PlayerCharacter)89 LoadContext (pcgen.rules.context.LoadContext)16 BonusObj (pcgen.core.bonus.BonusObj)13 Prerequisite (pcgen.core.prereq.Prerequisite)12 Ability (pcgen.core.Ability)11 PCClass (pcgen.core.PCClass)11 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 StringTokenizer (java.util.StringTokenizer)5 Domain (pcgen.core.Domain)5 PCTemplate (pcgen.core.PCTemplate)5 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)5 URI (java.net.URI)4 Equipment (pcgen.core.Equipment)4 PersistenceManager (pcgen.persistence.PersistenceManager)4 DamageReduction (pcgen.cdom.content.DamageReduction)3 ClassSource (pcgen.cdom.helper.ClassSource)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 QualifiedObject (pcgen.core.QualifiedObject)3