use of pcgen.base.lang.UnreachableError 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));
}
use of pcgen.base.lang.UnreachableError 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.base.lang.UnreachableError 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.base.lang.UnreachableError in project pcgen by PCGen.
the class PObjectTest method testNoChoiceBonus.
/**
* Test the function of adding an ability multiple times which has
* no choices and adds a static bonus.
* @throws Exception
*/
public void testNoChoiceBonus() 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");
Globals.getContext().getReferenceContext().constructCDOMObject(Language.class, "Foo");
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 PreWeaponProfTest 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
*/
public void testWithFeatThatGrantsBonus() throws Exception {
final PlayerCharacter character = getCharacter();
PCTemplate pctls = new PCTemplate();
LoadContext context = Globals.getContext();
context.unconditionallyProcess(pctls, "AUTO", "WEAPONPROF|Longsword");
assertTrue(context.getReferenceContext().resolveReferences(null));
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());
character.addTemplate(pctls);
Ability foo = new Ability();
final String fooStr = "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PREWEAPONPROF:1,Longsword";
featLoader.parseLine(Globals.getContext(), foo, fooStr, cse);
addAbility(AbilityCategory.FEAT, foo);
assertEquals("Character has the longsword proficiency so the bonus should be added", baseHp + 50 + 50, character.hitPoints());
}
Aggregations