use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCTemplateTest method testAddFeatAbility.
/**
* Test the definition and application of abilities of category FEAT.
* @throws PersistenceLayerException
* @throws MalformedURLException
*/
public void testAddFeatAbility() throws PersistenceLayerException, MalformedURLException {
LoadContext context = Globals.getContext();
// Create some abilities to be added
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 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(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);
// Need to do this to populate the ability list
//pc.getAutomaticAbilityList(AbilityCategory.FEAT);
assertTrue("Character should have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab2));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PObjectTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
*/
public void testAddAbility() throws PersistenceLayerException {
// Create some abilities to be added
LoadContext context = Globals.getContext();
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
new AbilityCategoryLoader().parseLine(context, "TestCat\tCATEGORY:TestCat", null);
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
// Link them to a template
Race race = new Race();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
GenericLoader<Race> loader = new GenericLoader<>(Race.class);
loader.parseLine(context, race, "Race1 ABILITY:TestCat|AUTOMATIC|Ability1 ABILITY:TestCat|AUTOMATIC|Ability2", source);
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 = race.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.setRace(race);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class StatListTest method setUp.
/**
* @see pcgen.AbstractCharacterTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
PlayerCharacter pc = getCharacter();
LoadContext context = Globals.getContext();
locker = new PCTemplate();
locker.setName("locker");
CDOMDirectSingleRef<PCStat> strRef = CDOMDirectSingleRef.getRef(str);
locker.addToListFor(ListKey.STAT_LOCKS, new StatLock(strRef, FormulaFactory.getFormulaFor(12)));
unlocker = new PCTemplate();
unlocker.setName("unlocker");
unlocker.addToListFor(ListKey.UNLOCKED_STATS, strRef);
bonus = TestHelper.makeAbility("Bonus", AbilityCategory.FEAT, "General.Fighter");
BonusObj aBonus = Bonus.newBonus(context, "STAT|STR|7|TYPE=Enhancement");
if (aBonus != null) {
bonus.addToListFor(ListKey.BONUS, aBonus);
}
lockedBonus = TestHelper.makeAbility("LockedBonus", AbilityCategory.FEAT, "General.Fighter");
aBonus = Bonus.newBonus(context, "LOCKEDSTAT|STR|3|TYPE=Morale");
if (aBonus != null) {
lockedBonus.addToListFor(ListKey.BONUS, aBonus);
}
setPCStat(pc, str, 6);
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testSkillPrereq.
/**
* Test the skill pre reqs
* @throws Exception
*/
public void testSkillPrereq() throws Exception {
LoadContext context = Globals.getContext();
final Skill rideSkill = new Skill();
rideSkill.setName("Ride");
rideSkill.put(StringKey.KEY_NAME, "Ride");
rideSkill.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
final Ability skillFocus = new Ability();
skillFocus.setName("Skill Focus");
skillFocus.put(StringKey.KEY_NAME, "Skill Focus");
final BonusObj saddleBonus = Bonus.newBonus(context, "SKILL|Ride|-5|!PREITEM:1,TYPE.Saddle");
rideSkill.addToListFor(ListKey.BONUS, saddleBonus);
final Equipment saddle = new Equipment();
saddle.setName("Saddle, Test");
saddle.addToListFor(ListKey.TYPE, Type.getConstant("SADDLE"));
final PlayerCharacter pc = getCharacter();
BonusActivation.activateBonuses(rideSkill, pc);
double iBonus = saddleBonus.resolve(pc, "").doubleValue();
assertEquals("Bonus value", -5.0, iBonus, 0.05);
assertTrue("No saddle, should have a penalty", pc.isApplied(saddleBonus));
pc.addEquipment(saddle);
final EquipSet eqSet = new EquipSet("Test", "Test", "", saddle);
pc.addEquipSet(eqSet);
pc.calcActiveBonuses();
BonusActivation.activateBonuses(rideSkill, pc);
assertFalse("Saddle, should not have a penalty", pc.isApplied(saddleBonus));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusTest method testBonuswithLISTValueTwoAssoc.
public void testBonuswithLISTValueTwoAssoc() {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
setPCStat(character, intel, 18);
setPCStat(character, str, 16);
BonusObj bonus = Bonus.newBonus(context, "VISION|Darkvision|%LIST+10|TYPE=Magical Boon");
List<BonusObj> bonusList = new ArrayList<>();
bonusList.add(bonus);
Ability testBonus = new Ability();
testBonus.setName("TB2Assoc");
testBonus.setCDOMCategory(AbilityCategory.FEAT);
testBonus.addToListFor(ListKey.BONUS, bonus);
Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
CNAbility cna = AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "INT");
testBonus = cna.getAbility();
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "STR");
character.calcActiveBonuses();
bonus = testBonus.getSafeListFor(ListKey.BONUS).get(0);
List<BonusPair> bonusPairs = character.getStringListFromBonus(bonus);
assertEquals(2, bonusPairs.size());
int totalBonus = 0;
BonusPair bp = bonusPairs.get(0);
assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
totalBonus += bp.resolve(character).intValue();
bp = bonusPairs.get(1);
assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
totalBonus += bp.resolve(character).intValue();
assertEquals(27, totalBonus);
}
Aggregations