Search in sources :

Example 11 with SkillCost

use of pcgen.cdom.enumeration.SkillCost in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method findNextLevelForSkill.

@Override
public CharacterLevelFacade findNextLevelForSkill(SkillFacade skill, CharacterLevelFacade baseLevel, float newRank) {
    Skill aSkill = (Skill) skill;
    SkillCost skillCost = getSkillCost(baseLevel, aSkill);
    float maxRanks = getMaxRanks(baseLevel, skillCost, isClassSkillForMaxRanks(baseLevel, aSkill));
    float currRank = SkillRankControl.getTotalRank(theCharacter, aSkill);
    if (newRank < currRank) {
        // 1. Selected level (if class had purchased a rank and is not above max ranks)
        if (classHasRanksIn(skill, ((CharacterLevelFacadeImpl) baseLevel).getSelectedClass()) && !Float.isNaN(maxRanks) && maxRanks >= currRank && getSpentSkillPoints(baseLevel) > 0) {
            return baseLevel;
        }
        // 2. Scan from level 1 for first level of the same class as currently 
        // selected level in which the rank to be removed is below max ranks and 
        // is a class that has bought ranks in the class
        CharacterLevelFacade levelToRefundSkill = scanForLevelToRefundSkill(aSkill, currRank, (PCClass) getClassTaken(baseLevel));
        if (levelToRefundSkill != null) {
            return levelToRefundSkill;
        }
        // 3. Scan from level 1 for first level of any class in which the rank 
        // to be removed is below max ranks and is a class that has bought 
        // ranks in the class
        levelToRefundSkill = scanForLevelToRefundSkill(aSkill, currRank, null);
        return levelToRefundSkill;
    }
    // Check if current level ok
    if (!Float.isNaN(maxRanks) && maxRanks >= newRank && getRemainingSkillPoints(baseLevel) > 0) {
        return baseLevel;
    }
    // Check for class cost on this level or higher
    int baseLevelIndex = getLevelIndex(baseLevel);
    CharacterLevelFacade levelToBuySkill = scanForwardforLevelToBuySkill(aSkill, newRank, baseLevelIndex, SkillCost.CLASS);
    if (levelToBuySkill != null) {
        return levelToBuySkill;
    }
    // Check for class cost on any level
    levelToBuySkill = scanForwardforLevelToBuySkill(aSkill, newRank, 0, SkillCost.CLASS);
    if (levelToBuySkill != null) {
        return levelToBuySkill;
    }
    // Check for any cost on this level or higher
    levelToBuySkill = scanForwardforLevelToBuySkill(aSkill, newRank, baseLevelIndex, null);
    if (levelToBuySkill != null) {
        return levelToBuySkill;
    }
    // Check for any cost on any level
    levelToBuySkill = scanForwardforLevelToBuySkill(aSkill, newRank, 0, null);
    return levelToBuySkill;
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) Skill(pcgen.core.Skill) SkillCost(pcgen.cdom.enumeration.SkillCost)

Example 12 with SkillCost

use of pcgen.cdom.enumeration.SkillCost in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method getMaxRanks.

@Override
public float getMaxRanks(CharacterLevelFacade level, SkillCost cost, boolean isClassForMaxRanks) {
    if (cost == null || level == null || !(level instanceof CharacterLevelFacadeImpl)) {
        return 0.0f;
    }
    if (cost.getCost() == 0) {
        return Float.NaN;
    }
    SkillCost costForMaxRanks = isClassForMaxRanks ? SkillCost.CLASS : cost;
    CharacterLevelFacadeImpl levelImpl = (CharacterLevelFacadeImpl) level;
    if (costForMaxRanks == SkillCost.CLASS) {
        return SkillUtilities.maxClassSkillForLevel(levelImpl.getCharacterLevel(), theCharacter).floatValue();
    } else if (costForMaxRanks == SkillCost.CROSS_CLASS) {
        return SkillUtilities.maxCrossClassSkillForLevel(levelImpl.getCharacterLevel(), theCharacter).floatValue();
    } else if (costForMaxRanks == SkillCost.EXCLUSIVE) {
        // levels for the skill itself will need to be made elsewhere 
        return SkillUtilities.maxClassSkillForLevel(levelImpl.getCharacterLevel(), theCharacter).floatValue();
    }
    return Float.NaN;
}
Also used : SkillCost(pcgen.cdom.enumeration.SkillCost)

Example 13 with SkillCost

use of pcgen.cdom.enumeration.SkillCost 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 14 with SkillCost

use of pcgen.cdom.enumeration.SkillCost in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method investSkillPoints.

/**
	 * @see pcgen.core.facade.CharacterLevelsFacade#investSkillPoints(int, pcgen.core.facade.SkillFacade, int)
	 */
@Override
public boolean investSkillPoints(CharacterLevelFacade level, SkillFacade skill, int points) {
    if (points == 0 || level == null || !(level instanceof CharacterLevelFacadeImpl)) {
        Logging.errorPrint("Invalid request to investSkillPoints in " + skill + ". Points: " + points + " level: " + level);
        return false;
    }
    PCLevelInfo classLevel = getLevelInfo(level);
    int skillPool;
    if (Globals.getGameModeHasPointPool()) {
        skillPool = theCharacter.getSkillPoints();
    } else {
        skillPool = classLevel.getSkillPointsRemaining();
        if ((points < 0) && (((skillPool - points) > classLevel.getSkillPointsGained(theCharacter)) || !classHasRanksIn(skill, ((CharacterLevelFacadeImpl) level).getSelectedClass()))) {
            level = findLevelWithSpentSkillPoints(points, skill);
            if (level == null) {
                delegate.showInfoMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_iskErr_message_05", skill));
                return false;
            }
            classLevel = getLevelInfo(level);
            skillPool = classLevel.getSkillPointsRemaining();
        }
    }
    if ((points > 0) && (points > skillPool)) {
        delegate.showInfoMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_iskErr_message_04a", String.valueOf(skillPool)));
        return false;
    }
    SkillCost sc = getSkillCost(level, skill);
    if (sc == null) {
        Logging.errorPrint("Failed to get skillcost for skill " + skill + ". Could not process request to invest " + points + " in the skill");
        return false;
    }
    if (sc.equals(SkillCost.EXCLUSIVE)) {
        delegate.showInfoMessage(Constants.APPLICATION_NAME, LanguageBundle.getString("in_iskErr_message_06"));
        return false;
    }
    final double cost = sc.getCost();
    double rank = points / cost;
    Skill aSkill = (Skill) skill;
    boolean hasSkill = charDisplay.hasSkill(aSkill);
    if (!hasSkill) {
        SkillDisplay.updateSkillsOutputOrder(theCharacter, aSkill);
    }
    final String classKeyName = charDisplay.getLevelInfoClassKeyName(getLevelIndex(level));
    PCClass aClass = theCharacter.getClassKeyed(classKeyName);
    String errMessage = SkillRankControl.modRanks(rank, aClass, false, theCharacter, aSkill);
    if (//$NON-NLS-1$
    "".equals(errMessage)) {
        classLevel.setSkillPointsRemaining(skillPool - points);
    }
    if (ChooseActivation.hasNewChooseToken(aSkill) && characterFacadeImpl != null) {
        characterFacadeImpl.postLevellingUpdates();
    }
    if (!errMessage.isEmpty()) {
        delegate.showInfoMessage(Constants.APPLICATION_NAME, errMessage);
        return false;
    }
    updateSkillsTodo();
    fireSkillPointEvent(this, getLevelIndex(level), false);
    fireSkillBonusEvent(this, getLevelIndex(level), false);
    return true;
}
Also used : Skill(pcgen.core.Skill) SkillCost(pcgen.cdom.enumeration.SkillCost) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass)

Example 15 with SkillCost

use of pcgen.cdom.enumeration.SkillCost in project pcgen by PCGen.

the class ListToSkillCostFacet method dataAdded.

@Override
public void dataAdded(SubScopeFacetChangeEvent<ClassSkillList, SkillCost, Skill> dfce) {
    CharID id = dfce.getCharID();
    ClassSkillList skilllist = dfce.getScope1();
    SkillCost cost = dfce.getScope2();
    Skill sk = dfce.getCDOMObject();
    for (PCClass cl : skillListFacet.getScopes(id)) {
        if (skillListFacet.contains(id, cl, skilllist)) {
            add(id, cl, cost, sk, cl);
        }
    }
}
Also used : Skill(pcgen.core.Skill) SkillCost(pcgen.cdom.enumeration.SkillCost) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Aggregations

SkillCost (pcgen.cdom.enumeration.SkillCost)22 Skill (pcgen.core.Skill)16 PCClass (pcgen.core.PCClass)15 CharID (pcgen.cdom.enumeration.CharID)11 CharacterLevelFacade (pcgen.facade.core.CharacterLevelFacade)4 ArrayList (java.util.ArrayList)3 ClassSkillList (pcgen.cdom.list.ClassSkillList)3 DataSetID (pcgen.cdom.enumeration.DataSetID)2 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 SkillSituation (pcgen.cdom.helper.SkillSituation)1 CharacterDisplay (pcgen.core.display.CharacterDisplay)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1