use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class TempBonusTest method testANYPCTemporaryBonus.
public void testANYPCTemporaryBonus() throws PersistenceLayerException {
LoadContext context = Globals.getContext();
BonusObj bonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
Spell spell = context.getReferenceContext().constructNowIfNecessary(Spell.class, "PCTempBonusItem");
spell.addToListFor(ListKey.BONUS_ANYPC, bonus);
assertTrue(TempBonusHelper.hasAnyPCTempBonus(spell));
assertFalse(TempBonusHelper.hasPCTempBonus(spell));
assertTrue(TempBonusHelper.hasNonPCTempBonus(spell));
assertTrue(TempBonusHelper.hasCharacterTempBonus(spell));
assertFalse(TempBonusHelper.hasEquipmentTempBonus(spell));
try {
assertTrue(TempBonusHelper.getEquipmentApplyString(spell).isEmpty());
} catch (NullPointerException e) {
//This is appropriate too
}
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class DomainChoiceManagerTest method test001.
/**
* Test the constructor
*/
public void test001() {
Race pObj = new Race();
pObj.setName("My PObject");
LoadContext context = Globals.getContext();
Domain foo = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Foo");
Domain bar = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Bar");
Domain baz = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Baz");
Domain qux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Qux");
Domain quux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Quux");
context.unconditionallyProcess(pObj, "CHOOSE", "DOMAIN|KEY_Foo|KEY_Bar|KEY_Baz|KEY_Qux|KEY_Quux");
assertTrue(context.getReferenceContext().resolveReferences(null));
assertNotNull(pObj.get(ObjectKey.CHOOSE_INFO));
pObj.put(FormulaKey.NUMCHOICES, FormulaFactory.getFormulaFor(4));
PlayerCharacter aPC = getCharacter();
ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, aPC);
is(choiceManager, not(eq(null)), "Found the chooser");
List<Domain> aList = new ArrayList<>();
List<Domain> sList = new ArrayList<>();
choiceManager.getChoices(aPC, aList, sList);
assertEquals(5, aList.size());
assertTrue(aList.contains(foo));
assertTrue(aList.contains(bar));
assertTrue(aList.contains(baz));
assertTrue(aList.contains(qux));
assertTrue(aList.contains(quux));
assertEquals(0, sList.size());
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PlayerCharacterTest method testMakeIntoExClass.
public void testMakeIntoExClass() {
// Prepare class and ex-class
LoadContext context = Globals.getContext();
PCClass paladin = new PCClass();
paladin.setName("Paladin");
context.getReferenceContext().importObject(paladin);
PCClass exPaladin = new PCClass();
exPaladin.setName("exPaladin");
context.getReferenceContext().importObject(exPaladin);
paladin.put(ObjectKey.EX_CLASS, context.getReferenceContext().getCDOMReference(PCClass.class, exPaladin.getKeyName()));
readyToRun();
PlayerCharacter pc = getCharacter();
// Add a level of the class
pc.incrementClassLevel(2, paladin, true, false);
PCClass pcPalClass = pc.getClassKeyed(paladin.getKeyName());
pc.setHP(pc.getActiveClassLevel(pcPalClass, 0), 10);
pc.setHP(pc.getActiveClassLevel(pcPalClass, 1), 6);
// Make it into an ex-class
pc.makeIntoExClass(pcPalClass);
assertNull("Paladin class should not be held", pc.getClassKeyed(paladin.getKeyName()));
PCClass pcExPalClass = pc.getClassKeyed(exPaladin.getKeyName());
assertNotNull("Ex-Paladin class should be held", pcExPalClass);
PCClassLevel pcLvl1 = pc.getActiveClassLevel(pcExPalClass, 0);
assertNotNull("Level 1 should be Ex-Paladin", pcLvl1);
assertEquals("Should still be level 2 character", 2, pc.getTotalLevels());
assertEquals("Hp at first level incorrect", 10, (int) pc.getHP(pcLvl1));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class SizeAdjustmentTest method testSizeMod.
public void testSizeMod() throws Exception {
Race race = new Race();
race.setName("Race");
PCTemplate template = new PCTemplate();
template.setName("Template");
Deity deity = new Deity();
deity.setName("Deity");
LoadContext context = Globals.getContext();
context.getReferenceContext().importObject(template);
context.unconditionallyProcess(race, "SIZE", "S");
context.unconditionallyProcess(template, "SIZE", "D");
context.unconditionallyProcess(deity, "BONUS", "SIZEMOD|NUMBER|1");
context.resolveDeferredTokens();
context.getReferenceContext().resolveReferences(null);
PlayerCharacter pc = getCharacter();
assertEquals("M", pc.getDisplay().getSize());
pc.setRace(race);
assertEquals("S", pc.getDisplay().getSize());
pc.addTemplate(template);
assertEquals("D", pc.getDisplay().getSize());
pc.setDeity(deity);
pc.calcActiveBonuses();
assertEquals("T", pc.getDisplay().getSize());
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PreCheckBaseTest 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("PRECHECKBASE:1,Fortitude=1");
assertFalse("Character's base Fort save should be 0", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:1,Will=2");
assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:1,Fortitude=1,Will=3");
assertFalse("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECHECKBASE:2,Fortitude=1,Will=2");
assertFalse("Character's base Fort save not 1", PrereqHandler.passes(prereq, character, null));
}
Aggregations