Search in sources :

Example 1 with AbstractStorageFacet

use of pcgen.cdom.facet.base.AbstractStorageFacet 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;
}
Also used : AbstractStorageFacet(pcgen.cdom.facet.base.AbstractStorageFacet) EquipSet(pcgen.core.character.EquipSet) SourcedEquipmentFacet(pcgen.cdom.facet.SourcedEquipmentFacet) Follower(pcgen.core.character.Follower) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Aggregations

SourcedEquipmentFacet (pcgen.cdom.facet.SourcedEquipmentFacet)1 AbstractStorageFacet (pcgen.cdom.facet.base.AbstractStorageFacet)1 EquipSet (pcgen.core.character.EquipSet)1 Follower (pcgen.core.character.Follower)1 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)1