use of pcgen.core.Equipment in project pcgen by PCGen.
the class WeaponToken method getEqBonus.
private static int getEqBonus(PlayerCharacter pc, Equipment eq, int content, int ammo) {
int eqbonus = eq.getBonusToDamage(pc, true);
//Ammunition & Contents Modifier
Equipment containedEq = null;
if (content > -1) {
if (content < eq.getContainedEquipmentCount()) {
containedEq = eq.getContainedEquipment(content);
eqbonus += containedEq.getBonusToDamage(pc, true);
}
}
Equipment ammoUser = getAmmoUser(pc, eq, ammo);
if (ammoUser != null) {
eqbonus += ammoUser.getBonusToDamage(pc, true);
}
// If not using ammo stacking, correct for stacked enhancement bonus
if (!Globals.checkRule(RuleConstants.AMMOSTACKSWITHWEAPON)) {
eqbonus += calcAmmoEqCorrection("WEAPON.DAMAGE.ENHANCEMENT", eq, containedEq, ammoUser);
}
return eqbonus;
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class WeaponToken method getAmmoUser.
private static Equipment getAmmoUser(PlayerCharacter pc, Equipment eq, int ammo) {
int ammoCount = 0;
if (ammo < 0) {
return null;
}
String containerCapacity = eq.getContainerCapacityString();
for (Equipment equip : pc.getEquipmentListInOutputOrder()) {
for (String type : equip.typeList()) {
if (containerCapacity.indexOf(type) >= 0) {
++ammoCount;
break;
}
}
if (ammoCount == (ammo + 1)) {
return equip;
}
}
return null;
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class PCGIOHandler method resolveDuplicateEquipmentSets.
/**
* Check all equipment sets to ensure there are no duplicate paths. Where a
* duplicate path is found, report it and try to move one non-container to
* a new path.
*
* @param currentPC The character being loaded.
*/
private void resolveDuplicateEquipmentSets(PlayerCharacter currentPC) {
boolean anyMoved = false;
Iterable<EquipSet> equipSetList = new ArrayList<>(currentPC.getDisplay().getEquipSet());
Map<String, EquipSet> idMap = new HashMap<>();
for (final EquipSet es : equipSetList) {
String idPath = es.getIdPath();
if (idMap.containsKey(idPath)) {
EquipSet existingEs = idMap.get(idPath);
EquipSet esToBeMoved = chooseItemToBeMoved(existingEs, es);
if (esToBeMoved == null) {
warnings.add(String.format("Found two equipment items equipped to the " + "path %s. Items were %s and %s.", idPath, es.getItem(), existingEs.getItem()));
continue;
}
// change the item's location
currentPC.moveEquipSetToNewPath(esToBeMoved);
EquipSet esStaying = esToBeMoved == es ? existingEs : es;
// erroneously held to the item remaining in place
for (int j = esToBeMoved.getItem().getContainedEquipmentCount() - 1; j >= 0; j--) {
Equipment containedItem = esToBeMoved.getItem().getContainedEquipment(j);
esToBeMoved.getItem().removeChild(currentPC, containedItem);
esStaying.getItem().insertChild(currentPC, containedItem);
}
Logging.log(Logging.WARNING, String.format("Moved item %s from path %s to %s as it " + "clashed with %s", esToBeMoved.getItem(), idPath, esToBeMoved.getIdPath(), esToBeMoved == es ? existingEs.getItem() : es.getItem()));
idMap.put(es.getIdPath(), es);
idMap.put(existingEs.getIdPath(), existingEs);
anyMoved = true;
} else {
idMap.put(idPath, es);
}
}
if (anyMoved) {
warnings.add("Some equipment was moved as it was incorrectly stored." + " Please see the log for details.");
}
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class AutoEquipmentFacet method dataAdded.
/**
* Adds Equipment granted to a Player Character by AUTO:EQUIP.
*
* Triggered when one of the Facets to which AutoEquipmentFacet listens
* fires a DataFacetChangeEvent to indicate a CDOMObject was added to a
* Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
List<QualifiedObject<CDOMReference<Equipment>>> list = cdo.getSafeListFor(ListKey.EQUIPMENT);
if (list != null) {
addAll(dfce.getCharID(), list, cdo);
}
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class PreEquippedTester method passesPreEquipHandleTokens.
/**
* Process the tokens and return the number that is not passed.
*
* @param prereq
* @param character The pc to use.
* @param equippedType The equipped type to look for (e.g. Equipment.EQUIPPED_TWO_HANDS)
*
* @return the number that did not pass
* @throws PrerequisiteException
*/
public int passesPreEquipHandleTokens(final Prerequisite prereq, final PlayerCharacter character, final EquipmentLocation equippedType) throws PrerequisiteException {
// TODO refactor this code with PreEquipTester
boolean isEquipped = false;
if (character.hasEquipment()) {
String aString = prereq.getKey();
for (Equipment eq : character.getDisplay().getEquippedEquipmentSet()) {
//
if (eq.getLocation() != equippedType) {
continue;
}
if (aString.startsWith("WIELDCATEGORY=") || aString.startsWith("WIELDCATEGORY.")) {
final WieldCategory wCat = eq.getEffectiveWieldCategory(character);
if ((wCat != null) && wCat.getKeyName().equalsIgnoreCase(aString.substring(14))) {
isEquipped = true;
break;
}
} else if (//$NON-NLS-1$ //$NON-NLS-2$
aString.startsWith("TYPE=") || aString.startsWith("TYPE.")) {
isEquipped = eq.isType(aString);
break;
} else //not a TYPE string
{
String eqName;
if (//$NON-NLS-1$ //$NON-NLS-2$
aString.startsWith("BASEITEM=")) {
eqName = eq.getBaseItemName();
aString = aString.substring(aString.indexOf(Constants.EQUALS) + 1);
} else {
eqName = eq.getName();
}
if (aString.indexOf('%') >= 0) {
//handle wildcards (always assume they
// end the line)
final int percentPos = aString.indexOf('%');
if (eqName.regionMatches(true, 0, aString, 0, percentPos)) {
isEquipped = true;
break;
}
} else if (eqName.equalsIgnoreCase(aString)) {
//just a straight String compare
isEquipped = true;
break;
}
}
}
}
final PrerequisiteOperator operator = prereq.getOperator();
int runningTotal;
if (operator.equals(PrerequisiteOperator.EQ) || operator.equals(PrerequisiteOperator.GTEQ)) {
runningTotal = isEquipped ? 1 : 0;
} else if (operator.equals(PrerequisiteOperator.NEQ) || operator.equals(PrerequisiteOperator.LT)) {
runningTotal = isEquipped ? 0 : 1;
} else {
throw new PrerequisiteException(LanguageBundle.getFormattedString("PreEquipped.error.invalid_comparison", //$NON-NLS-1$
prereq.toString()));
}
return countedTotal(prereq, runningTotal);
}
Aggregations