Search in sources :

Example 61 with AbilityCategory

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

the class AbilityListToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    // Skip the ABILITYLIST token itself
    final String tokenString = aTok.nextToken();
    final String catString = aTok.nextToken();
    final AbilityCategory aCategory = SettingsHandler.getGame().getAbilityCategory(catString);
    return getTokenForCategory(pc, aTok, tokenString, aCategory);
}
Also used : StringTokenizer(java.util.StringTokenizer) AbilityCategory(pcgen.core.AbilityCategory)

Example 62 with AbilityCategory

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

the class AbilityListToken method getAbilityList.

/**
	 * Returns the correct list of abilities of a particular category for the character.
	 * This method is overridden in subclasses if they need to change the list
	 * of abilities looked at.
	 *
	 * @param pc the character who's feats we are retrieving.
	 * @param aCategory The category of ability required.
	 * @return List of feats.
	 */
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 63 with AbilityCategory

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

the class AbilityToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    if (isEmpty(value)) {
        return new ParseResult.Fail("Value in " + getFullName() + " may not be empty", context);
    }
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    sep.addGroupingPair('[', ']');
    sep.addGroupingPair('(', ')');
    String first = sep.next();
    if (!sep.hasNext()) {
        return new ParseResult.Fail("Syntax of ADD:" + getTokenName() + " requires 3 to 4 |: " + value, context);
    }
    String second = sep.next();
    if (!sep.hasNext()) {
        return new ParseResult.Fail("Syntax of ADD:" + getTokenName() + " requires a minimum of three | : " + value, context);
    }
    String third = sep.next();
    Formula count;
    if (sep.hasNext()) {
        count = FormulaFactory.getFormulaFor(first);
        if (!count.isValid()) {
            return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
        }
        if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
            return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
        }
        first = second;
        second = third;
        third = sep.next();
    } else {
        count = FormulaFactory.ONE;
    }
    if (sep.hasNext()) {
        return new ParseResult.Fail("Syntax of ADD:" + getTokenName() + " has max of four | when a count is not present: " + value, context);
    }
    CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(ABILITY_CATEGORY_CLASS, first);
    Nature nature = Nature.valueOf(second);
    if (nature == null) {
        return new ParseResult.Fail(getFullName() + ": Invalid ability nature: " + second, context);
    }
    if (Nature.ANY.equals(nature)) {
        return new ParseResult.Fail(getTokenName() + " refers to ANY Ability Nature, cannot be used in " + getTokenName() + ": " + value);
    }
    if (Nature.AUTOMATIC.equals(nature)) {
        return new ParseResult.Fail(getTokenName() + " refers to AUTOMATIC Ability Nature, cannot be used in " + getTokenName() + ": " + value, context);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', third);
    if (!pr.passed()) {
        return pr;
    }
    List<CDOMReference<Ability>> refs = new ArrayList<>();
    ParsingSeparator tok = new ParsingSeparator(third, ',');
    tok.addGroupingPair('[', ']');
    tok.addGroupingPair('(', ')');
    boolean allowStack = false;
    int dupChoices = 0;
    ReferenceManufacturer<Ability> rm = context.getReferenceContext().getManufacturer(ABILITY_CLASS, ABILITY_CATEGORY_CLASS, first);
    if (rm == null) {
        return new ParseResult.Fail("Could not get Reference Manufacturer for Category: " + first, context);
    }
    while (tok.hasNext()) {
        CDOMReference<Ability> ab;
        String token = tok.next();
        if ("STACKS".equals(token)) {
            if (allowStack) {
                return new ParseResult.Fail(getFullName() + " found second stacking specification in value: " + value, context);
            }
            allowStack = true;
            continue;
        } else if (token.startsWith("STACKS=")) {
            if (allowStack) {
                return new ParseResult.Fail(getFullName() + " found second stacking specification in value: " + value, context);
            }
            allowStack = true;
            try {
                dupChoices = Integer.parseInt(token.substring(7));
            } catch (NumberFormatException nfe) {
                return new ParseResult.Fail("Invalid Stack number in " + getFullName() + ": " + value, context);
            }
            if (dupChoices <= 0) {
                return new ParseResult.Fail("Invalid (less than 1) Stack number in " + getFullName() + ": " + value, context);
            }
            continue;
        } else {
            if (Constants.LST_ALL.equals(token)) {
                ab = rm.getAllReference();
            } else {
                ab = TokenUtilities.getTypeOrPrimitive(rm, token);
            }
        }
        if (ab == null) {
            return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName() + ": " + value + " had an invalid reference: " + token, context);
        }
        refs.add(ab);
    }
    if (refs.isEmpty()) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains no ability reference: " + value, context);
    }
    AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(acRef, refs, nature);
    if (!rcs.getGroupingState().isValid()) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    AbilityChoiceSet cs = new AbilityChoiceSet(getTokenName(), rcs);
    StringBuilder title = new StringBuilder(50);
    if (!Nature.NORMAL.equals(nature)) {
        title.append(nature.toString());
        title.append(' ');
    }
    title.append(first);
    title.append(" Choice");
    cs.setTitle(title.toString());
    PersistentTransitionChoice<CNAbilitySelection> tc = new ConcretePersistentTransitionChoice<>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.allowStack(allowStack);
    if (dupChoices != 0) {
        tc.setStackLimit(dupChoices);
    }
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
}
Also used : Nature(pcgen.cdom.enumeration.Nature) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ParseResult(pcgen.rules.persistence.token.ParseResult) ArrayList(java.util.ArrayList) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) Formula(pcgen.base.formula.Formula) ParsingSeparator(pcgen.base.text.ParsingSeparator) AbilityChoiceSet(pcgen.cdom.base.ChoiceSet.AbilityChoiceSet) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory) CDOMReference(pcgen.cdom.base.CDOMReference) AbilityRefChoiceSet(pcgen.cdom.choiceset.AbilityRefChoiceSet)

Example 64 with AbilityCategory

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

the class TestHelper method makeAbility.

/**
	 * Set the important info about a Skill
	 * @param name The skill name
	 * @param cat the category of this Ability
	 * @param type The type info ("." separated)
	 * @return The ability (which has also been added to global storage
	 */
public static Ability makeAbility(final String name, final String cat, final String type) {
    AbilityCategory useCat = Globals.getContext().getReferenceContext().constructNowIfNecessary(AbilityCategory.class, cat);
    final Ability anAbility = new Ability();
    anAbility.setName(name);
    anAbility.put(StringKey.KEY_NAME, ("KEY_" + name));
    anAbility.setCDOMCategory(useCat);
    addType(anAbility, type);
    Globals.getContext().getReferenceContext().importObject(anAbility);
    return anAbility;
}
Also used : Ability(pcgen.core.Ability) AbilityCategory(pcgen.core.AbilityCategory)

Example 65 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)

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