Search in sources :

Example 21 with UnreachableError

use of pcgen.base.lang.UnreachableError 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 22 with UnreachableError

use of pcgen.base.lang.UnreachableError 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 23 with UnreachableError

use of pcgen.base.lang.UnreachableError 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)

Example 24 with UnreachableError

use of pcgen.base.lang.UnreachableError 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());
}
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 25 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class PreWeaponProfTest method testWithFeatThatGrantsBonus.

/**
	 * Test Preweaponprof with a feat that has a bonus tag
	 * This test was written to help find the source of bug 1699779
	 * @throws Exception
	 */
public void testWithFeatThatGrantsBonus() throws Exception {
    final PlayerCharacter character = getCharacter();
    PCTemplate pctls = new PCTemplate();
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(pctls, "AUTO", "WEAPONPROF|Longsword");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    final FeatLoader featLoader = new FeatLoader();
    CampaignSourceEntry cse;
    try {
        cse = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    int baseHp = character.hitPoints();
    Ability bar = new Ability();
    final String barStr = "Bar	TYPE:General	DESC:See Text	BONUS:HP|CURRENTMAX|50";
    featLoader.parseLine(Globals.getContext(), bar, barStr, cse);
    addAbility(AbilityCategory.FEAT, bar);
    assertEquals("Character should have 50 bonus hp added.", baseHp + 50, character.hitPoints());
    character.addTemplate(pctls);
    Ability foo = new Ability();
    final String fooStr = "Foo	TYPE:General	DESC:See Text	BONUS:HP|CURRENTMAX|50|PREWEAPONPROF:1,Longsword";
    featLoader.parseLine(Globals.getContext(), foo, fooStr, cse);
    addAbility(AbilityCategory.FEAT, foo);
    assertEquals("Character has the longsword proficiency so the bonus should be added", baseHp + 50 + 50, character.hitPoints());
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) Campaign(pcgen.core.Campaign) FeatLoader(pcgen.persistence.lst.FeatLoader) LoadContext(pcgen.rules.context.LoadContext) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCTemplate(pcgen.core.PCTemplate) URI(java.net.URI)

Aggregations

UnreachableError (pcgen.base.lang.UnreachableError)39 URI (java.net.URI)23 URISyntaxException (java.net.URISyntaxException)23 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)19 LoadContext (pcgen.rules.context.LoadContext)14 Field (java.lang.reflect.Field)9 Ability (pcgen.core.Ability)9 Campaign (pcgen.core.Campaign)9 CDOMReference (pcgen.cdom.base.CDOMReference)7 AbilityList (pcgen.cdom.list.AbilityList)6 CNAbility (pcgen.cdom.content.CNAbility)5 PlayerCharacter (pcgen.core.PlayerCharacter)4 FeatLoader (pcgen.persistence.lst.FeatLoader)4 ArrayList (java.util.ArrayList)3 PCClass (pcgen.core.PCClass)3 PCTemplate (pcgen.core.PCTemplate)3 QualifiedObject (pcgen.core.QualifiedObject)3 AbilityLoader (pcgen.persistence.lst.AbilityLoader)3 GenericLoader (pcgen.persistence.lst.GenericLoader)3 PCClassLoader (pcgen.persistence.lst.PCClassLoader)3