use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class SpellLevelTest method testGetPCBasedBonusKnownSpells.
/**
* Test method for {@link pcgen.core.analysis.SpellLevel#getPCBasedBonusKnownSpells(pcgen.core.PlayerCharacter, pcgen.core.PCClass)}.
* @throws Exception
*/
public void testGetPCBasedBonusKnownSpells() throws Exception {
LoadContext context = Globals.getContext();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
final String classLine = "CLASS:Sorcerer TYPE:Base.PC SPELLSTAT:CHA SPELLTYPE:Arcane MEMORIZE:NO BONUS:CASTERLEVEL|Sorcerer|CL";
PCClassLoader classLoader = new PCClassLoader();
PCClass pcc = classLoader.parseLine(context, null, classLine, source);
Spell spell = TestHelper.makeSpell("Bless");
String abilityLine = "Spell bonanza CATEGORY:FEAT SPELLKNOWN:CLASS|Sorcerer=3|KEY_Bless";
AbilityLoader abilityLoader = new AbilityLoader();
abilityLoader.parseLine(context, null, abilityLine, source);
Ability ab1 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Spell bonanza");
// Do the post parsing cleanup
context.resolveDeferredTokens();
context.getReferenceContext().buildDeferredObjects();
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().validate(null);
assertTrue(context.getReferenceContext().resolveReferences(null));
PlayerCharacter aPC = getCharacter();
Collection<Integer> levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
assertEquals("Initial number of spell levels incorrect", 0, levels.size());
addAbility(AbilityCategory.FEAT, ab1);
// Now for the tests
levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
assertEquals("Incorrect number of spell levels returned", 1, levels.size());
assertEquals("Incorrect spell level returned", Integer.valueOf(3), levels.iterator().next());
Collection<Spell> result = listManagerFacet.getSet(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST), 3);
assertEquals("Incorrect number of spells returned", 1, result.size());
assertEquals("Incorrect spell returned", spell, result.iterator().next());
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class PreArmorProfTest method testWithFeatThatGrantsBonus.
/**
* Test Preweaponprof with a feat that has a bonus tag
* This test was written to help find the source of bug 1699779.
*
* @throws Exception the exception
*/
public void testWithFeatThatGrantsBonus() throws Exception {
final PlayerCharacter character = getCharacter();
final FeatLoader featLoader = new FeatLoader();
CampaignSourceEntry cse;
try {
cse = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
int baseHp = character.hitPoints();
Ability bar = new Ability();
final String barStr = "Bar TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50";
featLoader.parseLine(Globals.getContext(), bar, barStr, cse);
addAbility(AbilityCategory.FEAT, bar);
assertEquals("Character should have 50 bonus hp added.", baseHp + 50, character.hitPoints());
final Ability martialProf = TestHelper.makeAbility("Shield Proficiency (Single)", "FEAT", "General");
Globals.getContext().unconditionallyProcess(martialProf, "AUTO", "ARMORPROF|Full Plate");
assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, martialProf, null);
Ability foo = new Ability();
final String fooStr = "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PREPROFWITHARMOR:1,Full Plate";
featLoader.parseLine(Globals.getContext(), foo, fooStr, cse);
addAbility(AbilityCategory.FEAT, foo);
assertEquals("Character has the Full Plate proficiency so the bonus should be added", baseHp + 50 + 50, character.hitPoints());
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class FeatTest method testAlertness.
/**
* Test Alertness Feat
* @throws Exception
*/
public void testAlertness() throws Exception {
Ability alertnessFeat;
FeatLoader featLoader = new FeatLoader();
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
alertnessFeat = new Ability();
featLoader.parseLine(Globals.getContext(), alertnessFeat, "Alertness TYPE:General DESC:+2 on Listen and Spot checks BONUS:SKILL|Listen,Spot|2", source);
assertEquals("Alertness", alertnessFeat.getKeyName());
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class AssociationListKey method buildMap.
private static void buildMap() {
map = new CaseInsensitiveMap<>();
Field[] fields = AssociationListKey.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 AssociationListKey) {
map.put(fields[i].getName(), (AssociationListKey<?>) obj);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new UnreachableError(e);
}
}
}
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class ListKey method buildMap.
private static void buildMap() {
map = new CaseInsensitiveMap<>();
Field[] fields = ListKey.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
int mod = fields[i].getModifiers();
if (java.lang.reflect.Modifier.isStatic(mod) && java.lang.reflect.Modifier.isFinal(mod) && java.lang.reflect.Modifier.isPublic(mod)) {
try {
Object obj = fields[i].get(null);
if (obj instanceof ListKey) {
map.put(fields[i].getName(), (ListKey<?>) obj);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new UnreachableError(e);
}
}
}
}
Aggregations