use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.
the class PlayerCharacter method clone.
/**
* Returns a deep copy of the PlayerCharacter. Note: This method does a
* shallow copy of many lists in here that seem to point to "system"
* objects. These copies should be validated before using this method.
*
* @return a new deep copy of the {@code PlayerCharacter}
*/
@Override
public PlayerCharacter clone() {
PlayerCharacter aClone = null;
// calling super.clone won't work because it will not create
// new data instances for all the final variables and I won't
// be able to reset them. Need to call new PlayerCharacter()
// aClone = (PlayerCharacter)super.clone();
aClone = new PlayerCharacter(campaignFacet.getSet(id));
//aClone.variableProcessor = new VariableProcessorPC(aClone);
try {
aClone.assocSupt = assocSupt.clone();
} catch (CloneNotSupportedException e) {
Logging.errorPrint("PlayerCharacter.clone failed", e);
}
Collection<AbstractStorageFacet> beans = SpringHelper.getStorageBeans();
for (AbstractStorageFacet bean : beans) {
bean.copyContents(id, aClone.id);
}
aClone.bonusManager = bonusManager.buildDeepClone(aClone);
for (PCClass cloneClass : aClone.classFacet.getSet(aClone.id)) {
cloneClass.addFeatPoolBonus(aClone);
}
Follower followerMaster = masterFacet.get(id);
if (followerMaster != null) {
aClone.masterFacet.set(id, followerMaster.clone());
} else {
aClone.masterFacet.remove(id);
}
aClone.equipSetFacet.removeAll(aClone.id);
for (EquipSet eqSet : equipSetFacet.getSet(id)) {
aClone.addEquipSet((EquipSet) eqSet.clone());
}
List<Equipment> equipmentMasterList = aClone.getEquipmentMasterList();
aClone.userEquipmentFacet.removeAll(aClone.id);
aClone.equipmentFacet.removeAll(aClone.id);
aClone.equippedFacet.removeAll(aClone.id);
FacetLibrary.getFacet(SourcedEquipmentFacet.class).removeAll(aClone.id);
for (Equipment equip : equipmentMasterList) {
aClone.addEquipment(equip.clone());
}
aClone.levelInfoFacet.removeAll(aClone.id);
for (PCLevelInfo info : getLevelInfo()) {
PCLevelInfo newLvlInfo = info.clone();
aClone.levelInfoFacet.add(aClone.id, newLvlInfo);
}
aClone.spellBookFacet.removeAll(aClone.id);
for (String book : spellBookFacet.getBookNames(id)) {
aClone.addSpellBook((SpellBook) spellBookFacet.getBookNamed(id, book).clone());
}
aClone.calcEquipSetId = calcEquipSetId;
aClone.tempBonusItemList.addAll(tempBonusItemList);
aClone.descriptionLst = descriptionLst;
aClone.autoKnownSpells = autoKnownSpells;
aClone.autoLoadCompanion = autoLoadCompanion;
aClone.autoSortGear = autoSortGear;
aClone.outputSheetHTML = outputSheetHTML;
aClone.outputSheetPDF = outputSheetPDF;
aClone.ageSetKitSelections = new boolean[10];
aClone.defaultDomainSource = defaultDomainSource;
System.arraycopy(ageSetKitSelections, 0, aClone.ageSetKitSelections, 0, ageSetKitSelections.length);
// Not sure what this is for
aClone.importing = false;
aClone.useTempMods = useTempMods;
aClone.costPool = costPool;
aClone.currentEquipSetNumber = currentEquipSetNumber;
aClone.poolAmount = poolAmount;
// order in which the skills will be output.
aClone.skillsOutputOrder = skillsOutputOrder;
aClone.spellLevelTemp = spellLevelTemp;
aClone.pointBuyPoints = pointBuyPoints;
aClone.adjustMoveRates();
//This mod set is necessary to trigger certain calculations to ensure correct output
//modSkillPointsBuffer = Integer.MIN_VALUE;
aClone.calcActiveBonuses();
//Just to be safe
aClone.equippedFacet.reset(aClone.id);
aClone.serial = serial;
return aClone;
}
use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.
the class PlayerCharacter method addLevelInfo.
public PCLevelInfo addLevelInfo(final String classKeyName) {
final PCLevelInfo li = new PCLevelInfo(classKeyName);
addLevelInfo(li);
return li;
}
use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.
the class PlayerCharacter method makeIntoExClass.
public void makeIntoExClass(final PCClass fromClass) {
CDOMSingleRef<PCClass> exc = fromClass.get(ObjectKey.EX_CLASS);
try {
PCClass cl = exc.get();
PCClass toClass = getClassKeyed(cl.getKeyName());
boolean bClassNew;
int toLevel;
if (toClass == null) {
//Still required :(
toClass = cl.clone();
bClassNew = true;
toLevel = 0;
} else {
bClassNew = false;
toLevel = getLevel(toClass);
}
//Capture necessary information
final int fromLevel = getLevel(fromClass);
Integer[] hpArray = new Integer[fromLevel];
for (int i = 0; i < fromLevel; i++) {
PCClassLevel frompcl = getActiveClassLevel(fromClass, i);
Integer hp = getHP(frompcl);
if (hp == null) {
System.err.println("Did not find HP for " + fromClass + " " + (i + 1) + " " + frompcl);
}
hpArray[i] = hp;
}
for (int i = 0; i < fromLevel; i++) {
fromClass.doMinusLevelMods(this, fromLevel - i);
}
fromClass.setLevel(0, this);
//Do the class swap
if (bClassNew) {
classFacet.replaceClass(id, fromClass, toClass);
} else {
classFacet.removeClass(id, fromClass);
}
toClass.setLevel(toLevel + fromLevel, this);
//Restore capture info to new class
for (int i = 0; i < fromLevel; i++) {
PCClassLevel topcl = getActiveClassLevel(toClass, i);
setHP(topcl, hpArray[i]);
}
//
for (int idx = getLevelInfoSize() - 1; idx >= 0; --idx) {
final PCLevelInfo li = levelInfoFacet.get(id, idx);
if (li.getClassKeyName().equals(fromClass.getKeyName())) {
li.setClassKeyName(toClass.getKeyName());
}
}
//
for (Skill skill : getSkillSet()) {
SkillRankControl.replaceClassRank(this, skill, fromClass, cl);
}
setSkillPool(toClass, fromClass.getSkillPool(this));
} catch (NumberFormatException nfe) {
ShowMessageDelegate.showMessageDialog(nfe.getMessage(), Constants.APPLICATION_NAME, MessageType.INFORMATION);
}
}
use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.
the class PlayerCharacter method giveClassesAway.
public void giveClassesAway(final PCClass toClass, final PCClass fromClass, int iCount) {
if ((toClass == null) || (fromClass == null)) {
return;
}
// Will take destination class over maximum?
if (toClass.hasMaxLevel() && (getLevel(toClass) + iCount) > toClass.getSafe(IntegerKey.LEVEL_LIMIT)) {
iCount = toClass.getSafe(IntegerKey.LEVEL_LIMIT) - getLevel(toClass);
}
// Enough levels to move?
if ((getLevel(fromClass) <= iCount) || (iCount < 1)) {
return;
}
final int fromLevel = getLevel(fromClass);
final int iFromLevel = fromLevel - iCount;
final int toLevel = getLevel(toClass);
//Capture necessary information
Integer[] hpArray = new Integer[iCount + toLevel];
for (int i = 0; i < iCount; i++) {
PCClassLevel frompcl = getActiveClassLevel(fromClass, i + iFromLevel);
hpArray[i] = getHP(frompcl);
}
for (int i = 0; i < toLevel; i++) {
PCClassLevel topcl = getActiveClassLevel(toClass, i);
hpArray[i + iCount] = getHP(topcl);
}
for (int i = 0; i < iCount; i++) {
fromClass.doMinusLevelMods(this, fromLevel - i);
}
//Do the class level swap
fromClass.setLevel(iFromLevel, this);
toClass.setLevel(toLevel + iCount, this);
//Restore capture info to new class
for (int i = 0; i < iCount + toLevel; i++) {
PCClassLevel topcl = getActiveClassLevel(toClass, i);
setHP(topcl, hpArray[i]);
}
// first, change the toClass current PCLevelInfo level
for (PCLevelInfo pcl : getLevelInfo()) {
if (pcl.getClassKeyName().equals(toClass.getKeyName())) {
final int iTo = (pcl.getClassLevel() + getLevel(toClass)) - toLevel;
pcl.setClassLevel(iTo);
}
}
// change old class PCLevelInfo to the new class
for (PCLevelInfo pcl : getLevelInfo()) {
if (pcl.getClassKeyName().equals(fromClass.getKeyName()) && (pcl.getClassLevel() > iFromLevel)) {
final int iFrom = pcl.getClassLevel() - iFromLevel;
pcl.setClassKeyName(toClass.getKeyName());
pcl.setClassLevel(iFrom);
}
}
/*
* // get skills associated with old class and link to new class for
* (Iterator e = getSkillList().iterator(); e.hasNext();) { Skill aSkill =
* (Skill) e.next(); aSkill.replaceClassRank(fromClass.getName(),
* toClass.getName()); } toClass.setSkillPool(fromClass.getSkillPool());
*/
}
use of pcgen.core.pclevelinfo.PCLevelInfo in project pcgen by PCGen.
the class PlayerCharacter method checkSkillModChange.
public void checkSkillModChange() {
List<PCClass> newClasses = getClassList();
Collection<PCLevelInfo> levelInfo = getLevelInfo();
int levelIndex = 1;
for (PCLevelInfo lvlInfo : levelInfo) {
Map<String, PCClass> classMap = new HashMap<>();
for (PCClass pcClass : newClasses) {
classMap.put(pcClass.getKeyName(), pcClass);
}
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;
}
PCClassLevel classLevel = getActiveClassLevel(currClass, lvlInfo.getClassLevel());
checkSkillModChangeForLevel(currClass, lvlInfo, classLevel, levelIndex++);
}
}
Aggregations