Search in sources :

Example 1 with AbilityList

use of pcgen.cdom.list.AbilityList in project pcgen by PCGen.

the class PCTemplateTest method testAddLevelAbility.

/**
	 * Test the definition and application of abilities. 
	 * @throws PersistenceLayerException 
	 * @throws MalformedURLException 
	 */
public void testAddLevelAbility() throws PersistenceLayerException, MalformedURLException {
    LoadContext context = Globals.getContext();
    AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
    // Create some abilities to be added
    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	LEVEL:2: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(1, listMods.size());
    Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
    CDOMReference<Ability> ref1 = iterator.next();
    Collection<Ability> contained1 = ref1.getContainedObjects();
    assertEquals(1, contained1.size());
    assertTrue(contained1.contains(ab2));
    List<PCTemplate> lvlTemplates = template.getSafeListFor(ListKey.LEVEL_TEMPLATES);
    assertEquals(1, lvlTemplates.size());
    PCTemplate lvl2 = lvlTemplates.get(0);
    assertEquals(2, lvl2.get(IntegerKey.LEVEL).intValue());
    listMods = lvl2.getListMods(autoList);
    assertEquals(1, listMods.size());
    iterator = listMods.iterator();
    ref1 = iterator.next();
    contained1 = ref1.getContainedObjects();
    assertEquals(1, contained1.size());
    assertTrue(contained1.contains(ab1));
    // Add the template to the character
    PlayerCharacter pc = getCharacter();
    pc.addTemplate(template);
    assertFalse("Character should not have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
    // Level the character up, testing for when the level tag kicks in
    pc.incrementClassLevel(1, testClass);
    pc.calcActiveBonuses();
    assertFalse("Character should not have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    pc.incrementClassLevel(1, testClass);
    pc.calcActiveBonuses();
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 2 with AbilityList

use of pcgen.cdom.list.AbilityList in project pcgen by PCGen.

the class PCTemplateTest method testAddLevelFeatAbility.

/**
	 * Test the definition and application of abilities of category FEAT. 
	 * @throws PersistenceLayerException 
	 * @throws MalformedURLException 
	 */
public void testAddLevelFeatAbility() throws PersistenceLayerException, MalformedURLException {
    // Create some abilities to be added
    LoadContext context = Globals.getContext();
    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	LEVEL:2: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(1, listMods.size());
    Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
    CDOMReference<Ability> ref1 = iterator.next();
    Collection<Ability> contained1 = ref1.getContainedObjects();
    assertEquals(1, contained1.size());
    assertTrue(contained1.contains(ab2));
    List<PCTemplate> lvlTemplates = template.getSafeListFor(ListKey.LEVEL_TEMPLATES);
    assertEquals(1, lvlTemplates.size());
    PCTemplate lvl2 = lvlTemplates.get(0);
    assertEquals(2, lvl2.get(IntegerKey.LEVEL).intValue());
    listMods = lvl2.getListMods(autoList);
    assertEquals(1, listMods.size());
    iterator = listMods.iterator();
    ref1 = iterator.next();
    contained1 = ref1.getContainedObjects();
    assertEquals(1, contained1.size());
    assertTrue(contained1.contains(ab1));
    // Add the template to the character
    PlayerCharacter pc = getCharacter();
    pc.addTemplate(template);
    assertFalse("Character should not have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab2));
    // Level the character up, testing for when the level tag kicks in
    pc.incrementClassLevel(1, testClass);
    pc.calcActiveBonuses();
    assertFalse("Character should not have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
    pc.incrementClassLevel(1, testClass);
    pc.calcActiveBonuses();
    assertTrue("Character should have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 3 with AbilityList

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

Example 4 with AbilityList

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

Example 5 with AbilityList

use of pcgen.cdom.list.AbilityList 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

CDOMReference (pcgen.cdom.base.CDOMReference)9 AbilityList (pcgen.cdom.list.AbilityList)9 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 UnreachableError (pcgen.base.lang.UnreachableError)6 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)6 LoadContext (pcgen.rules.context.LoadContext)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 ArrayList (java.util.ArrayList)2 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)2 ListKey (pcgen.cdom.enumeration.ListKey)2 Nature (pcgen.cdom.enumeration.Nature)2 AbilitySelector (pcgen.cdom.helper.AbilitySelector)2 AbilityTargetSelector (pcgen.cdom.helper.AbilityTargetSelector)2 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)2 Ability (pcgen.core.Ability)2 AbilityCategory (pcgen.core.AbilityCategory)2 Prerequisite (pcgen.core.prereq.Prerequisite)2 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1