Search in sources :

Example 21 with AbilityCategory

use of pcgen.core.AbilityCategory in project pcgen by PCGen.

the class AbilityListTokenTest method testCount.

/**
	 * Test the JEP count function on abilities.  
	 */
public void testCount() {
    //		verbose = true;
    PlayerCharacter character = getCharacter();
    AbilityCategory featCategory = SettingsHandler.getGame().getAbilityCategory("Feat");
    Ability ab5 = TestHelper.makeAbility("Silent Step (Greater)", AbilityCategory.FEAT, "General");
    ab5.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
    ab5.put(ObjectKey.VISIBILITY, Visibility.OUTPUT_ONLY);
    addAbility(featCategory, ab5);
    Ability ab6 = TestHelper.makeAbility("Perform (Fiddle)", AbilityCategory.FEAT, "Bardic");
    ab6.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.FALSE);
    addAbility(featCategory, ab6);
    is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT\")", ""), eq(4.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")", ""), eq(5.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT[and]TYPE=Fighter\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")", ""), eq(2.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT[and]TYPE=Fighter\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=BARDIC[and]TYPE=Bardic.General\")", ""), eq(1.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=BARDIC[and]TYPE=Bardic.General\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"NATURE=AUTOMATIC\")", ""), eq(0.0, 0.1), "count(\"ABILITIES\",\"NATURE=AUTOMATIC\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"NATURE=VIRTUAL\")", ""), eq(0.0, 0.1), "count(\"ABILITIES\",\"NATURE=VIRTUAL\")");
    is(character.getVariableValue("count(\"ABILITIES\",\"NATURE=NORMAL\")", ""), eq(6.0, 0.1), "count(\"ABILITIES\",\"NATURE=NORMAL\")");
    is(character.getVariableValue("count(\"ABILITIES\")", ""), eq(6.0, 0.1), "count(\"ABILITIES\")");
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) AbilityCategory(pcgen.core.AbilityCategory)

Example 22 with AbilityCategory

use of pcgen.core.AbilityCategory in project pcgen by PCGen.

the class QualifyTokenTest method testRoundRobinAbilitySpell.

@Test
public void testRoundRobinAbilitySpell() throws PersistenceLayerException {
    AbilityCategory pac = primaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    AbilityCategory sac = secondaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    Ability ab = primaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    primaryContext.getReferenceContext().reassociateCategory(pac, ab);
    ab = secondaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    secondaryContext.getReferenceContext().reassociateCategory(sac, ab);
    primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    runRoundRobin("ABILITY=NEWCAT|Abil3", "SPELL|Lightning Bolt");
}
Also used : Ability(pcgen.core.Ability) AbilityCategory(pcgen.core.AbilityCategory) Test(org.junit.Test)

Example 23 with AbilityCategory

use of pcgen.core.AbilityCategory in project pcgen by PCGen.

the class AbilityToken method removeChoice.

@Override
public void removeChoice(PlayerCharacter pc, CDOMObject owner, CNAbilitySelection choice) {
    CNAbility cna = choice.getCNAbility();
    Ability ab = cna.getAbility();
    AbilityCategory cat = (AbilityCategory) cna.getAbilityCategory();
    if (cna.getNature().equals(Nature.NORMAL)) {
        pc.adjustAbilities(cat, ab.getSafe(ObjectKey.SELECTION_COST).negate());
        pc.removeAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
    } else {
        pc.removeSavedAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategory(pcgen.core.AbilityCategory)

Example 24 with AbilityCategory

use of pcgen.core.AbilityCategory in project pcgen by PCGen.

the class AbilityToken method applyChoice.

@Override
public void applyChoice(CDOMObject owner, CNAbilitySelection choice, PlayerCharacter pc) {
    CNAbility cna = choice.getCNAbility();
    Ability ab = cna.getAbility();
    AbilityCategory cat = (AbilityCategory) cna.getAbilityCategory();
    boolean isVirtual = Nature.VIRTUAL.equals(cna.getNature());
    if (isVirtual) {
        pc.addSavedAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
    } else {
        pc.addAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
        pc.adjustAbilities(cat, ab.getSafe(ObjectKey.SELECTION_COST));
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategory(pcgen.core.AbilityCategory)

Example 25 with AbilityCategory

use of pcgen.core.AbilityCategory in project pcgen by PCGen.

the class AbilityTokenTest method testWithChoose.

@Test
public void testWithChoose() {
    try {
        setUpPC();
        //Need to make sure we use the character related context
        context = Globals.getContext();
        context.getReferenceContext().importObject(AbilityCategory.FEAT);
        TokenRegistration.register(ADD_TOKEN);
        TokenRegistration.register(ADD_ABILITY_TOKEN);
    } catch (PersistenceLayerException e1) {
        fail("Cannot set up PC");
    }
    Ability item = construct("ChooseAbility");
    Ability parent = construct("Parent");
    context.getReferenceContext().constructCDOMObject(Language.class, "Foo");
    context.getReferenceContext().constructCDOMObject(Language.class, "Bar");
    context.getReferenceContext().constructCDOMObject(Language.class, "Goo");
    context.getReferenceContext().constructCDOMObject(Language.class, "Wow");
    context.getReferenceContext().constructCDOMObject(Language.class, "Rev");
    AbilityCategory ff = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "Fighter Feat");
    ff.setAbilityCategory(CDOMDirectSingleRef.getRef(AbilityCategory.FEAT));
    AbilityCategory oc = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "Some Other Category");
    Ability badCA = context.getReferenceContext().constructCDOMObject(Ability.class, "ChooseAbility");
    context.getReferenceContext().reassociateCategory(oc, badCA);
    try {
        assertTrue(context.processToken(item, "CHOOSE", "LANG|Foo|Bar|Goo|Wow|Rev"));
        assertTrue(context.processToken(item, "MULT", "Yes"));
        assertTrue(context.processToken(badCA, "CHOOSE", "LANG|Foo|Bar|Goo|Wow|Rev"));
        assertTrue(context.processToken(badCA, "MULT", "Yes"));
        assertTrue(context.processToken(parent, "ADD", "ABILITY|FEAT|NORMAL|ChooseAbility"));
    } catch (PersistenceLayerException e) {
        e.printStackTrace();
        fail();
    }
    finishLoad(context);
    PlayerCharacter pc = new PlayerCharacter();
    Object source = UserSelection.getInstance();
    CNAbilitySelection badCACAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(oc, Nature.AUTOMATIC, badCA), "Foo");
    CNAbilitySelection fooCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.AUTOMATIC, item), "Foo");
    CNAbilitySelection barCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.VIRTUAL, item), "Bar");
    CNAbilitySelection gooCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, item), "Goo");
    CNAbilitySelection wowCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, item), "Wow");
    CNAbilitySelection wowFFCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(ff, Nature.NORMAL, item), "Wow");
    CNAbilitySelection revCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, item), "Rev");
    CNAbilitySelection revFFCAS = new CNAbilitySelection(CNAbilityFactory.getCNAbility(ff, Nature.NORMAL, item), "Rev");
    assertTrue(pca.allow(fooCAS, pc, false));
    assertTrue(pca.allow(barCAS, pc, false));
    assertTrue(pca.allow(gooCAS, pc, false));
    assertTrue(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(badCACAS, source);
    //Should have had no effect
    assertTrue(pca.allow(fooCAS, pc, false));
    assertTrue(pca.allow(barCAS, pc, false));
    assertTrue(pca.allow(gooCAS, pc, false));
    assertTrue(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(fooCAS, source);
    assertFalse(pca.allow(fooCAS, pc, false));
    assertTrue(pca.allow(barCAS, pc, false));
    assertTrue(pca.allow(gooCAS, pc, false));
    assertTrue(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(barCAS, source);
    assertFalse(pca.allow(fooCAS, pc, false));
    assertFalse(pca.allow(barCAS, pc, false));
    assertTrue(pca.allow(gooCAS, pc, false));
    assertTrue(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(gooCAS, source);
    assertFalse(pca.allow(fooCAS, pc, false));
    assertFalse(pca.allow(barCAS, pc, false));
    assertFalse(pca.allow(gooCAS, pc, false));
    assertTrue(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(wowFFCAS, source);
    assertFalse(pca.allow(fooCAS, pc, false));
    assertFalse(pca.allow(barCAS, pc, false));
    assertFalse(pca.allow(gooCAS, pc, false));
    assertFalse(pca.allow(wowCAS, pc, false));
    assertTrue(pca.allow(revFFCAS, pc, false));
    pc.applyAbility(revCAS, source);
    assertFalse(pca.allow(fooCAS, pc, false));
    assertFalse(pca.allow(barCAS, pc, false));
    assertFalse(pca.allow(gooCAS, pc, false));
    assertFalse(pca.allow(wowCAS, pc, false));
    assertFalse(pca.allow(revFFCAS, pc, false));
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory) Test(org.junit.Test)

Aggregations

AbilityCategory (pcgen.core.AbilityCategory)72 Ability (pcgen.core.Ability)60 CNAbility (pcgen.cdom.content.CNAbility)34 HashMapToList (pcgen.base.util.HashMapToList)14 ArrayList (java.util.ArrayList)10 PlayerCharacter (pcgen.core.PlayerCharacter)10 StringTokenizer (java.util.StringTokenizer)9 Test (org.junit.Test)9 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)7 Nature (pcgen.cdom.enumeration.Nature)6 BigDecimal (java.math.BigDecimal)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)4 PCTemplate (pcgen.core.PCTemplate)3 SpecialAbility (pcgen.core.SpecialAbility)3 BonusObj (pcgen.core.bonus.BonusObj)3 ParseResult (pcgen.rules.persistence.token.ParseResult)3 HashSet (java.util.HashSet)2