use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class JepCountType method buildMap.
private static void buildMap() {
typeMap = new CaseInsensitiveMap<>();
Field[] fields = JepCountType.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
int mod = fields[i].getModifiers();
if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) {
try {
Object obj = fields[i].get(null);
if (obj instanceof JepCountType) {
typeMap.put(fields[i].getName(), (JepCountType) obj);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new UnreachableError(e);
}
}
}
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class AddClassSkillsTest method testGetChoicesListWithClassSkill.
/**
* Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)'
*/
@Test
public void testGetChoicesListWithClassSkill() {
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
String classPCCText = "CLASS:Cleric HD:8 TYPE:Base.PC ABB:Clr\n" + "CLASS:Cleric STARTSKILLPTS:2 CSKILL:KEY_Knowledge (Dungeoneering)";
PCClass po;
try {
po = parsePCClassText(classPCCText, source);
} catch (PersistenceLayerException e) {
throw new UnreachableError(e);
}
getCharacter().incrementClassLevel(1, po, false);
PCTemplate pct = new PCTemplate();
Skill bluff = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, "KEY_Bluff");
pct.addToListFor(ListKey.CSKILL, CDOMDirectSingleRef.getRef(bluff));
getCharacter().addTemplate(pct);
Globals.getContext().unconditionallyProcess(po, "ADD", "CLASSSKILLS|2|KEY_Bluff,KEY_Listen,KEY_Knowledge (Arcana)");
assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
List<PersistentTransitionChoice<?>> choiceList = po.getListFor(ListKey.ADD);
assertEquals(1, choiceList.size());
TransitionChoice<?> choice = choiceList.get(0);
Collection<?> choiceSet = choice.getChoices().getSet(getCharacter());
assertEquals(3, choiceSet.size());
Set<Object> limitedSet = new HashSet<>();
ClassSkillChoiceActor csca = new ClassSkillChoiceActor(po, 0);
for (Object sc : choiceSet) {
if (csca.allow((Skill) sc, getCharacter(), true)) {
limitedSet.add(sc);
}
}
assertEquals(2, limitedSet.size());
assertEquals(2, choice.getCount().resolve(getCharacter(), ""));
List<String> choiceStrings = new ArrayList<>();
for (Object o : limitedSet) {
choiceStrings.add(o.toString());
}
assertTrue(choiceStrings.contains("Listen"));
assertTrue(choiceStrings.contains("Knowledge (Arcana)"));
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class PObjectTest method testNoSubsChoiceBonus.
/**
* Test the function of adding an ability multiple times which has
* a single choice and adds a static bonus.
* @throws Exception
*/
public void testNoSubsChoiceBonus() throws Exception {
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
AbilityLoader loader = new AbilityLoader();
loader.parseLine(Globals.getContext(), null, "Toughness CATEGORY:FEAT TYPE:General STACK:YES MULT:YES CHOOSE:NOCHOICE BONUS:HP|CURRENTMAX|3", source);
Ability pObj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Toughness");
PlayerCharacter aPC = getCharacter();
int baseHP = aPC.hitPoints();
AbstractCharacterTestCase.applyAbility(aPC, AbilityCategory.FEAT, pObj, "");
aPC.calcActiveBonuses();
assertEquals("Should have added 3 HPs", baseHP + 3, aPC.hitPoints());
AbstractCharacterTestCase.applyAbility(aPC, AbilityCategory.FEAT, pObj, "");
aPC.calcActiveBonuses();
assertEquals("2 instances should have added 6 HPs", baseHP + 6, aPC.hitPoints());
}
use of pcgen.base.lang.UnreachableError 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.base.lang.UnreachableError 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));
}
Aggregations