use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class SkillCostDisplayTest method setUp.
/**
* @see pcgen.AbstractCharacterTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
if (firstTime) {
firstTime = false;
pcClass = new PCClass();
TestHelper.makeSkill("Bluff", "Charisma", cha, true, SkillArmorCheck.NONE);
TestHelper.makeSkill("Listen", "Wisdom", wis, true, SkillArmorCheck.NONE);
skillFocus = TestHelper.makeAbility("Skill Focus", AbilityCategory.FEAT, "General");
BonusObj aBonus = Bonus.newBonus(context, "SKILL|LIST|3");
if (aBonus != null) {
skillFocus.addToListFor(ListKey.BONUS, aBonus);
}
skillFocus.put(ObjectKey.MULTIPLE_ALLOWED, true);
Globals.getContext().unconditionallyProcess(skillFocus, "CHOOSE", "SKILL|TYPE.Strength|TYPE.Dexterity|TYPE.Constitution|TYPE.Intelligence|TYPE.Wisdom|TYPE.Charisma");
persuasive = TestHelper.makeAbility("Persuasive", AbilityCategory.FEAT, "General");
aBonus = Bonus.newBonus(context, "SKILL|KEY_Bluff,KEY_Listen|2");
if (aBonus != null) {
persuasive.addToListFor(ListKey.BONUS, aBonus);
}
persuasive.put(ObjectKey.MULTIPLE_ALLOWED, false);
}
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, pcClass);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PlayerCharacterTest method setUp.
// /**
// * @return Test
// */
// public static Test suite()
// {
// return new TestSuite(PlayerCharacterTest.class);
// }
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
// Giant Class
giantClass = new PCClass();
giantClass.setName("Giant");
BuildUtilities.setFact(giantClass, "ClassType", "Monster");
final BonusObj babClassBonus = Bonus.newBonus(context, "COMBAT|BASEAB|CL*3/4");
giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
context.getReferenceContext().importObject(giantClass);
// Human
human = new Race();
final BonusObj humanRaceFeatBonus = Bonus.newBonus(context, "FEAT|POOL|2");
human.addToListFor(ListKey.BONUS, humanRaceFeatBonus);
human.ownBonuses(human);
// Giant Race
giantRace = new Race();
giantRace.setName("Ogre");
giantRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(giantClass), FormulaFactory.getFormulaFor(4)));
giantRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, 100);
final BonusObj giantRaceFeatBonus = Bonus.newBonus(context, "FEAT|POOL|1");
giantRace.addToListFor(ListKey.BONUS, giantRaceFeatBonus);
giantRace.ownBonuses(giantRace);
context.getReferenceContext().importObject(giantRace);
// Create the monster class type
SettingsHandler.getGame().addClassType("Monster CRFORMULA:0 ISMONSTER:YES XPPENALTY:NO");
pcClass = new PCClass();
pcClass.setName("MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
context.getReferenceContext().importObject(pcClass);
classMemDivine = new PCClass();
classMemDivine.setName("MemDivine");
BuildUtilities.setFact(classMemDivine, "SpellType", "Divine");
classMemDivine.put(ObjectKey.MEMORIZE_SPELLS, true);
context.unconditionallyProcess(classMemDivine, "SPELLSTAT", "WIS");
context.unconditionallyProcess(classMemDivine.getOriginalClassLevel(1), "CAST", "3,2,2");
context.unconditionallyProcess(classMemDivine, "BONUS", "DOMAIN|NUMBER|1");
context.getReferenceContext().importObject(classMemDivine);
classWarmind = new PCClass();
classWarmind.setName("Warmind");
context.getReferenceContext().importObject(classWarmind);
class2LpfM = new PCClass();
class2LpfM.setName("2LpfM");
BuildUtilities.setFact(class2LpfM, "ClassType", "Monster");
class2LpfM.put(IntegerKey.LEVELS_PER_FEAT, 2);
class2LpfM.put(StringKey.LEVEL_TYPE, "MONSTER");
context.getReferenceContext().importObject(class2LpfM);
class3LpfM = new PCClass();
class3LpfM.setName("3LpfM");
BuildUtilities.setFact(class3LpfM, "ClassType", "Monster");
class3LpfM.put(IntegerKey.LEVELS_PER_FEAT, 3);
class3LpfM.put(StringKey.LEVEL_TYPE, "MONSTER");
context.getReferenceContext().importObject(class3LpfM);
class3LpfBlank = new PCClass();
class3LpfBlank.setName("3LpfBlank");
BuildUtilities.setFact(class3LpfBlank, "ClassType", "Foo");
class3LpfBlank.put(IntegerKey.LEVELS_PER_FEAT, 3);
context.getReferenceContext().importObject(class3LpfBlank);
toughness = new Ability();
toughness.setName("Toughness");
toughness.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
toughness.put(ObjectKey.STACKS, Boolean.TRUE);
context.unconditionallyProcess(toughness, "CHOOSE", "NOCHOICE");
toughness.setCDOMCategory(AbilityCategory.FEAT);
final BonusObj aBonus = Bonus.newBonus(context, "HP|CURRENTMAX|3");
if (aBonus != null) {
toughness.addToListFor(ListKey.BONUS, aBonus);
}
context.getReferenceContext().importObject(toughness);
Ability exoticWpnProf = TestHelper.makeAbility("Exotic Weapon Proficiency", AbilityCategory.FEAT, "General.Fighter");
exoticWpnProf.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
context.unconditionallyProcess(exoticWpnProf, "CHOOSE", "WEAPONPROFICIENCY|!PC[TYPE.Exotic]");
context.unconditionallyProcess(exoticWpnProf, "AUTO", "WEAPONPROF|%LIST");
WeaponProf wpnProfTestA = new WeaponProf();
wpnProfTestA.setName("Weapon A");
wpnProfTestA.put(StringKey.KEY_NAME, "Weapon A");
wpnProfTestA.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
context.getReferenceContext().importObject(wpnProfTestA);
WeaponProf wpnProfTestB = new WeaponProf();
wpnProfTestB.setName("Weapon B");
wpnProfTestB.put(StringKey.KEY_NAME, "Weapon B");
wpnProfTestB.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
context.getReferenceContext().importObject(wpnProfTestB);
WeaponProf wpnProfTestC = new WeaponProf();
wpnProfTestC.setName("Weapon C");
wpnProfTestC.put(StringKey.KEY_NAME, "Weapon C");
wpnProfTestC.addToListFor(ListKey.TYPE, Type.getConstant("Exotic"));
context.getReferenceContext().importObject(wpnProfTestC);
UIPropertyContext.setSingleChoiceAction(Constants.CHOOSER_SINGLE_CHOICE_METHOD_SELECT_EXIT);
ChooserFactory.pushChooserClassname(RandomChooser.class.getName());
context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon B)");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(2), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon A)");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(3), "ADD", "FEAT|KEY_Exotic Weapon Proficiency (Weapon C)");
specialFeatCat = Globals.getContext().getReferenceContext().constructNowIfNecessary(AbilityCategory.class, "Special Feat");
specialFeatCat.setAbilityCategory(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT));
specialAbilityCat = Globals.getContext().getReferenceContext().constructNowIfNecessary(AbilityCategory.class, "Special Ability");
luckDomain = TestHelper.makeDomain("Luck");
context.getReferenceContext().buildDerivedObjects();
luckDomainLvl1Spell = TestHelper.makeSpell("true strike");
luckDomainLvl2Spell = TestHelper.makeSpell("aid");
TestHelper.makeSpell("protection from energy");
context.unconditionallyProcess(luckDomain, "SPELLLEVEL", "DOMAIN|Luck=1|KEY_True Strike|Luck=2|KEY_Aid|Luck=3|KEY_Protection from Energy");
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCTemplateTest method testAddLevelAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddLevelAbility() throws PersistenceLayerException, MalformedURLException {
LoadContext context = Globals.getContext();
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
// Create some abilities to be added
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab2);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
loader.parseLine(context, null, "Template1 LEVEL:2:ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
assertEquals(1, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
assertEquals(1, contained1.size());
assertTrue(contained1.contains(ab2));
List<PCTemplate> lvlTemplates = template.getSafeListFor(ListKey.LEVEL_TEMPLATES);
assertEquals(1, lvlTemplates.size());
PCTemplate lvl2 = lvlTemplates.get(0);
assertEquals(2, lvl2.get(IntegerKey.LEVEL).intValue());
listMods = lvl2.getListMods(autoList);
assertEquals(1, listMods.size());
iterator = listMods.iterator();
ref1 = iterator.next();
contained1 = ref1.getContainedObjects();
assertEquals(1, contained1.size());
assertTrue(contained1.contains(ab1));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.addTemplate(template);
assertFalse("Character should not have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
// Level the character up, testing for when the level tag kicks in
pc.incrementClassLevel(1, testClass);
pc.calcActiveBonuses();
assertFalse("Character should not have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
pc.incrementClassLevel(1, testClass);
pc.calcActiveBonuses();
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCTemplateTest method testAddLevelFeatAbility.
/**
* Test the definition and application of abilities of category FEAT.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddLevelFeatAbility() throws PersistenceLayerException, MalformedURLException {
// Create some abilities to be added
LoadContext context = Globals.getContext();
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(AbilityCategory.FEAT);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(AbilityCategory.FEAT);
context.getReferenceContext().importObject(ab2);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
loader.parseLine(context, null, "Template1 LEVEL:2:ABILITY:Feat|AUTOMATIC|Ability1 ABILITY:Feat|AUTOMATIC|Ability2", source);
PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "Feat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
assertEquals(1, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
assertEquals(1, contained1.size());
assertTrue(contained1.contains(ab2));
List<PCTemplate> lvlTemplates = template.getSafeListFor(ListKey.LEVEL_TEMPLATES);
assertEquals(1, lvlTemplates.size());
PCTemplate lvl2 = lvlTemplates.get(0);
assertEquals(2, lvl2.get(IntegerKey.LEVEL).intValue());
listMods = lvl2.getListMods(autoList);
assertEquals(1, listMods.size());
iterator = listMods.iterator();
ref1 = iterator.next();
contained1 = ref1.getContainedObjects();
assertEquals(1, contained1.size());
assertTrue(contained1.contains(ab1));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.addTemplate(template);
assertFalse("Character should not have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab2));
// Level the character up, testing for when the level tag kicks in
pc.incrementClassLevel(1, testClass);
pc.calcActiveBonuses();
assertFalse("Character should not have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
pc.incrementClassLevel(1, testClass);
pc.calcActiveBonuses();
assertTrue("Character should have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCTemplateTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddAbility() throws PersistenceLayerException, MalformedURLException {
LoadContext context = Globals.getContext();
// Create some abilities to be added
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab2);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
loader.parseLine(context, null, "Template1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
assertEquals(2, listMods.size());
Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
CDOMReference<Ability> ref1 = iterator.next();
CDOMReference<Ability> ref2 = iterator.next();
Collection<Ability> contained1 = ref1.getContainedObjects();
Collection<Ability> contained2 = ref2.getContainedObjects();
assertEquals(1, contained1.size());
assertEquals(1, contained2.size());
assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
// Add the template to the character
PlayerCharacter pc = getCharacter();
pc.addTemplate(template);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
Aggregations