use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class PCClassLoader method parseClassLevelLine.
public void parseClassLevelLine(LoadContext context, PCClass pcClass, int lvl, SourceEntry source, String restOfLine) throws PersistenceLayerException {
if (restOfLine == null) {
return;
}
PCClassLevel classlevel = pcClass.getOriginalClassLevel(lvl);
final StringTokenizer colToken = new StringTokenizer(restOfLine, SystemLoader.TAB_DELIM);
// loop through all the tokens and parse them
while (colToken.hasMoreTokens()) {
String token = colToken.nextToken().trim();
int colonLoc = token.indexOf(':');
if (colonLoc == -1) {
Logging.errorPrint("Invalid Token - does not contain a colon: '" + token + "' in Class " + pcClass.getDisplayName() + " of " + source);
continue;
} else if (colonLoc == 0) {
Logging.errorPrint("Invalid Token - starts with a colon: '" + token + "' in Class " + pcClass.getDisplayName() + " of " + source);
continue;
}
String key = token.substring(0, colonLoc);
String value = (colonLoc == token.length() - 1) ? null : token.substring(colonLoc + 1);
if (context.processToken(classlevel, key.intern(), value.intern())) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
}
Logging.clearParseMessages();
}
}
use of pcgen.cdom.inst.PCClassLevel 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);
}
}
}
use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class HitPointFacet method rollHP.
/**
* Rolls the hit points for a given PCClass and level.
*
* @param id
* The CharID identifying the Player Character on which the hit
* points are to be rolled
* @param pcc
* The PCClass for which the hit points are to be rolled
* @param level
* The class level for which the hit points are to be rolled
* @param first
* And identifier indicating if this is the Player Character's
* first level.
*/
public void rollHP(CharID id, PCClass pcc, int level, boolean first) {
int roll = 0;
HitDie lvlDie = getLevelHitDie(id, pcc, level);
if ((lvlDie == null) || (lvlDie.getDie() == 0)) {
roll = 0;
} else {
final int min = 1 + (int) bonusCheckingFacet.getBonus(id, "HD", "MIN") + (int) bonusCheckingFacet.getBonus(id, "HD", "MIN;CLASS." + pcc.getKeyName());
final int max = getLevelHitDie(id, pcc, level).getDie() + (int) bonusCheckingFacet.getBonus(id, "HD", "MAX") + (int) bonusCheckingFacet.getBonus(id, "HD", "MAX;CLASS." + pcc.getKeyName());
if (SettingsHandler.getGame().getHPFormula().isEmpty()) {
if (first && level == 1 && SettingsHandler.isHPMaxAtFirstLevel() && (!SettingsHandler.isHPMaxAtFirstPCClassLevelOnly() || pcc.isType("PC"))) {
roll = max;
} else {
PlayerCharacter pc = trackingFacet.getPC(id);
if (!pc.isImporting()) {
roll = rollHP(min, max, levelFacet.getTotalLevels(id));
}
}
}
roll += ((int) bonusCheckingFacet.getBonus(id, "HP", "CURRENTMAXPERLEVEL"));
}
PCClassLevel classLevel = classFacet.getClassLevel(id, pcc, level - 1);
set(id, classLevel, roll);
}
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;
}
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);
}
}
Aggregations