use of pcgen.persistence.lst.AbilityLoader 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.persistence.lst.AbilityLoader 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.persistence.lst.AbilityLoader 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());
}
Aggregations