use of pcgen.persistence.lst.CampaignSourceEntry 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.persistence.lst.CampaignSourceEntry 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.CampaignSourceEntry in project pcgen by PCGen.
the class AbstractKitTokenTestCase method classSetUp.
@BeforeClass
public static void classSetUp() throws URISyntaxException {
testCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case"));
classSetUpFired = true;
}
use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.
the class PreVarTest method test2857848c.
public void test2857848c() {
final PCClass warrior = new PCClass();
warrior.setName("Warrior");
LoadContext context = Globals.getContext();
context.unconditionallyProcess(warrior, "DEFINE", "MyVar|0");
context.unconditionallyProcess(warrior, "BONUS", "VAR|MyVar|2");
final PCClass notawarrior = new PCClass();
notawarrior.setName("NotAWarrior");
context.unconditionallyProcess(notawarrior, "PREVARGTEQ", "MyVar,1");
Skill concentration = context.getReferenceContext().constructCDOMObject(Skill.class, "Concentration");
context.unconditionallyProcess(notawarrior, "CSKILL", "Concentration");
context.unconditionallyProcess(notawarrior, "BONUS", "SKILL|Concentration|5");
assertTrue(context.getReferenceContext().resolveReferences(null));
PCClassLoader loader = new PCClassLoader();
try {
SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
loader.completeObject(context, se, warrior);
loader.completeObject(context, se, notawarrior);
PlayerCharacter character = this.getCharacter();
assertFalse(notawarrior.qualifies(character, notawarrior));
//Fails
character.incrementClassLevel(1, notawarrior);
assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
character.incrementClassLevel(1, warrior);
assertEquals(0, SkillModifier.modifier(concentration, character).intValue());
assertTrue(notawarrior.qualifies(character, notawarrior));
character.incrementClassLevel(1, notawarrior);
assertEquals(5, SkillModifier.modifier(concentration, character).intValue());
} catch (URISyntaxException | PersistenceLayerException e) {
fail(e.getMessage());
}
}
use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.
the class PreVarTest method test2857849and2862276.
public void test2857849and2862276() {
LoadContext context = Globals.getContext();
final PCClass spellcaster = new PCClass();
spellcaster.setName("Spellcaster");
context.getReferenceContext().importObject(spellcaster);
context.unconditionallyProcess(spellcaster, "SPELLTYPE", "Arcane");
context.unconditionallyProcess(spellcaster, "SPELLSTAT", "INT");
context.unconditionallyProcess(spellcaster, "PREVARGTEQ", "BASESPELLSTAT,2");
PCClassLoader loader = new PCClassLoader();
try {
SourceEntry se = new CampaignSourceEntry(new Campaign(), new URI("file://test"));
loader.completeObject(context, se, spellcaster);
context.getReferenceContext().resolveReferences(null);
PlayerCharacter character = this.getCharacter();
setPCStat(character, intel, 16);
assertTrue(spellcaster.qualifies(character, spellcaster));
} catch (URISyntaxException | PersistenceLayerException e) {
fail(e.getMessage());
}
}
Aggregations