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);
}
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));
}
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);
}
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));
}
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);
}
Aggregations