use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method addEqModifier.
/**
* Adds a feature to the EqModifier attribute of the Equipment object. If a
* non-null selectedChoice is supplied, this method will not be interactive,
* and will not show a dialog if a choice is required. Instead, the provided
* value will be used.
*
* @param eqMod
* The feature to be added to the EqModifier attribute
* @param bPrimary
* The feature to be added to the EqModifier attribute
* @param aPC
* The PC that the modifier is being added for.
* @param selectedChoice
* The choice to be used instead of asking the user, should a
* choice be required.
* @param equipChoice
* The details of the choice to be made. Used when there are
* secondary options.
*/
public void addEqModifier(final EquipmentModifier eqMod, final boolean bPrimary, final PlayerCharacter aPC, final String selectedChoice, final EquipmentChoice equipChoice) {
boolean bImporting = false;
if ((aPC != null) && aPC.isImporting()) {
bImporting = true;
}
if (!bImporting && !canAddModifier(aPC, eqMod, bPrimary)) {
return;
}
List<CDOMSingleRef<EquipmentModifier>> replaces = eqMod.getListFor(ListKey.REPLACED_KEYS);
EquipmentHead head = getEquipmentHead(bPrimary ? 1 : 2);
if (replaces != null) {
//
for (CDOMSingleRef<EquipmentModifier> ref : replaces) {
EquipmentModifier mod = ref.get();
String key = mod.getKeyName();
for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
if (key.equalsIgnoreCase(aMod.getKeyName())) {
head.removeFromListFor(ListKey.EQMOD, aMod);
head.removeVarModifiers(aPC.getCharID(), aMod);
if (bPrimary) {
usePrimaryCache = false;
} else {
useSecondaryCache = false;
}
setDirty(true);
}
}
}
}
if (eqMod.isType("BaseMaterial")) {
for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
if (aMod.isType("BaseMaterial")) {
head.removeFromListFor(ListKey.EQMOD, aMod);
head.removeVarModifiers(aPC.getCharID(), aMod);
if (bPrimary) {
usePrimaryCache = false;
} else {
useSecondaryCache = false;
}
setDirty(true);
}
}
} else if (eqMod.isType("MagicalEnhancement")) {
for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
if (aMod.isType("MagicalEnhancement")) {
head.removeFromListFor(ListKey.EQMOD, aMod);
head.removeVarModifiers(aPC.getCharID(), aMod);
if (bPrimary) {
usePrimaryCache = false;
} else {
useSecondaryCache = false;
}
}
}
}
//
// Add the modifier if it's not already there
//
EquipmentModifier aMod = getEqModifierKeyed(eqMod.getKeyName(), bPrimary);
if (aMod == null) {
//
if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
aMod = eqMod.clone();
if (aMod == null) {
return;
}
} else {
aMod = eqMod;
}
head.addToListFor(ListKey.EQMOD, aMod);
head.addVarModifiers(aPC.getCharID(), aMod);
if (bPrimary) {
usePrimaryCache = false;
} else {
useSecondaryCache = false;
}
}
//
if (!bImporting) {
boolean allRemoved = false;
if (selectedChoice != null && !selectedChoice.isEmpty()) {
if (!eqMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER.")) {
EquipmentChoiceDriver.setChoice(this, aMod, selectedChoice, equipChoice);
allRemoved = !hasAssociations(aMod);
}
} else if (!EquipmentChoiceDriver.getChoice(1, this, aMod, true, aPC)) {
allRemoved = true;
}
if (allRemoved) {
head.removeFromListFor(ListKey.EQMOD, aMod);
head.removeVarModifiers(aPC.getCharID(), aMod);
if (bPrimary) {
usePrimaryCache = false;
} else {
useSecondaryCache = false;
}
}
}
setBase();
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getDamage.
private String getDamage(PlayerCharacter apc, boolean bPrimary) {
int headnum = bPrimary ? 1 : 2;
EquipmentHead head = getEquipmentHeadReference(headnum);
if (head == null) {
return "";
}
String dam = head.get(StringKey.DAMAGE);
if (!isWeapon() || (!bPrimary && !isDouble())) {
return dam == null ? "" : dam;
}
if (bPrimary && dam == null) {
// No need to grab reference, always exists due to if above
EquipmentHead altHead = getEquipmentHead(2);
dam = altHead.get(StringKey.DAMAGE);
}
String override = get(StringKey.DAMAGE_OVERRIDE);
if (bPrimary && override != null) {
// this overides the base damage
dam = override;
}
if (dam == null) {
dam = getWeaponInfo("DAMAGE", bPrimary);
}
final int iSize = sizeInt();
int iMod = iSize + (int) bonusTo(apc, "EQMWEAPON", "DAMAGESIZE", bPrimary);
iMod += (int) bonusTo(apc, "WEAPON", "DAMAGESIZE", bPrimary);
AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
if (iMod < 0) {
iMod = 0;
} else {
int maxIndex = ref.getConstructedObjectCount(SizeAdjustment.class) - 1;
if (iMod > maxIndex) {
iMod = maxIndex;
}
}
SizeAdjustment sa = ref.getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(iMod);
return adjustDamage(dam, sa);
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getItemNameFromModifiers.
/**
* Get the item name based off the modifiers
*
* @param baseName base name of the object, may instead be the base key if generating a key
* @return item name based off the modifiers
*/
public String getItemNameFromModifiers(String baseName) {
CDOMSingleRef<Equipment> baseItem = get(ObjectKey.BASE_ITEM);
if (baseItem == null) {
return getName();
}
final List<EquipmentModifier> modList;
EquipmentHead head = getEquipmentHeadReference(1);
if (head == null) {
modList = Collections.emptyList();
} else {
modList = head.getSafeListFor(ListKey.EQMOD);
}
EquipmentHead althead = getEquipmentHeadReference(2);
final List<EquipmentModifier> altModList;
if (althead == null) {
altModList = Collections.emptyList();
} else {
altModList = althead.getSafeListFor(ListKey.EQMOD);
}
final List<EquipmentModifier> commonList = new ArrayList<>();
final List<List<EquipmentModifier>> modListByFC = initSplitModList();
final List<List<EquipmentModifier>> altModListByFC = initSplitModList();
final List<List<EquipmentModifier>> commonListByFC = initSplitModList();
final Equipment baseEquipment = baseItem.get();
if (baseEquipment != null) {
modList.removeAll(baseEquipment.getEqModifierList(true));
altModList.removeAll(baseEquipment.getEqModifierList(false));
}
for (Iterator<EquipmentModifier> it = modList.iterator(); it.hasNext(); ) {
EquipmentModifier eqMod = it.next();
if (eqMod.getSafe(ObjectKey.VISIBILITY).equals(Visibility.HIDDEN)) {
it.remove();
}
}
extractListFromCommon(commonList, modList);
removeCommonFromList(altModList, commonList, "eqMod expected but not found: ");
// Remove masterwork from the list if magic is present
suppressMasterwork(commonList);
// Split the eqmod lists by format category
splitModListByFormatCat(commonList, commonListByFC);
splitModListByFormatCat(modList, modListByFC);
splitModListByFormatCat(altModList, altModListByFC);
final StringBuilder itemName = new StringBuilder(100);
// Add in front eq mods
int fcf = EqModFormatCat.FRONT.ordinal();
itemName.append(buildEqModDesc(commonListByFC.get(fcf), modListByFC.get(fcf), altModListByFC.get(fcf)));
if (itemName.length() > 0) {
itemName.append(' ');
}
// Add in the base name, less any modifiers
baseName = baseName.trim();
int idx = baseName.indexOf('(');
if (idx >= 0) {
itemName.append(baseName.substring(0, idx - 1).trim());
} else {
itemName.append(baseName);
}
// Add in middle mods
int fcm = EqModFormatCat.MIDDLE.ordinal();
String eqmodDesc1 = buildEqModDesc(commonListByFC.get(fcm), modListByFC.get(fcm), altModListByFC.get(fcm));
if (!eqmodDesc1.isEmpty()) {
itemName.append(' ').append(eqmodDesc1);
}
// Tack on the original modifiers
if (idx >= 0) {
itemName.append(' ');
itemName.append(baseName.substring(idx));
}
// Strip off the ending ')' in anticipation of more modifiers
final int idx1 = itemName.toString().lastIndexOf(')');
if (idx1 >= 0) {
itemName.setLength(idx1);
itemName.append('/');
} else {
itemName.append(" (");
}
//
// Put size in name if not the same as the base item
//
SizeAdjustment thisSize = getSafe(ObjectKey.SIZE).get();
if (!getSafe(ObjectKey.BASESIZE).get().equals(thisSize)) {
itemName.append(thisSize.getDisplayName());
itemName.append('/');
}
// Put in parens mods
int fcp = EqModFormatCat.PARENS.ordinal();
itemName.append(buildEqModDesc(commonListByFC.get(fcp), modListByFC.get(fcp), altModListByFC.get(fcp)));
//
if (itemName.toString().endsWith("/") || itemName.toString().endsWith(";")) {
itemName.setLength(itemName.length() - 1);
}
itemName.append(')');
// If there were no modifiers, then strip the empty parenthesis
final int idx2 = itemName.toString().indexOf(" ()");
if (idx2 >= 0) {
itemName.setLength(idx2);
}
return itemName.toString();
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getSpecialProperties.
/**
* Returns special properties of an Equipment.
*
* @param aPC The PC with the Equipment
* @return special properties of an Equipment.
*/
public String getSpecialProperties(final PlayerCharacter aPC) {
final List<EquipmentModifier> modList;
EquipmentHead head = getEquipmentHeadReference(1);
if (head == null) {
modList = Collections.emptyList();
} else {
modList = head.getSafeListFor(ListKey.EQMOD);
}
EquipmentHead althead = getEquipmentHeadReference(2);
final List<EquipmentModifier> altModList;
if (althead == null) {
altModList = Collections.emptyList();
} else {
altModList = althead.getSafeListFor(ListKey.EQMOD);
}
final List<EquipmentModifier> comn = new ArrayList<>();
extractListFromCommon(comn, modList);
removeCommonFromList(altModList, comn, "SPROP: eqMod expected but not found: ");
final String common = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(comn, aPC)), ", ");
final String saList1 = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(modList, aPC)), ", ");
final String saList2 = StringUtil.join(getSpecialAbilityTimesList(getSpecialAbilityList(altModList, aPC)), ", ");
final StringBuilder sp = new StringBuilder(200);
boolean first = true;
for (SpecialProperty sprop : getSafeListFor(ListKey.SPECIAL_PROPERTIES)) {
final String text = sprop.getParsedText(aPC, this, this);
if (!"".equals(text)) {
if (!first) {
sp.append(", ");
}
first = false;
sp.append(text);
}
}
if (!common.isEmpty()) {
if (!first) {
sp.append(", ");
}
first = false;
sp.append(common);
}
if (!saList1.isEmpty()) {
if (!first) {
sp.append(", ");
}
first = false;
if (isDouble()) {
sp.append("Head1: ");
}
sp.append(saList1);
}
if (isDouble() && (!saList2.isEmpty())) {
if (!first) {
sp.append(", ");
}
sp.append("Head2: ").append(saList2);
}
return sp.toString();
}
use of pcgen.cdom.inst.EquipmentHead in project pcgen by PCGen.
the class Equipment method getDamageAdjustedForSize.
/**
* Gets the damageAdjustedForSize attribute of the Equipment object
*
* @param aSize
* The size to adjust for
* @param bPrimary
* If true get the damage for the primary head, otherwise
* get the damage for the secondary head
* @return The damageAdjustedForSize value
*/
private String getDamageAdjustedForSize(final SizeAdjustment aSize, final boolean bPrimary) {
int headnum = bPrimary ? 1 : 2;
EquipmentHead head = getEquipmentHeadReference(headnum);
if (head == null) {
return null;
}
String dam = head.get(StringKey.DAMAGE);
if (!isWeapon() || (!bPrimary && !isDouble())) {
return dam;
}
if (dam == null) {
dam = getWeaponInfo("DAMAGE", bPrimary);
}
return adjustDamage(dam, aSize);
}
Aggregations