Search in sources :

Example 66 with PreParserFactory

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

the class PreDeityAlignTest method testAbbrev.

/**
	 * Test that alignment abbreviation values work correctly in Deity Align tests.
	 * @throws Exception
	 */
public void testAbbrev() throws Exception {
    final PlayerCharacter character = getCharacter();
    character.setAlignment(ng);
    character.setDeity(deity);
    assertEquals("Deity should have been set for character.", deity, character.getDeity());
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("deityAlign");
    prereq.setOperand("NG");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertTrue("Abbrev NG should match deity's alignment of NG", PrereqHandler.passes(prereq, character, null));
    prereq = new Prerequisite();
    prereq.setKind("deityAlign");
    prereq.setOperand("LG");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Abbrev LG should not match deity's alignment of NG", PrereqHandler.passes(prereq, character, null));
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREDEITYALIGN:NG");
    assertTrue("Abbrev NG should match deity's alignment of NG", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREDEITYALIGN:LG");
    assertFalse("Abbrev LG should not match deity's alignment of NG", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 67 with PreParserFactory

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

the class PreDeityDomainTest method testMultiple.

public void testMultiple() throws Exception {
    final PlayerCharacter character = getCharacter();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREDEITYDOMAIN:1,Good,Law");
    assertFalse("Character has no deity selected", PrereqHandler.passes(prereq, character, null));
    character.setAlignment(ng);
    character.setDeity(deity);
    assertTrue("Character's deity has Good domain", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREDEITYDOMAIN:2,Good,Law");
    assertFalse("Character's deity doesn't have Law domain", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREDEITYDOMAIN:2,Good,Animal");
    assertTrue("Character's deity has Good and animal domains", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 68 with PreParserFactory

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

the class PreCityTest method testCity.

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

Example 69 with PreParserFactory

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

the class PreClassTest method testSpellcasterLevelsTwoClasses.

public void testSpellcasterLevelsTwoClasses() 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", "Divine");
    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=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 70 with PreParserFactory

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

the class PreAttTest method testAtt.

/**
	 * Test the PREATT code
	 * @throws Exception
	 */
public void testAtt() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(1, myClass, true);
    character.calcActiveBonuses();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREATT:6");
    assertTrue("Character's BAB should be 6", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREATT:7");
    assertFalse("Character's BAB should be less than 7", PrereqHandler.passes(prereq, character, null));
    final BonusObj toHitBonus = Bonus.newBonus(context, "COMBAT|TOHIT|1");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, toHitBonus);
    character.calcActiveBonuses();
    assertFalse("Character's BAB should be less than 7", 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)

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