Search in sources :

Example 11 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.

the class KitSkill method updatePCSkills.

/**
	 * Needs documentation.
	 *
	 * @param pc update skills for this PC
	 * @param aSkill Skill to update
	 * @param aRank Number of ranks to add
	 * @param aCost Cost of added ranks
	 * @param langList Languages to be selected for a language skill
	 * @param pcClass skills apply to this class
	 *
	 * @return {@code true} for success
	 * TODO What about throwing on failure?
	 */
private boolean updatePCSkills(final PlayerCharacter pc, final Skill aSkill, final int aRank, final double aCost, List<Language> langList, final PCClass pcClass) {
    boolean oldImporting = pc.isImporting();
    pc.setImporting(true);
    final String aString = SkillRankControl.modRanks(aRank, pcClass, true, pc, aSkill);
    pc.setImporting(oldImporting);
    if (!aString.isEmpty()) {
        Logging.errorPrint("SKILL: " + aString);
        return false;
    }
    // Add any supplied languages
    ChoiceManagerList<Language> controller = ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<>());
    for (Language lang : langList) {
        if (!controller.conditionallyApply(pc, lang)) {
            Logging.errorPrint("Failed to apply Language into Skill: " + lang.getLSTformat());
        }
    }
    //
    // Fix up the skill pools to reflect what we just spent.
    //
    double ptsToSpend = aCost;
    if (ptsToSpend >= 0.0) {
        for (PCLevelInfo info : pc.getLevelInfo()) {
            if (info.getClassKeyName().equals(pcClass.getKeyName())) {
                // We are spending this class' points.
                int remaining = info.getSkillPointsRemaining();
                if (remaining == 0) {
                    continue;
                }
                int left = remaining - (int) Math.min(remaining, ptsToSpend);
                info.setSkillPointsRemaining(left);
                ptsToSpend -= (remaining - left);
                if (ptsToSpend <= 0) {
                    break;
                }
            }
        }
    }
    return true;
}
Also used : Language(pcgen.core.Language) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 12 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method refreshClassList.

/**
	 * Update the list of class levels from scratch to match the current
	 * state of the character. 
	 */
private void refreshClassList() {
    List<PCClass> newClasses = charDisplay.getClassList();
    Collection<PCLevelInfo> levelInfo = charDisplay.getLevelInfo();
    Map<String, Integer> levelCount = new HashMap<>();
    Map<String, PCClass> classMap = new HashMap<>();
    for (PCClass pcClass : newClasses) {
        levelCount.put(pcClass.getKeyName(), 1);
        classMap.put(pcClass.getKeyName(), pcClass);
    }
    classLevels.clear();
    clearContents();
    for (PCLevelInfo lvlInfo : levelInfo) {
        final String classKeyName = lvlInfo.getClassKeyName();
        PCClass currClass = classMap.get(classKeyName);
        if (currClass == null) {
            Logging.errorPrint("No PCClass found for '" + classKeyName + "' in character's class list: " + newClasses);
            return;
        }
        int clsLvlNum = levelCount.get(classKeyName);
        levelCount.put(classKeyName, clsLvlNum + 1);
        classLevels.add(currClass);
        CharacterLevelFacadeImpl levelFI = new CharacterLevelFacadeImpl(currClass, classLevels.size());
        addElement(levelFI);
    //PCClassLevel classLevel = currClass.getClassLevel(clsLvlNum);
    }
    updateSkillsTodo();
}
Also used : HashMap(java.util.HashMap) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass)

Example 13 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.

the class ClassSkillChoiceActor method applyChoice.

/**
	 * Applies the given Skill choice to the given PlayerCharacter. The given
	 * Skill is added as a class skill for the PCClass provided during
	 * construction of this ClassSkillChoiceActor. If the number of ranks
	 * provided during construction of this ClassSkillChoiceActor was not null
	 * or zero, then ranks are also applied to the given skill.
	 * 
	 * @param owner
	 *            The owning object for this choice.
	 * @param choice
	 *            The Skill which should be added as a Class Skill for the
	 *            PCClass provided during construction of this
	 *            ClassSkillChoiceActor
	 * @param pc
	 *            The PlayerCharacter to which the changes driven by this
	 *            ClassSkillChoiceActor should be applied.
	 */
@Override
public void applyChoice(CDOMObject owner, Skill choice, PlayerCharacter pc) {
    PCClass pcc = getSourceClass(pc);
    if (pcc == null) {
        Logging.errorPrint("Unable to find the pc's class " + source + " to apply skill choices to.");
        return;
    }
    pc.addLocalCost(pcc, choice, SkillCost.CLASS, owner);
    if (applyRank != null) {
        if (owner instanceof PCClassLevel) {
            // Ensure that the skill points for this level are already calculated.
            PCClassLevel classLevel = (PCClassLevel) owner;
            PCClass pcClass = (PCClass) classLevel.getSafe(ObjectKey.PARENT);
            int levelIndex = 1;
            for (PCLevelInfo lvlInfo : pc.getLevelInfo()) {
                if (lvlInfo.getClassKeyName() == pcClass.getKeyName() && lvlInfo.getClassLevel() == classLevel.getSafe(IntegerKey.LEVEL)) {
                    pc.checkSkillModChangeForLevel(pcClass, lvlInfo, classLevel, levelIndex++);
                    break;
                }
            }
        }
        String result = SkillRankControl.modRanks(applyRank, pcc, false, pc, choice);
        if (StringUtils.isNotEmpty(result)) {
            Logging.errorPrint("Unable to apply {0} ranks of {1}. Error: {2}", applyRank, choice, result);
        }
    }
}
Also used : PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 14 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.

the class SkillLevelToken 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) {
    CharacterDisplay display = pc.getDisplay();
    SkillDetails details = buildSkillDetails(tokenSource);
    if (details.getPropertyCount() > 0 && "TOTAL".equals(details.getProperty(0))) {
        final int aLevelOffset;
        try {
            aLevelOffset = Integer.parseInt(details.getSkillId()) - 1;
            if ((aLevelOffset >= display.getLevelInfoSize()) || (aLevelOffset < 0)) {
                return "0";
            }
            final PCLevelInfo wLevelInfo = display.getLevelInfo(aLevelOffset);
            final int wOutput = wLevelInfo.getSkillPointsGained(pc);
            return Integer.toString(wOutput);
        } catch (NumberFormatException nfe) {
            Logging.errorPrint("Error replacing SKILLLEVEL." + tokenSource, nfe);
            return "";
        }
    }
    return "";
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 15 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.

the class LevelToken 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) {
    String retString = "";
    StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    aTok.nextToken();
    int level = 1;
    if (aTok.hasMoreTokens()) {
        level = Integer.parseInt(aTok.nextToken());
    }
    if (level < 1 || level > pc.getDisplay().getLevelInfoSize()) {
        //TODO Error?
        return "";
    }
    PCLevelInfo pcl = pc.getDisplay().getLevelInfo(level - 1);
    if (aTok.hasMoreTokens()) {
        String tokName = aTok.nextToken();
        if (tokName.equals("CLASSNAME")) {
            retString = pcl.getClassKeyName();
        }
        if (tokName.equals("CLASSLEVEL")) {
            retString = Integer.toString(pcl.getClassLevel());
        }
        if (tokName.equals("FEATLIST")) {
            //TODO This is likely a bug...
            retString = "";
        }
        if (tokName.equals("HP")) {
            retString = getLevelHP(pc, pcl);
        }
        if (tokName.equals("SKILLPOINTS")) {
            retString = Integer.toString(pcl.getSkillPointsGained(pc));
        }
    }
    return retString;
}
Also used : StringTokenizer(java.util.StringTokenizer) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Aggregations

PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)33 PCClass (pcgen.core.PCClass)11 PCClassLevel (pcgen.cdom.inst.PCClassLevel)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 Skill (pcgen.core.Skill)3 StringTokenizer (java.util.StringTokenizer)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)2 ClassSource (pcgen.cdom.helper.ClassSource)2 Language (pcgen.core.Language)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 SpecialAbility (pcgen.core.SpecialAbility)2 SpellProhibitor (pcgen.core.SpellProhibitor)2 BonusObj (pcgen.core.bonus.BonusObj)2 PCLevelInfoStat (pcgen.core.pclevelinfo.PCLevelInfoStat)2 BigDecimal (java.math.BigDecimal)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 HitDie (pcgen.cdom.content.HitDie)1