Search in sources :

Example 1 with CharacterLevelFacade

use of pcgen.facade.core.CharacterLevelFacade in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method scanForLevelToRefundSkill.

private CharacterLevelFacade scanForLevelToRefundSkill(Skill aSkill, float testRank, PCClass classToMatch) {
    for (int i = 0; i < charLevels.size(); i++) {
        CharacterLevelFacade testLevel = getElementAt(i);
        //Logging.errorPrint("Checking " + testLevel);
        String lvlClassName = getLevelInfo(testLevel).getClassKeyName();
        if (classToMatch != null && !classToMatch.getKeyName().equals(lvlClassName)) {
            //Logging.errorPrint("Skipping level " + testLevel + " as it is not the same class as " + classToMatch);
            continue;
        }
        if (!classHasRanksIn(aSkill, ((CharacterLevelFacadeImpl) testLevel).getSelectedClass())) {
            //Logging.errorPrint("Skipping level " + testLevel + " as it does not have ranks in " + aSkill);
            continue;
        }
        if (getSpentSkillPoints(testLevel) <= 0) {
            //Logging.errorPrint("Skipping level " + testLevel + " as it does not have spent points.");
            continue;
        }
        SkillCost skillCost = getSkillCost(testLevel, aSkill);
        float maxRanks = getMaxRanks(testLevel, skillCost, isClassSkillForMaxRanks(testLevel, aSkill));
        if (!Float.isNaN(maxRanks) && maxRanks >= testRank) {
            //Logging.errorPrint("Selected level " + testLevel);
            return testLevel;
        }
    //Logging.errorPrint("Skipping level " + testLevel + " as skill is above max ranks");
    }
    return null;
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) SkillCost(pcgen.cdom.enumeration.SkillCost)

Example 2 with CharacterLevelFacade

use of pcgen.facade.core.CharacterLevelFacade in project pcgen by PCGen.

the class CharacterLevelsFacadeImpl method scanForwardforLevelToBuySkill.

private CharacterLevelFacade scanForwardforLevelToBuySkill(Skill aSkill, float testRank, int baseLevelIndex, SkillCost costToMatch) {
    for (int i = baseLevelIndex; i < charLevels.size(); i++) {
        CharacterLevelFacade testLevel = getElementAt(i);
        //Logging.errorPrint("Checking " + testLevel);
        if (getRemainingSkillPoints(testLevel) <= 0) {
            //Logging.errorPrint("Skipping level " + testLevel + " as it does not have points left.");
            continue;
        }
        SkillCost skillCost = getSkillCost(testLevel, aSkill);
        if (costToMatch != null && skillCost.getCost() != costToMatch.getCost()) {
            //Logging.errorPrint("Skipping level " + testLevel + " as it is not the same cost as " + costToMatch);
            continue;
        }
        float maxRanks = getMaxRanks(testLevel, skillCost, isClassSkillForMaxRanks(testLevel, aSkill));
        if (!Float.isNaN(maxRanks) && maxRanks >= testRank) {
            //Logging.errorPrint("Selected level " + testLevel);
            return testLevel;
        }
    //Logging.errorPrint("Skipping level " + testLevel + " as skill is above max ranks");
    }
    return null;
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) SkillCost(pcgen.cdom.enumeration.SkillCost)

Example 3 with CharacterLevelFacade

use of pcgen.facade.core.CharacterLevelFacade 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 4 with CharacterLevelFacade

use of pcgen.facade.core.CharacterLevelFacade in project pcgen by PCGen.

the class CharacterFacadeImpl method refreshClassLevelModel.

void refreshClassLevelModel() {
    List<CharacterLevelFacade> newlevels = new ArrayList<>();
    List<PCClass> newClasses = charDisplay.getClassList();
    Collection<PCLevelInfo> levelInfo = charDisplay.getLevelInfo();
    Map<String, PCClass> classMap = new HashMap<>();
    for (PCClass pcClass : newClasses) {
        classMap.put(pcClass.getKeyName(), pcClass);
    }
    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;
        }
        CharacterLevelFacadeImpl cl = new CharacterLevelFacadeImpl(currClass, newlevels.size() + 1);
        newlevels.add(cl);
    }
    pcClasses.clear();
    pcClasses.addAll(newClasses);
    pcClassLevels.updateContents(newlevels);
    // Now get the CharacterLevelsFacadeImpl to do a refresh too.
    charLevelsFacade.classListRefreshRequired();
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass)

Example 5 with CharacterLevelFacade

use of pcgen.facade.core.CharacterLevelFacade in project pcgen by PCGen.

the class CharacterFacadeImpl method getClassLevel.

/**
	 * @see pcgen.core.facade.CharacterFacade#getClassLevel(pcgen.core.facade.ClassFacade)
	 */
@Override
public int getClassLevel(ClassFacade c) {
    int clsLevel = 0;
    // We have to compare by class key as classes get cloned and we may have multiple instances of the same class in our level list 
    String classKey = c.getKeyName();
    for (CharacterLevelFacade charLevel : pcClassLevels) {
        if (charLevelsFacade.getClassTaken(charLevel).getKeyName().equals(classKey)) {
            clsLevel++;
        }
    }
    return clsLevel;
}
Also used : CharacterLevelFacade(pcgen.facade.core.CharacterLevelFacade)

Aggregations

CharacterLevelFacade (pcgen.facade.core.CharacterLevelFacade)10 SkillCost (pcgen.cdom.enumeration.SkillCost)4 PCClass (pcgen.core.PCClass)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Skill (pcgen.core.Skill)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1 SkillBreakdown (pcgen.facade.core.CharacterLevelsFacade.SkillBreakdown)1 ClassFacade (pcgen.facade.core.ClassFacade)1