Search in sources :

Example 11 with PreParserFactory

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

the class PreLevelTest method testPCLevel.

/**
	 * Make sure BONUS:PCLEVEL is not counted
	 * @throws Exception
	 */
public void testPCLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVEL:MIN=6");
    final BonusObj levelBonus = Bonus.newBonus(context, "PCLEVEL|MY_CLASS|2");
    myClass.addToListFor(ListKey.BONUS, levelBonus);
    character.calcActiveBonuses();
    assertFalse("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MAX=6");
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MAX=6");
    assertFalse("Character is less than 6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=5");
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=4,MAX=6");
    assertTrue("Character has 4-6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=6,MAX=8");
    assertFalse("Character does not have 6-8 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=6,MAX=8");
    assertTrue("Character is not 6-8 levels", 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)

Example 12 with PreParserFactory

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

the class PreLevelTest method testLevel.

/**
	 * Test that Level works
	 * @throws Exception
	 */
public void testLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.incrementClassLevel(1, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVEL:MIN=2");
    assertFalse("Character is not 2nd level", PrereqHandler.passes(prereq, character, null));
    character.incrementClassLevel(1, myClass, true);
    assertTrue("Character has 2 levels", PrereqHandler.passes(prereq, character, null));
    character.incrementClassLevel(1, myClass, true);
    prereq = factory.parse("PRELEVEL:MIN=2,MAX=3");
    assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, character, null));
    character.incrementClassLevel(1, myClass, true);
    assertFalse("Character is not 2nd or 3rd level", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=2,MAX=3");
    assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=4");
    assertFalse("Character is 4 or higher level", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MAX=3");
    assertTrue("Character is 3rd or higher level", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 13 with PreParserFactory

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

the class PreFactSetTest method testFact.

/**
	 * Test the PREFACT code
	 * @throws Exception
	 */
public void testFact() throws Exception {
    final PlayerCharacter character = getCharacter();
    Deity deity = new Deity();
    BuildUtilities.addToFactSet(deity, "PANTHEON", "Greek");
    BuildUtilities.addToFactSet(deity, "PANTHEON", "War");
    deity.setName("Ares");
    character.setDeity(deity);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=Roman");
    assertFalse("Character's deity should not match requirement", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=War");
    assertTrue("Character's deity should match pantheon", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=Greek");
    assertTrue("Character's deity should match pantheon", PrereqHandler.passes(prereq, character, null));
}
Also used : Deity(pcgen.core.Deity) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 14 with PreParserFactory

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

the class PreFactTest method testFact.

/**
	 * Test the PREFACT code
	 * @throws Exception
	 */
public void testFact() throws Exception {
    final PlayerCharacter character = getCharacter();
    Race race = new Race();
    BuildUtilities.setFact(race, "ABB", "Hgln");
    race.setName("Hobgoblin");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREFACT:1,RACE,ABB=Hum");
    assertFalse("Character should not be a matching race", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREFACT:1,RACE,ABB=Hgln");
    assertTrue("Character should be a matching race", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) Race(pcgen.core.Race)

Example 15 with PreParserFactory

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

the class PreHPTest method testHP.

/**
	 * Test the PREHP code
	 * @throws Exception
	 */
public void testHP() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(1, myClass, true);
    myClass = character.getClassList().get(0);
    PCClassLevel pcl = character.getActiveClassLevel(myClass, 1);
    character.setHP(pcl, 4);
    character.calcActiveBonuses();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREHP:4");
    assertTrue("Character should have 4 hp", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHP:5");
    assertFalse("Character should have less than 5 hp", PrereqHandler.passes(prereq, character, null));
    final BonusObj hpBonus = Bonus.newBonus(context, "HP|CURRENTMAX|1");
    myClass.addToListFor(ListKey.BONUS, hpBonus);
    character.calcActiveBonuses();
    assertTrue("Character should have 5 hp", 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) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

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