Search in sources :

Example 31 with UnreachableError

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

the class SpellLevelTest method testGetPCBasedBonusKnownSpells.

/**
	 * Test method for {@link pcgen.core.analysis.SpellLevel#getPCBasedBonusKnownSpells(pcgen.core.PlayerCharacter, pcgen.core.PCClass)}.
	 * @throws Exception 
	 */
public void testGetPCBasedBonusKnownSpells() throws Exception {
    LoadContext context = Globals.getContext();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    final String classLine = "CLASS:Sorcerer	TYPE:Base.PC	SPELLSTAT:CHA	SPELLTYPE:Arcane	MEMORIZE:NO	BONUS:CASTERLEVEL|Sorcerer|CL";
    PCClassLoader classLoader = new PCClassLoader();
    PCClass pcc = classLoader.parseLine(context, null, classLine, source);
    Spell spell = TestHelper.makeSpell("Bless");
    String abilityLine = "Spell bonanza	CATEGORY:FEAT	SPELLKNOWN:CLASS|Sorcerer=3|KEY_Bless";
    AbilityLoader abilityLoader = new AbilityLoader();
    abilityLoader.parseLine(context, null, abilityLine, source);
    Ability ab1 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Spell bonanza");
    // Do the post parsing cleanup
    context.resolveDeferredTokens();
    context.getReferenceContext().buildDeferredObjects();
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().validate(null);
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter aPC = getCharacter();
    Collection<Integer> levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Initial number of spell levels incorrect", 0, levels.size());
    addAbility(AbilityCategory.FEAT, ab1);
    // Now for the tests
    levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Incorrect number of spell levels returned", 1, levels.size());
    assertEquals("Incorrect spell level returned", Integer.valueOf(3), levels.iterator().next());
    Collection<Spell> result = listManagerFacet.getSet(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST), 3);
    assertEquals("Incorrect number of spells returned", 1, result.size());
    assertEquals("Incorrect spell returned", spell, result.iterator().next());
}
Also used : Ability(pcgen.core.Ability) AbilityLoader(pcgen.persistence.lst.AbilityLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) Spell(pcgen.core.spell.Spell) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 32 with UnreachableError

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

the class PreArmorProfTest 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 the exception
	 */
public void testWithFeatThatGrantsBonus() throws Exception {
    final PlayerCharacter character = getCharacter();
    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());
    final Ability martialProf = TestHelper.makeAbility("Shield Proficiency (Single)", "FEAT", "General");
    Globals.getContext().unconditionallyProcess(martialProf, "AUTO", "ARMORPROF|Full Plate");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, martialProf, null);
    Ability foo = new Ability();
    final String fooStr = "Foo	TYPE:General	DESC:See Text	BONUS:HP|CURRENTMAX|50|PREPROFWITHARMOR:1,Full Plate";
    featLoader.parseLine(Globals.getContext(), foo, fooStr, cse);
    addAbility(AbilityCategory.FEAT, foo);
    assertEquals("Character has the Full Plate 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) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 33 with UnreachableError

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

the class FeatTest method testAlertness.

/**
	 * Test Alertness Feat
	 * @throws Exception
	 */
public void testAlertness() throws Exception {
    Ability alertnessFeat;
    FeatLoader featLoader = new FeatLoader();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    alertnessFeat = new Ability();
    featLoader.parseLine(Globals.getContext(), alertnessFeat, "Alertness	TYPE:General	DESC:+2 on Listen and Spot checks	BONUS:SKILL|Listen,Spot|2", source);
    assertEquals("Alertness", alertnessFeat.getKeyName());
}
Also used : Ability(pcgen.core.Ability) Campaign(pcgen.core.Campaign) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 34 with UnreachableError

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

the class AssociationListKey method buildMap.

private static void buildMap() {
    map = new CaseInsensitiveMap<>();
    Field[] fields = AssociationListKey.class.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        int mod = fields[i].getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) {
            try {
                Object obj = fields[i].get(null);
                if (obj instanceof AssociationListKey) {
                    map.put(fields[i].getName(), (AssociationListKey<?>) obj);
                }
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new UnreachableError(e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) UnreachableError(pcgen.base.lang.UnreachableError)

Example 35 with UnreachableError

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

the class ListKey method buildMap.

private static void buildMap() {
    map = new CaseInsensitiveMap<>();
    Field[] fields = ListKey.class.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        int mod = fields[i].getModifiers();
        if (java.lang.reflect.Modifier.isStatic(mod) && java.lang.reflect.Modifier.isFinal(mod) && java.lang.reflect.Modifier.isPublic(mod)) {
            try {
                Object obj = fields[i].get(null);
                if (obj instanceof ListKey) {
                    map.put(fields[i].getName(), (ListKey<?>) obj);
                }
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new UnreachableError(e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) QualifiedObject(pcgen.core.QualifiedObject) UnreachableError(pcgen.base.lang.UnreachableError)

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