use of pcgen.core.character.EquipSet 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.character.EquipSet in project pcgen by PCGen.
the class PlayerCharacter method getEquipSetForItem.
/**
* Checks to see if Equipment exists in selected EquipSet and if so, then
* return the EquipSet containing eqI
*
* @param eSet
* @param eqI
* @return EquipSet
*/
public EquipSet getEquipSetForItem(EquipSet eSet, Equipment eqI) {
final String rPath = eSet.getIdPath();
for (EquipSet es : getEquipSet()) {
String esIdPath = es.getIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
String rIdPath = rPath + Constants.EQUIP_SET_PATH_SEPARATOR;
if (!esIdPath.startsWith(rIdPath)) {
continue;
}
if (eqI.getName().equals(es.getValue())) {
return es;
}
}
return null;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class PlayerCharacter method addEquipToTarget.
public EquipSet addEquipToTarget(final EquipSet eSet, final Equipment eqTarget, String locName, final Equipment eqI, Float newQty) {
float tempQty = 1.0f;
if (newQty != null) {
tempQty = newQty.floatValue();
} else {
newQty = tempQty;
}
boolean addAll = false;
boolean mergeItem = false;
Equipment masterEq = getEquipmentNamed(eqI.getName());
if (masterEq == null) {
return null;
}
float diffQty = masterEq.getQty().floatValue() - getEquippedQty(eSet, eqI).floatValue();
// been added to the EquipSet
if (newQty.floatValue() < 0.0f) {
tempQty = diffQty;
newQty = new Float(tempQty + getEquippedQty(eSet, eqI).floatValue());
addAll = true;
}
// the PC's equipmentList number for this item
if (tempQty > diffQty) {
return null;
}
// check to see if the target item is a container
if ((eqTarget != null) && eqTarget.isContainer()) {
// set these to newQty just for testing
eqI.setQty(newQty);
eqI.setNumberCarried(newQty);
// of this type and is not full
if (eqTarget.canContain(this, eqI) == 1) {
locName = eqTarget.getName();
addAll = true;
mergeItem = true;
} else {
return null;
}
}
// If there is more than one option return with an error.
if (locName == null || locName.isEmpty()) {
locName = getSingleLocation(eqI);
if (locName.isEmpty()) {
return null;
}
} else // If it is to go into equipped, check for a specific slot it should be in.
if (locName.equalsIgnoreCase("Equipped")) {
String singleLoc = getSingleLocation(eqI);
if (!singleLoc.isEmpty()) {
locName = singleLoc;
}
}
// make sure we can add item to that slot in this EquipSet
if (!canEquipItem(eSet, locName, eqI, eqTarget)) {
return null;
}
if (eqI.isContainer()) {
// don't merge containers
mergeItem = false;
}
EquipSet existingSet = getEquipSetForItem(eSet, eqI);
if (addAll && mergeItem && (existingSet != null)) {
newQty = new Float(tempQty + getEquippedQty(eSet, eqI).floatValue());
existingSet.setQty(newQty);
eqI.setQty(newQty);
eqI.setNumberCarried(newQty);
setDirty(true);
if ((eqTarget != null) && eqTarget.isContainer()) {
eqTarget.updateContainerContentsString(this);
}
return existingSet;
}
if ((eqTarget != null) && eqTarget.isContainer()) {
eqTarget.insertChild(this, eqI);
eqI.setParent(eqTarget);
}
// construct the new IdPath
// new id is one larger than any
// other id at this path level
String id = getNewIdPath(eSet);
// now create a new EquipSet to add
// this Equipment item to
EquipSet newSet = new EquipSet(id, locName, eqI.getName(), eqI);
// set the Quantity of equipment
eqI.setQty(newQty);
newSet.setQty(newQty);
addEquipSet(newSet);
setDirty(true);
return newSet;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class PlayerCharacter method canEquipItem.
/**
* returns true if you can put Equipment into a location in EquipSet
*
* @param eSet
* @param locName
* @param eqI
* @param eqTarget
* @return true if equipment can be added
*/
private boolean canEquipItem(EquipSet eSet, String locName, Equipment eqI, Equipment eqTarget) {
final String idPath = eSet.getIdPath();
// If target is a container, allow it
if ((eqTarget != null) && eqTarget.isContainer()) {
// TODO - Should make sure eqI can be contained by eqTarget
return true;
}
// allow as many as they would like
if (locName.startsWith(Constants.EQUIP_LOCATION_CARRIED) || locName.startsWith(Constants.EQUIP_LOCATION_EQUIPPED) || locName.startsWith(Constants.EQUIP_LOCATION_NOTCARRIED)) {
return true;
}
// allow as many unarmed items as you'd like
if (eqI.isUnarmed()) {
return true;
}
// allow many Secondary Natural weapons
if (locName.equals(Constants.EQUIP_LOCATION_NATURAL_SECONDARY)) {
return true;
}
// Don't allow weapons that are too large for PC
if (eqI.isWeapon() && eqI.isWeaponOutsizedForPC(this) && !eqI.isNatural()) {
return false;
}
// make a HashMap to keep track of the number of each
// item that is already equipped to a slot
Map<String, String> slotMap = new HashMap<>();
for (EquipSet es : getEquipSet()) {
String esID = es.getParentIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
String abID = idPath + Constants.EQUIP_SET_PATH_SEPARATOR;
if (!esID.startsWith(abID)) {
continue;
}
// an item in that particular location
if (es.getName().equals(locName)) {
final Equipment eItem = es.getItem();
final String nString = slotMap.get(locName);
int existNum = 0;
if (nString != null) {
existNum = Integer.parseInt(nString);
}
if (eItem != null) {
existNum += eItem.getSlots(this);
}
slotMap.put(locName, String.valueOf(existNum));
}
}
for (EquipSet es : getEquipSet()) {
String esID = es.getParentIdPath() + Constants.EQUIP_SET_PATH_SEPARATOR;
String abID = idPath + Constants.EQUIP_SET_PATH_SEPARATOR;
if (!esID.startsWith(abID)) {
continue;
}
// checks for hands already in use
if (eqI.isWeapon() && !eqI.isNatural()) {
// weapons can never occupy the same slot
if (es.getName().equals(locName)) {
return false;
}
// other weapon slots can be occupied
if ((locName.equals(Constants.EQUIP_LOCATION_BOTH) || locName.equals(Constants.EQUIP_LOCATION_DOUBLE)) && (es.getName().equals(Constants.EQUIP_LOCATION_PRIMARY) || es.getName().equals(Constants.EQUIP_LOCATION_SECONDARY) || es.getName().equals(Constants.EQUIP_LOCATION_BOTH) || es.getName().equals(Constants.EQUIP_LOCATION_DOUBLE))) {
return false;
}
// inverse of above case
if ((locName.equals(Constants.EQUIP_LOCATION_PRIMARY) || locName.equals(Constants.EQUIP_LOCATION_SECONDARY)) && (es.getName().equals(Constants.EQUIP_LOCATION_BOTH) || es.getName().equals(Constants.EQUIP_LOCATION_DOUBLE))) {
return false;
}
}
// check to see how many are allowed in that slot
if (es.getName().equals(locName)) {
final String nString = slotMap.get(locName);
int existNum = 0;
if (nString != null) {
existNum = Integer.parseInt(nString);
}
existNum += eqI.getSlots(this);
EquipSlot eSlot = Globals.getEquipSlotByName(locName);
if (eSlot == null) {
return true;
}
for (String slotType : eSlot.getContainType()) {
if (eqI.isType(slotType)) {
// if the item takes more slots, return false
if (existNum > (eSlot.getSlotCount() + (int) getTotalBonusTo("SLOTS", slotType))) {
return false;
}
}
}
return true;
}
}
return true;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class PlayerCharacter method moveEquipSetToNewPath.
/**
* Move the equipset to a new unique path under its existing parent.
* @param es The equipment set item to be moved.
*/
public void moveEquipSetToNewPath(EquipSet es) {
String parentPath = es.getParentIdPath();
EquipSet parent = getEquipSetByIdPath(parentPath);
String newPath = getNewIdPath(parent);
es.setIdPath(newPath);
}
Aggregations