Search in sources :

Example 6 with PCLevelInfo

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

the class PCClass method subLevel.

void subLevel(final PlayerCharacter aPC) {
    if (aPC != null) {
        int total = aPC.getTotalLevels();
        int oldLevel = aPC.getLevel(this);
        int spMod = 0;
        final PCLevelInfo pcl = aPC.getLevelInfoFor(getKeyName(), oldLevel);
        if (pcl != null) {
            spMod = pcl.getSkillPointsGained(aPC);
        } else {
            Logging.errorPrint("ERROR: could not find class/level info for " + getDisplayName() + "/" + oldLevel);
        }
        final int newLevel = oldLevel - 1;
        if (oldLevel > 0) {
            PCClassLevel classLevel = aPC.getActiveClassLevel(this, oldLevel - 1);
            aPC.removeHP(classLevel);
        }
        //			aPC.adjustFeats(-aPC.getBonusFeatsForNewLevel(this));
        setLevel(newLevel, aPC);
        aPC.removeKnownSpellsForClassLevel(this);
        doMinusLevelMods(aPC, newLevel + 1);
        DomainApplication.removeDomainsForLevel(this, newLevel + 1, aPC);
        if (newLevel == 0) {
            SubClassApplication.setSubClassKey(aPC, this, Constants.NONE);
            //
            for (Skill skill : aPC.getSkillSet()) {
                SkillRankControl.setZeroRanks(this, aPC, skill);
            }
            Integer currentPool = aPC.getSkillPool(this);
            spMod = currentPool == null ? 0 : currentPool;
        }
        if (!isMonster() && (total > aPC.getTotalLevels())) {
            total = aPC.getTotalLevels();
            // Roll back any stat changes that were made as part of the
            // level
            final List<PCLevelInfoStat> moddedStats = new ArrayList<>();
            if (pcl.getModifiedStats(true) != null) {
                moddedStats.addAll(pcl.getModifiedStats(true));
            }
            if (pcl.getModifiedStats(false) != null) {
                moddedStats.addAll(pcl.getModifiedStats(false));
            }
            if (!moddedStats.isEmpty()) {
                for (PCLevelInfoStat statToRollback : moddedStats) {
                    for (PCStat aStat : aPC.getStatSet()) {
                        if (aStat.equals(statToRollback.getStat())) {
                            aPC.setStat(aStat, aPC.getStat(aStat) - statToRollback.getStatMod());
                            break;
                        }
                    }
                }
            }
        }
        aPC.setLevelWithoutConsequence(this, newLevel);
        if (isMonster() || (total != 0)) {
            Integer currentPool = aPC.getSkillPool(this);
            int newSkillPool = (currentPool == null ? 0 : currentPool) - spMod;
            aPC.setSkillPool(this, newSkillPool);
            aPC.setDirty(true);
        }
        if (aPC.getLevel(this) == 0) {
            aPC.removeClass(this);
        }
        aPC.validateCharacterDomains();
        if (!aPC.isImporting()) {
            final int maxxp = aPC.minXPForNextECL();
            if (aPC.getXP() >= maxxp) {
                aPC.setXP(Math.max(maxxp - 1, 0));
            }
        }
    } else {
        Logging.errorPrint("No current pc in subLevel()? How did this happen?");
        return;
    }
}
Also used : PCLevelInfoStat(pcgen.core.pclevelinfo.PCLevelInfoStat) ArrayList(java.util.ArrayList) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 7 with PCLevelInfo

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

the class CharacterFacadeImpl method showPointPool.

/**
	 * Update the  
	 */
private void showPointPool() {
    if (poolPointText == null) {
        return;
    }
    int poolPointsTotal = 0;
    for (PCLevelInfo pcl : charDisplay.getLevelInfo()) {
        poolPointsTotal += pcl.getSkillPointsGained(theCharacter);
    }
    int poolPointsUsed = poolPointsTotal - theCharacter.getSkillPoints();
    //$NON-NLS-1$
    poolPointText.set(Integer.toString(poolPointsUsed) + " / " + Integer.toString(poolPointsTotal));
}
Also used : PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 8 with PCLevelInfo

use of pcgen.core.pclevelinfo.PCLevelInfo 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 9 with PCLevelInfo

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

the class PlayerCharacter method removeLevelInfo.

/**
	 * Remove from the character the PCLevelInfo representing the highest level
	 * of the supplied class.
	 *
	 * @param classKeyName The keyname of the class to have a level removed.
	 * @return The level removed, or null if none was found
	 */
private PCLevelInfo removeLevelInfo(final String classKeyName) {
    for (int idx = getLevelInfoSize() - 1; idx >= 0; --idx) {
        final PCLevelInfo li = levelInfoFacet.get(id, idx);
        if (li.getClassKeyName().equals(classKeyName)) {
            levelInfoFacet.remove(id, li);
            setDirty(true);
            return li;
        }
    }
    return null;
}
Also used : PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 10 with PCLevelInfo

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

the class PlayerCharacter method addTemplate.

public boolean addTemplate(final PCTemplate inTemplate) {
    if (inTemplate == null) {
        return false;
    }
    // Don't allow multiple copies of template.
    if (hasTemplate(inTemplate)) {
        return false;
    }
    // this is what this value was before
    int lockMonsterSkillPoints = 0;
    // adding this template
    for (PCClass pcClass : getClassSet()) {
        if (pcClass.isMonster()) {
            lockMonsterSkillPoints = (int) getTotalBonusTo("MONSKILLPTS", "LOCKNUMBER");
            break;
        }
    }
    boolean added = templateInputFacet.add(id, inTemplate);
    if (!added) {
        return false;
    }
    this.setDirty(true);
    calcActiveBonuses();
    // this is what this value was before
    int postLockMonsterSkillPoints;
    // adding this template
    boolean first = true;
    for (PCClass pcClass : getClassSet()) {
        if (pcClass.isMonster()) {
            postLockMonsterSkillPoints = (int) getTotalBonusTo("MONSKILLPTS", "LOCKNUMBER");
            if (postLockMonsterSkillPoints != lockMonsterSkillPoints && postLockMonsterSkillPoints > 0) {
                for (PCLevelInfo pi : getLevelInfo()) {
                    final int newSkillPointsGained = recalcSkillPointMod(pcClass, pi.getClassLevel());
                    if (pi.getClassKeyName().equals(pcClass.getKeyName())) {
                        final int formerGained = pi.getSkillPointsGained(this);
                        pi.setSkillPointsGained(this, newSkillPointsGained);
                        pi.setSkillPointsRemaining(pi.getSkillPointsRemaining() + newSkillPointsGained - formerGained);
                        setSkillPool(pcClass, pcClass.getSkillPool(this) + newSkillPointsGained - formerGained);
                    }
                }
            }
        }
        //
        if (!importing) {
            Processor<HitDie> dieLock = inTemplate.get(ObjectKey.HITDIE);
            if (dieLock != null) {
                for (int level = 1; level <= getLevel(pcClass); level++) {
                    HitDie baseHD = pcClass.getSafe(ObjectKey.LEVEL_HITDIE);
                    if (!baseHD.equals(getLevelHitDie(pcClass, level))) {
                        // If the HD has changed from base reroll
                        rollHP(pcClass, level, first);
                    }
                }
            }
        }
        first = false;
    }
    setDirty(true);
    return true;
}
Also used : HitDie(pcgen.cdom.content.HitDie) 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