Search in sources :

Example 96 with Skill

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

the class CharacterFacadeImpl method getLanguageChoosers.

@Override
public ListFacade<LanguageChooserFacade> getLanguageChoosers() {
    CNAbility cna = theCharacter.getBonusLanguageAbility();
    DefaultListFacade<LanguageChooserFacade> chooserList = new DefaultListFacade<>();
    chooserList.addElement(new LanguageChooserFacadeImpl(this, LanguageBundle.getString("in_sumLangBonus"), //$NON-NLS-1$
    cna));
    SkillFacade speakLangSkill = dataSet.getSpeakLanguageSkill();
    if (speakLangSkill != null) {
        chooserList.addElement(new LanguageChooserFacadeImpl(this, //$NON-NLS-1$
        LanguageBundle.getString("in_sumLangSkill"), (Skill) speakLangSkill));
    }
    return chooserList;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) LanguageChooserFacade(pcgen.facade.core.LanguageChooserFacade) Skill(pcgen.core.Skill) SkillFacade(pcgen.facade.core.SkillFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 97 with Skill

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

the class CcskillLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    boolean first = true;
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokText)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
            }
            context.getObjectContext().removeList(obj, ListKey.CCSKILL);
        } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            String clearText = tokText.substring(7);
            if (Constants.LST_ALL.equals(clearText)) {
                context.getObjectContext().removeFromList(obj, ListKey.CCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } else if (Constants.LST_LIST.equals(clearText)) {
                context.getObjectContext().removeFromList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
            } else {
                CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText);
                if (ref == null) {
                    return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
                }
                context.getObjectContext().removeFromList(obj, ListKey.CCSKILL, ref);
            }
        } else {
            /*
				 * Note this HAS to be done one-by-one, because the
				 * .clearChildNodeOfClass method above does NOT recognize the
				 * C/CC Skill object and therefore doesn't know how to search
				 * the sublists
				 */
            if (Constants.LST_ALL.equals(tokText)) {
                foundAny = true;
                context.getObjectContext().addToList(obj, ListKey.CCSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } else {
                foundOther = true;
                if (Constants.LST_LIST.equals(tokText)) {
                    context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
                } else {
                    CDOMReference<Skill> ref = getSkillReference(context, tokText);
                    if (ref == null) {
                        return new ParseResult.Fail("  Error was encountered " + "while parsing " + getTokenName(), context);
                    }
                    context.getObjectContext().addToList(obj, ListKey.CCSKILL, ref);
                }
            }
        }
        first = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) ParseResult(pcgen.rules.persistence.token.ParseResult) Ungranted(pcgen.cdom.base.Ungranted) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 98 with Skill

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

the class ChooseLst method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (obj instanceof NonInteractive) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
    }
    String key;
    String val;
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (value.startsWith("FEAT=")) {
        key = "FEATEQ";
        val = value.substring(5);
    } else if (value.startsWith("LANGAUTO:")) {
        key = "LANGAUTO";
        val = value.substring(9);
    } else if (pipeLoc == -1) {
        key = value;
        val = null;
    } else {
        key = value.substring(0, pipeLoc);
        val = value.substring(pipeLoc + 1);
    }
    if (!((obj instanceof Ability) || (obj instanceof Domain) || (obj instanceof Race) || (obj instanceof PCTemplate) || (obj instanceof Skill) || (obj instanceof EquipmentModifier))) {
        //Allow TEMPBONUS related choose
        if (!"NUMBER".equals(key)) {
            return new ParseResult.Fail(getTokenName() + " is not supported for " + obj.getClass().getSimpleName(), context);
        }
    }
    if (key.startsWith("NUMCHOICES=")) {
        String maxCount = key.substring(11);
        if (maxCount == null || maxCount.isEmpty()) {
            return new ParseResult.Fail("NUMCHOICES in CHOOSE must be a formula: " + value, context);
        }
        Formula f = FormulaFactory.getFormulaFor(maxCount);
        if (!f.isValid()) {
            return new ParseResult.Fail("Number of Choices in " + getTokenName() + " was not valid: " + f.toString(), context);
        }
        context.getObjectContext().put(obj, FormulaKey.NUMCHOICES, f);
        pipeLoc = val.indexOf(Constants.PIPE);
        if (pipeLoc == -1) {
            key = val;
            val = null;
        } else {
            key = val.substring(0, pipeLoc);
            val = val.substring(pipeLoc + 1);
        }
    }
    return context.processSubToken(obj, getTokenName(), key, val);
}
Also used : Ability(pcgen.core.Ability) Formula(pcgen.base.formula.Formula) Skill(pcgen.core.Skill) EquipmentModifier(pcgen.core.EquipmentModifier) Race(pcgen.core.Race) NonInteractive(pcgen.cdom.base.NonInteractive) Domain(pcgen.core.Domain) PCTemplate(pcgen.core.PCTemplate) Ungranted(pcgen.cdom.base.Ungranted)

Example 99 with Skill

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

the class CskillLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    boolean first = true;
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
        String tokText = tok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokText)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
            }
            context.getObjectContext().removeList(obj, ListKey.CSKILL);
        } else if (tokText.startsWith(Constants.LST_DOT_CLEAR_DOT)) {
            String clearText = tokText.substring(7);
            if (Constants.LST_ALL.equals(clearText)) {
                context.getObjectContext().removeFromList(obj, ListKey.CSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } else if (Constants.LST_LIST.equals(clearText)) {
                context.getObjectContext().removeFromList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
            } else {
                CDOMReference<Skill> ref = TokenUtilities.getTypeOrPrimitive(context, SKILL_CLASS, clearText);
                if (ref == null) {
                    return new ParseResult.Fail("  Error was encountered while parsing " + getTokenName(), context);
                }
                context.getObjectContext().removeFromList(obj, ListKey.CSKILL, ref);
            }
        } else {
            /*
				 * Note this HAS to be done one-by-one, because the
				 * .clearChildNodeOfClass method above does NOT recognize the
				 * C/CC Skill object and therefore doesn't know how to search
				 * the sublists
				 */
            if (Constants.LST_ALL.equals(tokText)) {
                foundAny = true;
                context.getObjectContext().addToList(obj, ListKey.CSKILL, context.getReferenceContext().getCDOMAllReference(SKILL_CLASS));
            } else {
                foundOther = true;
                if (Constants.LST_LIST.equals(tokText)) {
                    context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, this);
                } else {
                    CDOMReference<Skill> ref = getSkillReference(context, tokText);
                    if (ref == null) {
                        return new ParseResult.Fail("  Error was encountered " + "while parsing " + getTokenName(), context);
                    }
                    context.getObjectContext().addToList(obj, ListKey.CSKILL, ref);
                }
            }
        }
        first = false;
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value, context);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) ParseResult(pcgen.rules.persistence.token.ParseResult) Ungranted(pcgen.cdom.base.Ungranted) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 100 with Skill

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

the class SkillInfoCommand method run.

/**
	 * Runs skill on the inStack. The parameter is popped
	 * off the {@code inStack}, and the variable's value is
	 * pushed back to the top of {@code inStack}.
	 * @param inStack the jep stack
	 * @throws ParseException
	 */
//Uses JEP, which doesn't use generics
@SuppressWarnings("unchecked")
@Override
public void run(final Stack inStack) throws ParseException {
    // check the stack
    checkStack(inStack);
    // get the parameters from the stack
    //
    // have to do this in reverse order...this is a stack afterall
    //
    final Object param2 = inStack.pop();
    final Object param1 = inStack.pop();
    if ((param1 instanceof String) && (param2 instanceof String)) {
        PlayerCharacter pc = null;
        if (parent instanceof VariableProcessor) {
            pc = ((VariableProcessor) parent).getPc();
        } else if (parent instanceof PlayerCharacter) {
            pc = (PlayerCharacter) parent;
        }
        if (pc == null) {
            throw new ParseException("Invalid parent (no PC): " + parent.getClass().getName());
        }
        Skill aSkill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, param2.toString());
        Object result = null;
        if (aSkill != null && pc.getDisplay().hasSkill(aSkill)) {
            if ("modifier".equalsIgnoreCase((String) param1)) {
                // aSkill.modifier() returns Integer
                result = (double) SkillModifier.modifier(aSkill, pc).intValue();
            } else if ("rank".equalsIgnoreCase((String) param1)) {
                // aSkill.getRank() returns Float
                result = pc.getDisplay().getRank(aSkill).doubleValue();
            } else if ("total".equalsIgnoreCase((String) param1)) {
                result = (double) SkillRankControl.getTotalRank(pc, aSkill).intValue() + SkillModifier.modifier(aSkill, pc);
            } else if ("totalrank".equalsIgnoreCase((String) param1)) {
                // aSkill.getTotalRank() returns Float
                result = SkillRankControl.getTotalRank(pc, aSkill).doubleValue();
            } else if ("stat".equalsIgnoreCase((String) param1)) {
                result = (double) SkillModifier.getStatMod(aSkill, pc);
            } else if ("misc".equalsIgnoreCase((String) param1)) {
                result = (double) (SkillModifier.modifier(aSkill, pc).intValue() - SkillModifier.getStatMod(aSkill, pc));
            } else {
                Logging.log(Logging.LST_ERROR, "Ignoring unknown parameter '" + param1 + "' in Skillinfo call: skillinfo(\"" + param1 + "\",\"" + param2 + "\")");
                result = (double) 0;
            }
        } else {
            result = (double) 0;
        }
        inStack.push(result);
    } else {
        throw new ParseException("Invalid parameter type");
    }
}
Also used : Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) VariableProcessor(pcgen.core.VariableProcessor) ParseException(org.nfunk.jep.ParseException)

Aggregations

Skill (pcgen.core.Skill)165 Test (org.junit.Test)60 PCClass (pcgen.core.PCClass)55 ArrayList (java.util.ArrayList)29 CDOMReference (pcgen.cdom.base.CDOMReference)24 CharID (pcgen.cdom.enumeration.CharID)23 SkillCost (pcgen.cdom.enumeration.SkillCost)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 PlayerCharacter (pcgen.core.PlayerCharacter)14 ChoiceSet (pcgen.cdom.base.ChoiceSet)13 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)13 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)13 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)13 StringTokenizer (java.util.StringTokenizer)10 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 Ability (pcgen.core.Ability)10 LoadContext (pcgen.rules.context.LoadContext)9 ClassSkillList (pcgen.cdom.list.ClassSkillList)8 HashSet (java.util.HashSet)7 CNAbility (pcgen.cdom.content.CNAbility)7