Search in sources :

Example 1 with AbilityCategoryLoader

use of pcgen.persistence.lst.AbilityCategoryLoader 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));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) AbilityList(pcgen.cdom.list.AbilityList) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) AbilityCategoryLoader(pcgen.persistence.lst.AbilityCategoryLoader) CDOMReference(pcgen.cdom.base.CDOMReference)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnreachableError (pcgen.base.lang.UnreachableError)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 CNAbility (pcgen.cdom.content.CNAbility)1 AbilityList (pcgen.cdom.list.AbilityList)1 AbilityCategoryLoader (pcgen.persistence.lst.AbilityCategoryLoader)1 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)1 GenericLoader (pcgen.persistence.lst.GenericLoader)1 LoadContext (pcgen.rules.context.LoadContext)1