use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method removePurchasedEquipment.
/**
* @see pcgen.core.facade.CharacterFacade#removePurchasedEquipment(pcgen.core.facade.EquipmentFacade, int)
*/
@Override
public void removePurchasedEquipment(EquipmentFacade equipment, int quantity, boolean free) {
if (equipment == null || quantity <= 0) {
return;
}
Equipment equipItemToAdjust = (Equipment) equipment;
Equipment updatedItem = theCharacter.getEquipmentNamed(equipItemToAdjust.getName());
double numRemoved = 0;
// see if item is already in inventory; update it
if (updatedItem != null) {
final double prevQty = (updatedItem.qty() < 0) ? 0 : updatedItem.qty();
numRemoved = Math.min(quantity, prevQty);
final double newQty = Math.max(prevQty - numRemoved, 0);
if (newQty <= 0) {
// completely remove item
updatedItem.setNumberCarried(new Float(0));
updatedItem.setLocation(EquipmentLocation.NOT_CARRIED);
final Equipment eqParent = updatedItem.getParent();
if (eqParent != null) {
eqParent.removeChild(theCharacter, updatedItem);
}
theCharacter.removeEquipment(updatedItem);
purchasedEquip.removeElement(updatedItem);
} else {
// update item count
theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty);
Float qty = new Float(newQty);
updatedItem.setQty(qty);
updatedItem.setNumberCarried(qty);
purchasedEquip.setQuantity(equipment, qty.intValue());
}
theCharacter.updateEquipmentQty(updatedItem, prevQty, newQty);
Float qty = new Float(newQty);
updatedItem.setQty(qty);
updatedItem.setNumberCarried(qty);
}
// Update the PC and equipment
if (!free) {
double itemCost = calcItemCost(updatedItem, numRemoved * -1, (GearBuySellScheme) gearBuySellSchemeRef.get());
theCharacter.adjustGold(itemCost * -1);
}
theCharacter.setCalcEquipmentList();
theCharacter.setDirty(true);
updateWealthFields();
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method isQualifiedFor.
/**
* @see pcgen.core.facade.CharacterFacade#isQualifiedFor(pcgen.core.facade.EquipmentFacade)
*/
@Override
public boolean isQualifiedFor(EquipmentFacade equipment) {
final Equipment equip = (Equipment) equipment;
final boolean accept = PrereqHandler.passesAll(equip.getPrerequisiteList(), theCharacter, equip);
if (accept && (equip.isShield() || equip.isWeapon() || equip.isArmor())) {
return theCharacter.isProficientWith(equip);
}
return accept;
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method openCustomizer.
private Equipment openCustomizer(Equipment aEq) {
if (aEq == null) {
return null;
}
Equipment newEquip = aEq.clone();
if (!newEquip.containsKey(ObjectKey.BASE_ITEM)) {
newEquip.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(aEq));
}
List<VarModifier<?>> modifiers = newEquip.getListFor(ListKey.MODIFY);
if (modifiers != null) {
for (VarModifier<?> vm : modifiers) {
theCharacter.addModifier(vm, newEquip, newEquip);
}
}
for (EquipmentHead head : newEquip.getEquipmentHeads()) {
modifiers = head.getListFor(ListKey.MODIFY);
if (modifiers != null) {
for (VarModifier<?> vm : modifiers) {
theCharacter.addModifier(vm, head, head);
}
}
}
EquipmentBuilderFacadeImpl builder = new EquipmentBuilderFacadeImpl(newEquip, theCharacter, delegate);
CustomEquipResult result = delegate.showCustomEquipDialog(this, builder);
if (newEquip != null && result != CustomEquipResult.CANCELLED) {
dataSet.addEquipment(newEquip);
}
//TODO if this is returning null, then the SolverManager needs to destroy the unused channels :/
return result == CustomEquipResult.PURCHASE ? newEquip : null;
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method addNote.
@Override
public void addNote(List<EquipmentFacade> targets) {
List<Equipment> notedEquip = new ArrayList<>();
for (EquipmentFacade equipmentFacade : targets) {
if (equipmentFacade instanceof Equipment) {
notedEquip.add((Equipment) equipmentFacade);
}
}
if (notedEquip.isEmpty()) {
return;
}
for (Equipment equip : notedEquip) {
String note = getNote(equip);
if (note == null) {
return;
}
equip.setNote(note);
purchasedEquip.modifyElement(equip);
}
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method removeTempBonus.
@Override
public void removeTempBonus(TempBonusFacade bonusFacade) {
if (bonusFacade == null || !(bonusFacade instanceof TempBonusFacadeImpl)) {
return;
}
TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) bonusFacade;
Equipment aEq = null;
if (tempBonus.getTarget() instanceof Equipment) {
aEq = (Equipment) tempBonus.getTarget();
}
CDOMObject originObj = tempBonus.getOriginObj();
TempBonusHelper.removeBonusFromCharacter(theCharacter, aEq, originObj);
appliedTempBonuses.removeElement(tempBonus);
refreshStatScores();
postLevellingUpdates();
}
Aggregations