use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class PreShieldProfTest method testWithFeatThatGrantsBonus.
/**
* Test PREPROFWITHSHIELD with a feat that has a bonus tag
*
* @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", "SHIELDPROF|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|PREPROFWITHSHIELD: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 PCClassTest method testGetPCCText.
/**
* Test the processing of getPCCText to ensure that it correctly produces
* an LST representation of an object and that the LST can then be reloaded
* to recrete the object.
*
* @throws PersistenceLayerException
*/
public void testGetPCCText() throws PersistenceLayerException {
FactKey.getConstant("Abb", new StringManager());
// Test a basic class
String classPCCText = humanoidClass.getPCCText();
assertNotNull("PCC Text for race should not be null", classPCCText);
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
PCClass reconstClass = null;
System.out.println("Got text:" + classPCCText);
reconstClass = parsePCClassText(classPCCText, source);
assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
assertEquals("Class abbrev was not restored after saving and reloading.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
// Test a class with some innate spells
String b = "1" + "\t" + "SPELLS:" + "Humanoid|TIMES=1|CASTERLEVEL=var(\"TCL\")|Create undead,11+WIS";
PCClassLoader classLoader = new PCClassLoader();
classLoader.parseLine(Globals.getContext(), humanoidClass, b, source);
classPCCText = humanoidClass.getPCCText();
assertNotNull("PCC Text for race should not be null", classPCCText);
reconstClass = null;
System.out.println("Got text:" + classPCCText);
reconstClass = parsePCClassText(classPCCText, source);
assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
assertEquals("Class abbrev was not restored after saving and reloading.", humanoidClass.getAbbrev(), reconstClass.getAbbrev());
Collection<CDOMReference<Spell>> startSpells = humanoidClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
Collection<CDOMReference<Spell>> reconstSpells = reconstClass.getOriginalClassLevel(1).getListMods(Spell.SPELLS);
assertEquals("All spell should have been reconstituted.", startSpells.size(), reconstSpells.size());
assertEquals("Spell names should been preserved.", startSpells, reconstSpells);
}
use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.
the class SpellListTokenTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
LoadContext context = Globals.getContext();
SettingsHandler.getGame().setSpellBaseDC("10+SPELLLEVEL+BASESPELLSTAT");
SimpleLoader<BonusSpellInfo> bonusSpellLoader = new SimpleLoader<>(BonusSpellInfo.class);
try {
URI testURI = new URI("file:/" + getClass().getName() + ".java");
bonusSpellLoader.parseLine(context, "1 BASESTATSCORE:12 STATRANGE:8", testURI);
bonusSpellLoader.parseLine(context, "2 BASESTATSCORE:14 STATRANGE:8", testURI);
bonusSpellLoader.parseLine(context, "3 BASESTATSCORE:16 STATRANGE:8", testURI);
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
// Human
human = new Race();
final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|2");
human.addToListFor(ListKey.BONUS, bon);
arcaneClass = new PCClass();
arcaneClass.setName("TestArcane");
BuildUtilities.setFact(arcaneClass, "SpellType", "Arcane");
context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
arcaneClass.put(ObjectKey.SPELLBOOK, false);
arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2,1");
context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1,0");
context.getReferenceContext().importObject(arcaneClass);
divineClass = new PCClass();
divineClass.setName("TestDivine");
BuildUtilities.setFact(divineClass, "SpellType", "Divine");
context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
divineClass.put(ObjectKey.SPELLBOOK, false);
divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
context.unconditionallyProcess(divineClass.getOriginalClassLevel(1), "CAST", "3,1,0");
context.unconditionallyProcess(divineClass, "SPELLLEVEL", "CLASS|SPELLCASTER.Divine=1|Cure Light Wounds");
context.getReferenceContext().importObject(divineClass);
context.resolveDeferredTokens();
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
}
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)"));
}
Aggregations