Search in sources :

Example 31 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry 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());
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) CNAbility(pcgen.cdom.content.CNAbility) AbilityLoader(pcgen.persistence.lst.AbilityLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 32 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry 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 33 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry 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 34 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry 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 35 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry 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)

Aggregations

CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)95 URI (java.net.URI)54 Campaign (pcgen.core.Campaign)44 URISyntaxException (java.net.URISyntaxException)27 LoadContext (pcgen.rules.context.LoadContext)25 UnreachableError (pcgen.base.lang.UnreachableError)19 BeforeClass (org.junit.BeforeClass)16 PCClassLoader (pcgen.persistence.lst.PCClassLoader)15 TreeSet (java.util.TreeSet)12 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 ArrayList (java.util.ArrayList)9 PCClass (pcgen.core.PCClass)9 File (java.io.File)8 GenericLoader (pcgen.persistence.lst.GenericLoader)8 CDOMReference (pcgen.cdom.base.CDOMReference)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Ability (pcgen.core.Ability)6 FeatLoader (pcgen.persistence.lst.FeatLoader)6 AbilityList (pcgen.cdom.list.AbilityList)5