Search in sources :

Example 71 with AbilityCategory

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

the class ExportHandlerTest method testExpressionOutput.

public void testExpressionOutput() throws IOException {
    LoadContext context = Globals.getContext();
    Ability dummyFeat = new Ability();
    dummyFeat.setName("DummyFeat");
    dummyFeat.setCDOMCategory(AbilityCategory.FEAT);
    final PlayerCharacter pc = getCharacter();
    // Create a variable
    dummyFeat.put(VariableKey.getConstant("NegLevels"), FormulaFactory.getFormulaFor(0));
    // Create a bonus to it
    Ability dummyFeat2 = new Ability();
    dummyFeat2.setName("DummyFeat2");
    dummyFeat2.setCDOMCategory(AbilityCategory.FEAT);
    final BonusObj aBonus = Bonus.newBonus(context, "VAR|NegLevels|7");
    if (aBonus != null) {
        dummyFeat2.addToListFor(ListKey.BONUS, aBonus);
    }
    AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "Maneuver");
    AbilityCategory cat2 = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "Maneuver(Special)");
    Ability dummyFeat3 = new Ability();
    dummyFeat3.setName("DummyFeat3");
    dummyFeat3.setCDOMCategory(cat);
    Ability dummyFeat4 = new Ability();
    dummyFeat4.setName("DummyFeat4");
    dummyFeat4.setCDOMCategory(cat2);
    addAbility(AbilityCategory.FEAT, dummyFeat);
    addAbility(AbilityCategory.FEAT, dummyFeat2);
    addAbility(cat, dummyFeat3);
    addAbility(cat2, dummyFeat4);
    assertEquals("Unsigned output", "7", evaluateToken("VAR.NegLevels.INTVAL", pc));
    assertEquals("Signed output", "+7", evaluateToken("VAR.NegLevels.INTVAL.SIGN", pc));
    String tok = "";
    tok = "count(\"ABILITIES\", \"CATEGORY=Maneuver\")";
    // if this evaluates math wise, the values should be string "1.0"
    assertFalse("Token: |" + tok + "| != 1.0: ", evaluateToken(tok, pc).equals("1.0"));
    tok = "VAR.count(\"ABILITIES\", \"CATEGORY=Maneuver\")";
    assertTrue("Token: |" + tok + "| == 1.0: ", evaluateToken(tok, pc).equals("1.0"));
    tok = "COUNT[\"ABILITIES\", \"CATEGORY=Maneuver\"]";
    assertFalse("Token: |" + tok + "| != 1.0: ", evaluateToken(tok, pc).equals("1.0"));
    tok = "count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")";
    assertFalse("Token: |" + tok + "| != 1.0 ", evaluateToken(tok, pc).equals("1.0"));
    tok = "${count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5}";
    assertFalse("Token: |" + tok + "| == 5.0 ", evaluateToken(tok, pc).equals("5.0"));
    tok = "${count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5}";
    assertTrue("Token: |" + tok + "| != 6.0 ", evaluateToken(tok, pc).equals("6.0"));
    tok = "${(count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5)/3}";
    assertFalse("Token: |" + tok + "| == 3.0 ", evaluateToken(tok, pc).equals("3.0"));
    tok = "${(count(\"ABILITIES\", \"CATEGORY=Maneuver(Special)\")+5)/3}";
    assertTrue("Token: |" + tok + "| != 2.0 ", evaluateToken(tok, pc).equals("2.0"));
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) AbilityCategory(pcgen.core.AbilityCategory)

Example 72 with AbilityCategory

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

the class ForwardrefTokenTest method testRoundRobinAbilitySpell.

@Test
public void testRoundRobinAbilitySpell() throws PersistenceLayerException {
    primaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    secondaryContext.getReferenceContext().constructCDOMObject(Spell.class, "Lightning Bolt");
    AbilityCategory newCatp = primaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    AbilityCategory newCats = secondaryContext.getReferenceContext().constructCDOMObject(AbilityCategory.class, "NEWCAT");
    Ability a = primaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    primaryContext.getReferenceContext().reassociateCategory(newCatp, a);
    Ability b = secondaryContext.getReferenceContext().constructCDOMObject(Ability.class, "Abil3");
    secondaryContext.getReferenceContext().reassociateCategory(newCats, b);
    runRoundRobin("ABILITY=NEWCAT|Abil3", "SPELL|Lightning Bolt");
}
Also used : Ability(pcgen.core.Ability) 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