Search in sources :

Example 76 with PreParserFactory

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));
}
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 77 with PreParserFactory

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

Example 78 with PreParserFactory

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

Example 79 with PreParserFactory

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));
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 80 with PreParserFactory

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

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