use of pcgen.core.PCClass in project pcgen by PCGen.
the class ClassSkillListFacet method levelChanged.
@Override
public void levelChanged(ClassLevelChangeEvent lce) {
if ((lce.getOldLevel() == 0) && (lce.getNewLevel() > 0)) {
PCClass cl = lce.getPCClass();
CharID id = lce.getCharID();
TransitionChoice<ClassSkillList> csc = cl.get(ObjectKey.SKILLLIST_CHOICE);
if (csc == null) {
ClassSkillList l = cl.get(ObjectKey.CLASS_SKILLLIST);
if (l != null) {
defaultClassSkillListFacet.add(id, cl, l, cl);
}
} else {
PlayerCharacter pc = trackingFacet.getPC(id);
for (ClassSkillList st : csc.driveChoice(pc)) {
add(id, cl, st, cl);
}
}
} else if ((lce.getOldLevel() > 0) && (lce.getNewLevel() == 0)) {
removeAllFromSource(lce.getCharID(), lce.getPCClass());
}
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class ClassSkillListFacet method dataAdded.
@Override
public void dataAdded(ScopeFacetChangeEvent<CharID, PCClass, String> dfce) {
PCClass cl = dfce.getScope();
String subClassKey = dfce.getCDOMObject();
SubClass subclass = cl.getSubClassKeyed(subClassKey);
if (subclass != null) {
ClassSkillList scl = subclass.get(ObjectKey.CLASS_SKILLLIST);
defaultClassSkillListFacet.add(dfce.getCharID(), cl, scl, subclass);
}
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class ClassSkillListFacet method dataRemoved.
@Override
public void dataRemoved(ScopeFacetChangeEvent<CharID, PCClass, String> dfce) {
PCClass cl = dfce.getScope();
String subClassKey = dfce.getCDOMObject();
SubClass subclass = cl.getSubClassKeyed(subClassKey);
if (subclass != null) {
ClassSkillList scl = subclass.get(ObjectKey.CLASS_SKILLLIST);
defaultClassSkillListFacet.add(dfce.getCharID(), cl, scl, subclass);
}
}
use of pcgen.core.PCClass 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.core.PCClass in project pcgen by PCGen.
the class SpellLevel method decodeChoice.
public static SpellLevel decodeChoice(String persistentFormat) {
int loc = persistentFormat.indexOf(";LEVEL.");
String classString;
String levelString;
if (loc == -1) {
/*
* Handle old persistence
*/
int spaceLoc = persistentFormat.indexOf(' ');
classString = persistentFormat.substring(0, spaceLoc);
levelString = persistentFormat.substring(spaceLoc + 1);
} else {
String classText = persistentFormat.substring(0, 6);
if (!"CLASS.".equals(classText)) {
return null;
}
classString = persistentFormat.substring(6, loc);
levelString = persistentFormat.substring(loc + 7);
}
PCClass pcc = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classString);
try {
int level = Integer.parseInt(levelString);
return new SpellLevel(pcc, level);
} catch (NumberFormatException e) {
return null;
}
}
Aggregations