use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class PlayerCharacter method setCalcEquipmentList.
/**
* Set's current equipmentList to selected output EquipSet then loops
* through all the equipment and sets the correct status of each (equipped,
* carried, etc). Boolean parameter useTempBonuses controls whether or
* not the temporary bonuses associated with equipment are applied.
*
* @param useTempBonuses whether to apply Temporary bonuses from equipment.
*/
public void setCalcEquipmentList(final boolean useTempBonuses) {
// First we get the EquipSet that is going to be used
// to calculate everything from
final String calcId = getCalcEquipSetId();
final EquipSet eSet = getEquipSetByIdPath(calcId);
if (eSet == null) {
if (Logging.isDebugMode()) {
Logging.debugPrint(//$NON-NLS-1$
"No EquipSet has been selected for calculations yet.");
}
return;
}
// set PC's equipmentList to new one
/*
* TODO This "global reset" directly followed by testing in the
* EquipSets and re-adding items as local equipment is something that
* needs to be cleaned up
*/
equipmentFacet.removeAll(id);
// get all the PC's EquipSet's
final List<EquipSet> pcEquipSetList = new ArrayList<>(getEquipSet());
if (pcEquipSetList.isEmpty()) {
equippedFacet.reset(id);
return;
}
// make sure EquipSet's are in sorted order
// (important for Containers contents)
Collections.sort(pcEquipSetList);
// then set status to equipped and add to PC's equipment list
for (EquipSet es : pcEquipSetList) {
if (es.getItem() == null || !es.isPartOf(calcId)) {
continue;
}
es.equipItem(this);
es.addNoteToItem();
addLocalEquipment(es.getItem());
}
// containers contents are updated
for (Equipment eq : getEquipmentSet()) {
if (eq.isContainer()) {
eq.updateContainerContentsString(this);
}
// also make sure the masterList output order is
// preserved as this equipmentList is a modified
// clone of the original
final Equipment anEquip = getEquipmentNamed(eq.getName());
if (anEquip != null) {
eq.setOutputIndex(anEquip.getOutputIndex());
}
}
// if temporary bonuses, read the bonus equipList
if (useTempBonuses) {
for (Equipment eq : tempBonusItemList) {
// make sure that this EquipSet is the one
// this temporary bonus item comes from
// to make sure we keep them together
final Equipment anEquip = getEquipmentNamed(eq.getName(), getEquipmentSet());
if (anEquip == null) {
continue;
}
eq.setQty(anEquip.getQty());
eq.setNumberCarried(anEquip.getCarried());
if (anEquip.isEquipped()) {
if (eq.isWeapon()) {
eq.put(IntegerKey.SLOTS, 0);
eq.put(ObjectKey.CURRENT_COST, BigDecimal.ZERO);
eq.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
eq.setLocation(anEquip.getLocation());
} else {
// replace the orig item with the bonus item
eq.setLocation(anEquip.getLocation());
removeLocalEquipment(anEquip);
anEquip.setIsEquipped(false, this);
anEquip.setLocation(EquipmentLocation.NOT_CARRIED);
anEquip.setNumberCarried(0.0f);
}
eq.setIsEquipped(true, this);
eq.setNumberEquipped(1);
} else {
eq.put(ObjectKey.CURRENT_COST, BigDecimal.ZERO);
eq.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
eq.setLocation(EquipmentLocation.EQUIPPED_TEMPBONUS);
eq.setIsEquipped(false, this);
}
// Adding this type to be correctly treated by Merge
eq.addType(Type.TEMPORARY);
addLocalEquipment(eq);
}
}
// all done!
equippedFacet.reset(id);
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class CharacterFacadeImpl method deleteEquipmentSet.
/**
* @see pcgen.core.facade.CharacterFacade#deleteEquipmentSet(pcgen.core.facade.EquipmentSetFacade)
*/
@Override
public void deleteEquipmentSet(EquipmentSetFacade set) {
if (set == null || !(set instanceof EquipmentSetFacadeImpl)) {
return;
}
EquipmentSetFacadeImpl setImpl = (EquipmentSetFacadeImpl) set;
EquipSet eSet = setImpl.getEquipSet();
theCharacter.delEquipSet(eSet);
equipmentSets.removeElement(set);
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipSetMigration method renumberChildren.
/**
* Renumber the equipment sets in order with a potential new parent path
* also. This is a recursive function.
*
* @param targets The ordered list of equipment sets to be renumbered.
* @param allEquipSets The collection of all of the character's equipment sets.
* @param newParentPath The new path of the parent.
*/
private static void renumberChildren(List<EquipSet> targets, Collection<EquipSet> allEquipSets, String newParentPath) {
if (targets.isEmpty()) {
return;
}
int index = 1;
NumberFormat format = new DecimalFormat("00");
for (EquipSet equipSet : targets) {
String oldIdPath = equipSet.getIdPath();
equipSet.setIdPath(newParentPath + "." + format.format(index++));
List<EquipSet> children = getSortedChildren(allEquipSets, oldIdPath);
renumberChildren(children, allEquipSets, equipSet.getIdPath());
}
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class EquipSetMigration method getSortedChildren.
/**
* Retrieve a list of the equipment sets underthe parent id path in id path order.
* @param allEquipSets The set of all equipment sets.
* @param parentIdPath The id path of the top of the tree we want to retrieve.
* @return The sorted list of child equipment sets.
*/
private static List<EquipSet> getSortedChildren(Collection<EquipSet> allEquipSets, String parentIdPath) {
List<EquipSet> children = new ArrayList<>();
for (EquipSet equipSet : allEquipSets) {
if (equipSet.getParentIdPath().equals(parentIdPath)) {
children.add(equipSet);
}
}
children.sort(comparator);
return children;
}
use of pcgen.core.character.EquipSet in project pcgen by PCGen.
the class KitGear method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
actingQuantity = quantity;
actingCost = maxCost;
actingMods = mods == null ? null : new ArrayList<>(mods);
actingLocation = theLocationStr;
if (size != null) {
actingSize = size.get();
}
theEquipment = null;
theQty = 0;
theLocation = "";
theCost = BigDecimal.ZERO;
processLookups(aKit, aPC);
int aBuyRate = aKit.getBuyRate(aPC);
final BigDecimal pcGold = aPC.getGold();
final BigDecimal fixedTotalCost = aKit.getTotalCost(aPC);
if (fixedTotalCost != null) {
// We are going to charge fr the kit once, rather than for every piece of gear
aBuyRate = 0;
}
List<Equipment> eqList = new ArrayList<>(equip.getContainedObjects());
if (actingCost != null) {
final BigDecimal bdMaxCost = new BigDecimal(Integer.toString(actingCost));
for (Iterator<Equipment> i = eqList.iterator(); i.hasNext(); ) {
if (i.next().getCost(aPC).compareTo(bdMaxCost) > 0) {
i.remove();
}
}
}
if (eqList.size() == 1) {
theEquipment = eqList.get(0);
} else {
List<Equipment> selected = new ArrayList<>(1);
selected = Globals.getChoiceFromList("Choose equipment", eqList, selected, 1, aPC);
if (selected.size() == 1) {
theEquipment = selected.get(0);
}
}
//
// TODO: Check to see if the user has selected an item that
// requires modification (MOD:R)
theEquipment = theEquipment.clone();
//
// Resize item for character--never resize weapons or ammo, unless it's a
// natural (weapon)
boolean tryResize = false;
SizeAdjustment sizeToSet = aPC.getSizeAdjustment();
if (actingSize == null) {
if (theEquipment.isType("Natural") || (sizeToPC != null && sizeToPC) || (!theEquipment.isWeapon() && !theEquipment.isAmmunition())) {
tryResize = Globals.canResizeHaveEffect(theEquipment, null);
}
} else {
if (sizeToPC != null && sizeToPC) {
tryResize = Globals.canResizeHaveEffect(theEquipment, null);
} else {
sizeToSet = actingSize;
tryResize = true;
}
}
if (tryResize) {
theEquipment.resizeItem(aPC, sizeToSet);
} else {
// We need setBase() called. The only way to do that is to resize.
// We will set the size to itself.
theEquipment.resizeItem(aPC, theEquipment.getSafe(ObjectKey.SIZE).get());
}
//
if (actingMods != null) {
for (EqModRef modref : actingMods) {
/*
* Going to do this the long way for now to avoid ugly entanglements
*/
StringBuilder sb = new StringBuilder(50);
EquipmentModifier eqMod = modref.getRef().get();
sb.append(eqMod.getKeyName());
for (String assoc : modref.getChoices()) {
sb.append(Constants.PIPE).append(eval(aPC, assoc));
}
theEquipment.addEqModifiers(sb.toString(), true);
}
}
if (tryResize || (actingMods != null)) {
theEquipment.nameItemFromModifiers(aPC);
}
if (actingQuantity == null) {
theQty = 1;
} else {
theQty = actingQuantity.resolve(aPC, "").intValue();
}
int origQty = theQty;
final BigDecimal eqCost = theEquipment.getCost(aPC);
if (aBuyRate != 0) {
if (fixedTotalCost == null) {
final BigDecimal bdBuyRate = new BigDecimal(Integer.toString(aBuyRate)).multiply(new BigDecimal("0.01"));
// Check to see if the PC can afford to buy this equipment. If
// not, then decrement the quantity and try again.
theCost = eqCost.multiply(new BigDecimal(Integer.toString(theQty))).multiply(bdBuyRate);
while (theQty > 0) {
if (// PC has enough?
theCost.compareTo(pcGold) <= 0) {
break;
}
theCost = eqCost.multiply(new BigDecimal(Integer.toString(--theQty))).multiply(bdBuyRate);
}
}
aPC.setGold(aPC.getGold().subtract(theCost));
}
boolean outOfFunds = false;
if (theQty != origQty) {
outOfFunds = true;
}
if (outOfFunds) {
warnings.add("GEAR: Could not purchase " + (origQty - theQty) + " " + theEquipment.getName() + ". Not enough funds.");
}
//
if (theQty == 0) {
return false;
}
Equipment testApplyEquipment = theEquipment.clone();
// Temporarily add the equipment so we can see if we can equip it.
testApplyEquipment.setQty(new Float(theQty));
aPC.addEquipment(testApplyEquipment);
Equipment theTarget = null;
if (actingLocation != null) {
theLocation = actingLocation;
if (!theLocation.equalsIgnoreCase("DEFAULT") && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_CARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_NOTCARRIED) && !theLocation.equalsIgnoreCase(Constants.EQUIP_LOCATION_EQUIPPED)) {
theTarget = EquipmentUtilities.findEquipmentByBaseKey(aPC.getEquipmentMasterList(), theLocation);
} else if (theLocation.equalsIgnoreCase("DEFAULT")) {
theLocation = "";
}
EquipSet eSet = null;
if (theTarget != null) {
eSet = aPC.getEquipSetForItem(aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH), theTarget);
}
if (eSet == null) {
eSet = aPC.getEquipSetByIdPath(EquipSet.DEFAULT_SET_PATH);
}
if (eSet == null) {
warnings.add("GEAR: Could not find location " + theLocation + " for gear " + testApplyEquipment.getName() + ".");
return false;
} else {
EquipSet eqSet = aPC.addEquipToTarget(eSet, theTarget, theLocation, testApplyEquipment, new Float(-1.0f));
if (eqSet == null) {
warnings.add("GEAR: Could not equip " + testApplyEquipment.getName() + " to " + theLocation);
}
}
}
return true;
}
Aggregations