Search in sources :

Example 71 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreBaseSizeTest method testBaseSize.

/**
	 * Test the PREBASESIZE code
	 * @throws Exception
	 */
public void testBaseSize() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREBASESIZEEQ:Medium");
    assertTrue("Character's base size should be equal to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZELTEQ:Medium");
    assertTrue("Character's base size should be <= to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZEGTEQ:Medium");
    assertTrue("Character's base size should be >= to Medium", 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:Large");
    assertTrue("Character's base size should be < to Large", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZELT:Medium");
    assertFalse("Character's base size should not be < to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZEGT:Medium");
    assertFalse("Character's base size should not be > to Medium", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 72 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreClassTest method testSpellcasterTypeLevelsTwoClasses.

public void testSpellcasterTypeLevelsTwoClasses() throws Exception {
    final PCClass pcClass = new PCClass();
    LoadContext context = Globals.getContext();
    pcClass.setName("MyClass");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    BonusObj aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass|CL");
    if (aBonus != null) {
        pcClass.addToListFor(ListKey.BONUS, aBonus);
    }
    final PCClass pcClass2 = new PCClass();
    pcClass2.setName("MyClass2");
    BuildUtilities.setFact(pcClass2, "SpellType", "Arcane");
    aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass2|CL");
    if (aBonus != null) {
        pcClass.addToListFor(ListKey.BONUS, aBonus);
    }
    final PlayerCharacter character = getCharacter();
    final PreParserFactory factory = PreParserFactory.getInstance();
    Prerequisite prereq = factory.parse("PRECLASS:2,SPELLCASTER.ARCANE=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) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass)

Example 73 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreClassTest method testFromParserAny.

/**
	 * 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 testFromParserAny() throws Exception {
    LoadContext context = Globals.getContext();
    final PCClass pcClass = new PCClass();
    pcClass.setName("MyClass");
    context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
    final PCClass pcClass2 = new PCClass();
    pcClass2.setName("Other Class");
    context.unconditionallyProcess(pcClass2, "SPELLSTAT", "INT");
    BuildUtilities.setFact(pcClass2, "SpellType", "Arcane");
    context.unconditionallyProcess(pcClass2.getOriginalClassLevel(1), "CAST", "5,4");
    final PlayerCharacter character = getCharacter();
    character.incrementClassLevel(1, pcClass);
    character.incrementClassLevel(2, pcClass2);
    final PreParserFactory factory = PreParserFactory.getInstance();
    final Prerequisite prereq = factory.parse("PRECLASS:1,ANY=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 74 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreBirthplaceTest method testAtt.

/**
	 * Test the PREBIRTHPLACE code
	 * @throws Exception
	 */
public void testAtt() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setPCAttribute(PCAttribute.BIRTHPLACE, "Klamath");
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREBIRTHPLACE:Klamath");
    assertTrue("Character is from Klamath", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBIRTHPLACE:KLAMATH");
    assertTrue("Case is not significant", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBIRTHPLACE:Klam");
    assertFalse("Requires a full match", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 75 with PreParserFactory

use of pcgen.persistence.lst.prereq.PreParserFactory in project pcgen by PCGen.

the class PreCampaignTest method testNestedKeyMatch.

/**
	 * Test matching by key.
	 * 
	 * @throws Exception the exception
	 */
@Test
public void testNestedKeyMatch() 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 preCampaign = factory.parse("PRECAMPAIGN:1,INCLUDES=Camp3");
    assertFalse("Nonpresent campaign should not be found", PrereqHandler.passes(preCampaign, null, sourceCamp));
    uris.add(camp2KeyParent.getSourceURI());
    pmgr.setChosenCampaignSourcefiles(uris);
    assertTrue("Present but nested campaign should be found", PrereqHandler.passes(preCampaign, 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)

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