Search in sources :

Example 1 with PCLevelInfoStat

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

the class PCGVer2Creator method appendClassLines.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void appendClassLines(StringBuilder buffer) {
    Cache specials = new Cache();
    for (PCClass pcClass : charDisplay.getClassSet()) {
        int classLevel = charDisplay.getLevel(pcClass);
        buffer.append(IOConstants.TAG_CLASS).append(':');
        buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        final String subClassKey = charDisplay.getSubClassName(pcClass);
        if (subClassKey != null && !Constants.EMPTY_STRING.equals(subClassKey)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SUBCLASS).append(':');
            buffer.append(EntityEncoder.encode(subClassKey));
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_LEVEL).append(':');
        buffer.append(classLevel);
        buffer.append('|');
        buffer.append(IOConstants.TAG_SKILLPOOL).append(':');
        Integer currentPool = thePC.getSkillPool(pcClass);
        buffer.append(currentPool == null ? 0 : currentPool);
        // determine if this class can cast spells
        boolean isCaster = false;
        if (!thePC.getSpellSupport(pcClass).canCastSpells(thePC)) {
            isCaster = true;
        }
        boolean isPsionic = thePC.getSpellSupport(pcClass).hasKnownList() && !isCaster;
        if (isCaster || isPsionic) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SPELLBASE).append(':');
            buffer.append(EntityEncoder.encode(pcClass.getSpellBaseStat()));
            buffer.append('|');
            buffer.append(IOConstants.TAG_CANCASTPERDAY).append(':');
            buffer.append(StringUtil.join(thePC.getSpellSupport(pcClass).getCastListForLevel(classLevel), ","));
        }
        Collection<? extends SpellProhibitor> prohib = charDisplay.getProhibitedSchools(pcClass);
        if (prohib != null) {
            Set<String> set = new TreeSet<>();
            for (SpellProhibitor sp : prohib) {
                set.addAll(sp.getValueList());
            }
            if (!set.isEmpty()) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_PROHIBITED).append(':');
                buffer.append(EntityEncoder.encode(StringUtil.join(set, ",")));
            }
        }
        appendAddTokenInfo(buffer, pcClass);
        buffer.append(IOConstants.LINE_SEP);
        String spec = thePC.getAssoc(pcClass, AssociationKey.SPECIALTY);
        if (spec != null) {
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + '0', spec);
        }
        String key;
        key = pcClass.getKeyName() + IOConstants.TAG_SAVE + '0';
        List<? extends SpecialAbility> salist = charDisplay.getUserSpecialAbilityList(pcClass);
        if (salist != null && !salist.isEmpty()) {
            SpecialAbility sa = salist.get(0);
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SA + 0, sa.getKeyName());
        }
        for (BonusObj save : thePC.getSaveableBonusList(pcClass)) {
            specials.put(key, "BONUS|" + save);
        }
        for (int i = 1; i <= charDisplay.getLevel(pcClass); i++) {
            key = pcClass.getKeyName() + IOConstants.TAG_SAVE + (i - 1);
            PCClassLevel pcl = charDisplay.getActiveClassLevel(pcClass, i);
            for (BonusObj save : thePC.getSaveableBonusList(pcl)) {
                specials.put(key, "BONUS|" + save);
            }
        }
    }
    //
    for (PCLevelInfo pcl : charDisplay.getLevelInfo()) {
        final String classKeyName = pcl.getClassKeyName();
        int lvl = pcl.getClassLevel() - 1;
        PCClass pcClass = thePC.getClassKeyed(classKeyName);
        buffer.append(IOConstants.TAG_CLASSABILITIESLEVEL).append(':');
        if (pcClass == null) {
            pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
            if (pcClass != null) {
                pcClass = thePC.getClassKeyed(pcClass.get(ObjectKey.EX_CLASS).get().getKeyName());
            }
        }
        if (pcClass != null) {
            buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        } else {
            //$NON-NLS-1$
            buffer.append(EntityEncoder.encode("???"));
        }
        buffer.append('=').append(lvl + 1);
        if (pcClass != null) {
            String aKey = charDisplay.getSubstitutionClassName(charDisplay.getActiveClassLevel(pcClass, lvl + 1));
            if (aKey != null) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_SUBSTITUTIONLEVEL).append(':');
                buffer.append(aKey);
            }
            buffer.append('|');
            buffer.append(IOConstants.TAG_HITPOINTS).append(':');
            PCClassLevel classLevel = charDisplay.getActiveClassLevel(pcClass, lvl);
            Integer hp = charDisplay.getHP(classLevel);
            buffer.append(hp == null ? 0 : hp);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SAVE + lvl), IOConstants.TAG_SAVES, IOConstants.TAG_SAVE, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + lvl), IOConstants.TAG_SPECIALTIES, IOConstants.TAG_SPECIALTY, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + lvl), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, lvl);
            if (lvl == 0) {
                appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + (lvl - 1)), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, -1);
            }
            //
            // Remember what choices were made for each of the ADD: tags
            //
            appendAddTokenInfo(buffer, charDisplay.getActiveClassLevel(pcClass, lvl + 1));
        }
        List<PCLevelInfoStat> statList = pcl.getModifiedStats(true);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        statList = pcl.getModifiedStats(false);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        int sp = pcl.getSkillPointsGained(thePC);
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSGAINED).append(':').append(sp);
        }
        sp = pcl.getSkillPointsRemaining();
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSREMAINING).append(':').append(sp);
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : PCLevelInfoStat(pcgen.core.pclevelinfo.PCLevelInfoStat) BonusObj(pcgen.core.bonus.BonusObj) SpecialAbility(pcgen.core.SpecialAbility) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) PCClassLevel(pcgen.cdom.inst.PCClassLevel) TreeSet(java.util.TreeSet) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 2 with PCLevelInfoStat

use of pcgen.core.pclevelinfo.PCLevelInfoStat 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)

Aggregations

PCClassLevel (pcgen.cdom.inst.PCClassLevel)2 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)2 PCLevelInfoStat (pcgen.core.pclevelinfo.PCLevelInfoStat)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 PCClass (pcgen.core.PCClass)1 SpecialAbility (pcgen.core.SpecialAbility)1 SpellProhibitor (pcgen.core.SpellProhibitor)1 BonusObj (pcgen.core.bonus.BonusObj)1