Search in sources :

Example 6 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class HitPointFacet method getLevelHitDie.

/**
	 * Returns the HitDie for the given PCClass and level in the Player
	 * Character identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            HitDie of the given PCClass and level will be returned
	 * @param pcClass
	 *            The PCClass for which the HitDie will be returned
	 * @param classLevel
	 *            The level for which the HitDie will be returned
	 * @return The HitDie for the given PCClass and level in the Player
	 *         Character identified by the given CharID
	 */
public HitDie getLevelHitDie(CharID id, PCClass pcClass, int classLevel) {
    // Class Base Hit Die
    HitDie currDie = pcClass.getSafe(ObjectKey.LEVEL_HITDIE);
    Processor<HitDie> dieLock = raceFacet.get(id).get(ObjectKey.HITDIE);
    if (dieLock != null) {
        currDie = dieLock.applyProcessor(currDie, pcClass);
    }
    // Templates
    for (PCTemplate template : templateFacet.getSet(id)) {
        if (template != null) {
            Processor<HitDie> lock = template.get(ObjectKey.HITDIE);
            if (lock != null) {
                currDie = lock.applyProcessor(currDie, pcClass);
            }
        }
    }
    // Levels
    PCClassLevel cl = classFacet.getClassLevel(id, pcClass, classLevel);
    if (cl != null) {
        if (cl.get(ObjectKey.DONTADD_HITDIE) != null) {
            //null;
            currDie = HitDie.ZERO;
        } else {
            Processor<HitDie> lock = cl.get(ObjectKey.HITDIE);
            if (lock != null) {
                currDie = lock.applyProcessor(currDie, pcClass);
            }
        }
    }
    return currDie;
}
Also used : HitDie(pcgen.cdom.content.HitDie) PCTemplate(pcgen.core.PCTemplate) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 7 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel 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 8 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class AddIntegrationTest method testRoundRobinLevelNoSet.

@Test
public void testRoundRobinLevelNoSet() throws PersistenceLayerException {
    primaryProf = new PCClassLevel();
    primaryProf.put(IntegerKey.LEVEL, 1);
    secondaryProf = new PCClassLevel();
    secondaryProf.put(IntegerKey.LEVEL, 1);
    verifyCleanStart();
    TestContext tc = new TestContext();
    emptyCommit(testCampaign, tc);
    commit(modCampaign, tc, ".CLEAR.LEVEL1");
    completeRoundRobin(tc);
}
Also used : TestContext(plugin.lsttokens.editcontext.testsupport.TestContext) PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test)

Example 9 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.

the class AbstractContentTokenTest method testFromClassLevel.

@Test
public void testFromClassLevel() throws PersistenceLayerException {
    PCClassLevel source = create(PCClassLevel.class, "Source");
    processToken(source);
    assertEquals(baseCount(), targetFacetCount());
    classLevelFacet.add(id, source, this);
    assertTrue(containsExpected());
    assertEquals(baseCount() + 1, targetFacetCount());
    classLevelFacet.remove(id, source, this);
    assertEquals(baseCount(), targetFacetCount());
}
Also used : PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test) AbstractTokenModelTest(tokenmodel.testsupport.AbstractTokenModelTest)

Example 10 with PCClassLevel

use of pcgen.cdom.inst.PCClassLevel 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)69 PCClass (pcgen.core.PCClass)26 Test (org.junit.Test)25 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)9 CDOMObject (pcgen.cdom.base.CDOMObject)8 ArrayList (java.util.ArrayList)5 CharID (pcgen.cdom.enumeration.CharID)5 ParseResult (pcgen.rules.persistence.token.ParseResult)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 SpecialAbility (pcgen.core.SpecialAbility)4 LoadContext (pcgen.rules.context.LoadContext)4 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)4 StringTokenizer (java.util.StringTokenizer)3 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)3 Domain (pcgen.core.Domain)3 Skill (pcgen.core.Skill)3 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2