Search in sources :

Example 1 with AbilityLoader

use of pcgen.persistence.lst.AbilityLoader 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 2 with AbilityLoader

use of pcgen.persistence.lst.AbilityLoader 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 3 with AbilityLoader

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

Aggregations

URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 UnreachableError (pcgen.base.lang.UnreachableError)3 AbilityLoader (pcgen.persistence.lst.AbilityLoader)3 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)3 CNAbility (pcgen.cdom.content.CNAbility)2 Ability (pcgen.core.Ability)1 Campaign (pcgen.core.Campaign)1 PCClass (pcgen.core.PCClass)1 PlayerCharacter (pcgen.core.PlayerCharacter)1 Spell (pcgen.core.spell.Spell)1 PCClassLoader (pcgen.persistence.lst.PCClassLoader)1 LoadContext (pcgen.rules.context.LoadContext)1