Search in sources :

Example 1 with SkillSituation

use of pcgen.cdom.helper.SkillSituation in project pcgen by PCGen.

the class SkillSitToken method getSkillPropValue.

/**
	 * Evaluate the property for the supplied skill and character. For
	 * properties such as ACP and the extended UNTRAINED property, the
	 * property text is required to be further parsed to pull out user
	 * defined text to be output in each case.
	 *
	 * @param skillSit The skill to be reported upon.
	 * @param property The property to be reported.
	 * @param propertyText The original text of the property.
	 * @param pc The character to be reported upon.
	 * @return The value of the property.
	 */
private String getSkillPropValue(Object skillSit, int property, String propertyText, PlayerCharacter pc) {
    StringBuilder retValue = new StringBuilder();
    if (((property == SkillToken.SKILL_ABMOD) || (property == SkillToken.SKILL_MISC)) && //&& aSkill.get(ObjectKey.KEY_STAT) == null)
    false) {
        retValue.append("n/a");
    } else {
        Skill skill;
        boolean isSituation;
        String situation;
        SkillSituation sit;
        if (skillSit instanceof Skill) {
            sit = null;
            skill = (Skill) skillSit;
            isSituation = false;
            situation = "";
        } else if (skillSit instanceof SkillSituation) {
            sit = (SkillSituation) skillSit;
            skill = sit.getSkill();
            isSituation = true;
            situation = sit.getSituation();
        } else {
            Logging.errorPrint("Internal Error: unexpected type: " + skillSit.getClass());
            return "";
        }
        switch(property) {
            case SkillToken.SKILL_NAME:
                String name = QualifiedName.qualifiedName(pc, skill);
                if (isSituation) {
                    name += " (" + situation + ')';
                }
                retValue.append(name);
                break;
            case SkillToken.SKILL_TOTAL:
                int rank = SkillRankControl.getTotalRank(pc, skill).intValue() + SkillModifier.modifier(skill, pc).intValue();
                if (isSituation) {
                    rank += sit.getSituationBonus();
                }
                if (SettingsHandler.getGame().hasSkillRankDisplayText()) {
                    retValue.append(SettingsHandler.getGame().getSkillRankDisplayText(rank));
                } else {
                    retValue.append(Integer.toString(rank));
                }
                break;
            case SkillToken.SKILL_RANK:
                Float sRank = SkillRankControl.getTotalRank(pc, skill);
                if (SettingsHandler.getGame().hasSkillRankDisplayText()) {
                    retValue.append(SettingsHandler.getGame().getSkillRankDisplayText(sRank.intValue()));
                } else {
                    retValue.append(SkillRankControl.getTotalRank(pc, skill).toString());
                }
                break;
            case SkillToken.SKILL_MOD:
                int mod = SkillModifier.modifier(skill, pc).intValue();
                if (isSituation) {
                    mod += sit.getSituationBonus();
                }
                retValue.append(Integer.toString(mod));
                break;
            case SkillToken.SKILL_ABILITY:
                retValue.append(SkillInfoUtilities.getKeyStatFromStats(pc, skill));
                break;
            case SkillToken.SKILL_ABMOD:
                retValue.append(Integer.toString(SkillModifier.getStatMod(skill, pc)));
                break;
            case SkillToken.SKILL_MISC:
                int misc = SkillModifier.modifier(skill, pc).intValue();
                if (isSituation) {
                    misc += sit.getSituationBonus();
                }
                misc -= SkillModifier.getStatMod(skill, pc);
                retValue.append(Integer.toString(misc));
                break;
            case SkillToken.SKILL_UNTRAINED:
                retValue.append(skill.getSafe(ObjectKey.USE_UNTRAINED) ? "Y" : "NO");
                break;
            case SkillToken.SKILL_EXCLUSIVE:
                retValue.append(skill.getSafe(ObjectKey.EXCLUSIVE) ? "Y" : "N");
                break;
            case SkillToken.SKILL_UNTRAINED_EXTENDED:
                retValue.append(SkillToken.getUntrainedOutput(skill, propertyText));
                break;
            case SkillToken.SKILL_ACP:
                retValue.append(SkillToken.getAcpOutput(skill, propertyText));
                break;
            case SkillToken.SKILL_COST:
                SkillCost cost = null;
                for (PCClass pcc : pc.getDisplay().getClassSet()) {
                    if (cost == null) {
                        cost = pc.getSkillCostForClass(skill, pcc);
                    } else {
                        SkillCost newCost = pc.getSkillCostForClass(skill, pcc);
                        if (SkillCost.CLASS.equals(newCost) || SkillCost.EXCLUSIVE.equals(cost)) {
                            cost = newCost;
                        }
                    }
                    if (SkillCost.CLASS.equals(cost)) {
                        break;
                    }
                }
                retValue.append(cost.toString());
                break;
            case SkillToken.SKILL_EXCLUSIVE_TOTAL:
                int etRank = SkillRankControl.getTotalRank(pc, skill).intValue();
                boolean b = (skill.getSafe(ObjectKey.EXCLUSIVE) || !skill.getSafe(ObjectKey.USE_UNTRAINED)) && (etRank == 0);
                if (b) {
                    retValue.append('0');
                } else {
                    int mRank = etRank + SkillModifier.modifier(skill, pc).intValue();
                    if (isSituation) {
                        mRank += sit.getSituationBonus();
                    }
                    retValue.append(Integer.toString(mRank));
                }
                break;
            case SkillToken.SKILL_TRAINED_TOTAL:
                int tRank = SkillRankControl.getTotalRank(pc, skill).intValue();
                boolean isNotTrained = !skill.getSafe(ObjectKey.USE_UNTRAINED) && (tRank == 0);
                if (isNotTrained) {
                    retValue.append('0');
                } else {
                    int mRank = tRank + SkillModifier.modifier(skill, pc).intValue();
                    if (isSituation) {
                        mRank += sit.getSituationBonus();
                    }
                    retValue.append(Integer.toString(mRank));
                }
                break;
            case SkillToken.SKILL_EXPLANATION:
                boolean shortFrom = !("_LONG".equals(propertyText.substring(7)));
                String bonusDetails = SkillCostDisplay.getModifierExplanation(skill, pc, shortFrom);
                if (isSituation) {
                    String sitDetails = SkillCostDisplay.getSituationModifierExplanation(skill, situation, pc, shortFrom);
                    retValue.append(bonusDetails + " situational: " + sitDetails);
                } else {
                    retValue.append(bonusDetails);
                }
                break;
            case SkillToken.SKILL_TYPE:
                String type = skill.getType();
                retValue.append(type);
                break;
            case SkillToken.SKILL_SIZE:
                int i = (int) (pc.getSizeAdjustmentBonusTo("SKILL", skill.getKeyName()));
                if (isSituation) {
                    i += pc.getSizeAdjustmentBonusTo("SITUATION", skill.getKeyName() + '=' + situation);
                }
                retValue.append(Integer.toString(i));
                break;
            case SkillToken.SKILL_CLASSES:
                List<String> classes = new ArrayList<>();
                for (PCClass aClass : pc.getClassList()) {
                    if (pc.getSkillCostForClass(skill, aClass) == SkillCost.CLASS) {
                        classes.add(aClass.getDisplayName());
                    }
                }
                retValue.append(StringUtils.join(classes, "."));
                break;
            default:
                Logging.errorPrint("In ExportHandler._writeSkillProperty the propIdvalue " + property + " is not handled.");
                break;
        }
    }
    return retValue.toString();
}
Also used : Skill(pcgen.core.Skill) SkillCost(pcgen.cdom.enumeration.SkillCost) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SkillSituation(pcgen.cdom.helper.SkillSituation)

Example 2 with SkillSituation

use of pcgen.cdom.helper.SkillSituation in project pcgen by PCGen.

the class SkillSitToken method getSkill.

/**
	 * Select the target skill based on the supplied criteria. Uses the
	 * id in the details object to either retrieve a skill by name or by
	 * position in the skill list.
	 *
	 * @param pc The character being processed.
	 * @param details The parsed details of the token.
	 * @param eh The ExportHandler
	 * @return The matching skill, or null if none match.
	 */
private Object getSkill(PlayerCharacter pc, SkillDetails details, ExportHandler eh) {
    Object skill = null;
    try {
        int i = Integer.parseInt(details.getSkillId());
        final List<Skill> pcSkills = new ArrayList<>(getSkillList(pc));
        SkillFilter filter = details.getSkillFilter();
        if (filter == null || filter == SkillFilter.Selected) {
            filter = pc.getSkillFilter();
        }
        Iterator<Skill> iter = pcSkills.iterator();
        while (iter.hasNext()) {
            Skill sk = iter.next();
            if (!pc.includeSkill(sk, filter) || !sk.qualifies(pc, null)) {
                iter.remove();
            }
        }
        if ((i >= (pcSkills.size() - 1)) && eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
        for (iter = pcSkills.iterator(); i >= 0; ) {
            Skill sk = iter.next();
            if (i == 0) {
                return sk;
            }
            //wasn't the base skill
            i--;
            List<String> situations = new ArrayList<>(sk.getUniqueListFor(ListKey.SITUATION));
            if (situations != null) {
                int numSits = situations.size();
                if (i < numSits) {
                    Collections.sort(situations);
                }
                for (String situation : situations) {
                    double bonus = pc.getTotalBonusTo("SITUATION", sk.getKeyName() + '=' + situation);
                    if (bonus > 0.01 || bonus < -0.01) {
                        if (i == 0) {
                            return new SkillSituation(sk, situation, bonus);
                        }
                        //Wasn't this situation
                        i--;
                    }
                }
            }
        }
    } catch (NumberFormatException exc) {
        String skillName = details.getSkillId();
        int equalLoc = skillName.indexOf("=");
        if (equalLoc == -1) {
            //Allowing SKILL.Spot.<subtoken>
            skill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillName);
        } else {
            //Allowing SKILL.Spot=Situation.<subtoken>
            String situation = skillName.substring(equalLoc + 1);
            Skill sk = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillName.substring(0, equalLoc));
            double bonus = pc.getTotalBonusTo("SITUATION", sk.getKeyName() + '=' + situation);
            return new SkillSituation(sk, situation, bonus);
        }
    }
    return skill;
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) SkillFilter(pcgen.cdom.enumeration.SkillFilter) SkillSituation(pcgen.cdom.helper.SkillSituation)

Aggregations

ArrayList (java.util.ArrayList)2 SkillSituation (pcgen.cdom.helper.SkillSituation)2 Skill (pcgen.core.Skill)2 SkillCost (pcgen.cdom.enumeration.SkillCost)1 SkillFilter (pcgen.cdom.enumeration.SkillFilter)1 PCClass (pcgen.core.PCClass)1