Search in sources :

Example 21 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreClassTest method testSpellcaster.

/**
	 * Test to ensure that a character with a spellcasting class can be found
	 * @throws Exception
	 */
public void testSpellcaster() throws Exception {
    LoadContext context = Globals.getContext();
    final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
    context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
    context.loadCampaignFacets();
    final PlayerCharacter character = getCharacter();
    setPCStat(character, cha, 12);
    character.incrementClassLevel(1, pcClass);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("class");
    prereq.setKey("Spellcaster");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.GTEQ);
    final PreClassTester test = new PreClassTester();
    final int passes = test.passes(prereq, character, null);
    assertEquals(1, passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreClassTester(plugin.pretokens.test.PreClassTester) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass)

Example 22 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreCheckTest method testBonus.

public void testBonus() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    final BonusObj fortBonus = Bonus.newBonus(context, "SAVE|Fortitude|1");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortBonus);
    character.incrementClassLevel(1, myClass, true);
    character.calcActiveBonuses();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRECHECK:1,Fortitude=1");
    assertTrue("Character's Fort save should be 1", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:1,Will=2");
    assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:1,Fortitude=1,Will=3");
    assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:2,Fortitude=2,Will=2");
    assertFalse("Character's Fort save not 1", 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 23 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreCheckTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    PCCheck obj = new PCCheck();
    obj.setName("Fortitude");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Reflex");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Will");
    Globals.getContext().getReferenceContext().importObject(obj);
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    final BonusObj fortRefBonus = Bonus.newBonus(context, "SAVE|BASE.Fortitude,BASE.Reflex|CL/3");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortRefBonus);
    final BonusObj willBonus = Bonus.newBonus(context, "SAVE|BASE.Will|CL/2+2");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, willBonus);
    Globals.getContext().getReferenceContext().importObject(myClass);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) PCCheck(pcgen.core.PCCheck)

Example 24 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreEquipBothTest method testWield.

/**
	 * Test wield category tests
	 * @throws Exception
	 */
public void testWield() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Test Race");
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    character.setRace(race);
    LoadContext context = Globals.getContext();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_BOTH);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equipboth");
    prereq.setKey("WIELDCATEGORY=OneHanded");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    // Test 3.0 Style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.SIZE, largeRef);
    longsword.put(ObjectKey.BASESIZE, largeRef);
    assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
    // Test 3.5 style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) WieldCategory(pcgen.core.character.WieldCategory) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 25 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreClassTest method testCharWithMultipleSpellClasses.

/**
	 * 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 testCharWithMultipleSpellClasses() 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 Prerequisite prereq = new Prerequisite();
    prereq.setKind("class");
    prereq.setKey("SPELLCASTER.ARCANE");
    prereq.setOperand("3");
    prereq.setTotalValues(true);
    prereq.setOperator(PrerequisiteOperator.GTEQ);
    final PreClassTester test = new PreClassTester();
    final int passes = test.passes(prereq, character, null);
    assertEquals(3, passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreClassTester(plugin.pretokens.test.PreClassTester) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass)

Aggregations

LoadContext (pcgen.rules.context.LoadContext)141 PlayerCharacter (pcgen.core.PlayerCharacter)58 BonusObj (pcgen.core.bonus.BonusObj)48 PCClass (pcgen.core.PCClass)32 URI (java.net.URI)25 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)25 URISyntaxException (java.net.URISyntaxException)20 Campaign (pcgen.core.Campaign)16 Race (pcgen.core.Race)16 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)16 Equipment (pcgen.core.Equipment)15 UnreachableError (pcgen.base.lang.UnreachableError)14 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)14 PCClassLoader (pcgen.persistence.lst.PCClassLoader)14 Spell (pcgen.core.spell.Spell)13 Ability (pcgen.core.Ability)12 PCTemplate (pcgen.core.PCTemplate)12 SizeAdjustment (pcgen.core.SizeAdjustment)10 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)9 Skill (pcgen.core.Skill)9