use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method modifyCharges.
@Override
public void modifyCharges(List<EquipmentFacade> targets) {
List<Equipment> chargedEquip = new ArrayList<>();
for (EquipmentFacade equipmentFacade : targets) {
if (equipmentFacade instanceof Equipment && ((Equipment) equipmentFacade).getMaxCharges() > 0) {
chargedEquip.add((Equipment) equipmentFacade);
}
}
if (chargedEquip.isEmpty()) {
return;
}
for (Equipment equip : chargedEquip) {
int selectedCharges = getSelectedCharges(equip);
if (selectedCharges < 0) {
return;
}
equip.setRemainingCharges(selectedCharges);
purchasedEquip.modifyElement(equip);
}
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class CharacterFacadeImpl method addTempBonus.
@Override
public void addTempBonus(TempBonusFacade bonusFacade) {
if (bonusFacade == null || !(bonusFacade instanceof TempBonusFacadeImpl)) {
return;
}
TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) bonusFacade;
// Allow selection of target for bonus affecting equipment
CDOMObject originObj = tempBonus.getOriginObj();
Equipment aEq = null;
Object target = TempBonusHelper.getTempBonusTarget(originObj, theCharacter, delegate, infoFactory);
if (target == null) {
return;
}
TempBonusFacadeImpl appliedTempBonus;
if (target instanceof Equipment) {
aEq = (Equipment) target;
appliedTempBonus = TempBonusHelper.applyBonusToCharacterEquipment(aEq, originObj, theCharacter);
} else {
appliedTempBonus = TempBonusHelper.applyBonusToCharacter(originObj, theCharacter);
}
// Resolve choices and apply the bonus to the character.
if (appliedTempBonus == null) {
return;
}
appliedTempBonuses.addElement(appliedTempBonus);
refreshStatScores();
postLevellingUpdates();
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class WeaponToken method getTotalHitToken.
/**
* Get total hit token
* @param pc
* @param eq
* @param range
* @param content
* @param ammo
* @param attackNum
* @return total hit token
*/
public static String getTotalHitToken(PlayerCharacter pc, Equipment eq, int range, int content, int ammo, int attackNum) {
CharacterDisplay display = pc.getDisplay();
boolean isDouble = (eq.isDouble() && (eq.getLocation() == EquipmentLocation.EQUIPPED_TWO_HANDS));
boolean isDoubleSplit = (eq.isType("Head1") || eq.isType("Head2"));
int hitMode = HITMODE_TOTALHIT;
// First do unarmed.
if (eq.isUnarmed()) {
hitMode = HITMODE_BASEHIT;
} else // next do Double weapons
if (isDouble && !isDoubleSplit) {
hitMode = HITMODE_TWOHIT;
} else if (!isDouble && isDoubleSplit) {
hitMode = HITMODE_THHIT;
} else // eq is Primary
if (display.isPrimaryWeapon(eq) && display.hasSecondaryWeapons()) {
Equipment sEq = display.getSecondaryWeapons().iterator().next();
if (sEq == null) {
// Hmm, weird
// default to off-hand light
hitMode = HITMODE_TWPHITL;
} else if (sEq.isWeaponLightForPC(pc)) {
// offhand light
hitMode = HITMODE_TWPHITL;
} else {
// offhand heavy
hitMode = HITMODE_TWPHITH;
}
} else // eq is Secondary
if (display.isSecondaryWeapon(eq) && display.hasPrimaryWeapons()) {
if (eq.isWeaponLightForPC(pc)) {
// offhand light
hitMode = HITMODE_TWFOHL;
} else {
// offhand heavy
hitMode = HITMODE_TWFOHH;
}
} else // Just a single off-hand weapon
if (display.isSecondaryWeapon(eq) && !display.hasPrimaryWeapons()) {
hitMode = HITMODE_OHHIT;
} else // Just a single primary weapon
if (display.isPrimaryWeapon(eq) && !display.hasSecondaryWeapons()) {
if (eq.getLocation() == EquipmentLocation.EQUIPPED_BOTH) {
// both hands
hitMode = HITMODE_THHIT;
} else {
// single hand
hitMode = HITMODE_BASEHIT;
}
} else {
// probably just carried
if (eq.isWeaponTwoHanded(pc)) {
// Two Handed weapon
hitMode = HITMODE_THHIT;
} else {
// one handed weapon
hitMode = HITMODE_BASEHIT;
}
}
return getToHit(pc, eq, range, content, ammo, hitMode, attackNum);
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class WeaponToken method getToken.
/**
* @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
*/
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
//Weapon Token
aTok.nextToken();
int merge = Constants.MERGE_ALL;
int weapon = 0;
Equipment eq;
// First check to see if there is a MERGE token
String token = aTok.nextToken();
if (token.equals("MERGENONE")) {
merge = Constants.MERGE_NONE;
token = aTok.nextToken();
} else if (token.equals("MERGELOC")) {
merge = Constants.MERGE_LOCATION;
token = aTok.nextToken();
} else if (token.equals("MERGEALL")) {
merge = Constants.MERGE_ALL;
token = aTok.nextToken();
}
List<Equipment> weaponList = pc.getExpandedWeapons(merge);
if (token.equals("ALL")) {
token = aTok.nextToken();
} else if (token.equals("EQUIPPED")) {
// remove all weapons which are not equipped from list
for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
if (!it.next().isEquipped()) {
it.remove();
}
}
token = aTok.nextToken();
} else if (token.equals("NOT_EQUIPPED")) {
// remove all weapons which are equipped from list
for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
if (it.next().isEquipped()) {
it.remove();
}
}
token = aTok.nextToken();
} else if (token.equals("CARRIED")) {
// remove all weapons which are not carried from list
for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
if (it.next().numberCarried().intValue() == 0) {
it.remove();
}
}
token = aTok.nextToken();
} else if (token.equals("NOT_CARRIED")) {
// remove all weapons which are carried from list
for (Iterator<Equipment> it = weaponList.iterator(); it.hasNext(); ) {
if (it.next().numberCarried().intValue() > 0) {
it.remove();
}
}
token = aTok.nextToken();
}
weapon = getIntToken(token, 0);
if (weapon < weaponList.size()) {
eq = weaponList.get(weapon);
if (weapon == weaponList.size() - 1 && eh != null && eh.getExistsOnly()) {
eh.setNoMoreItems(true);
}
return getWeaponToken(pc, eq, aTok, tokenSource);
} else if (eh != null && eh.getExistsOnly()) {
eh.setNoMoreItems(true);
if (eh.getCheckBefore()) {
eh.setCanWrite(false);
}
}
return "";
}
use of pcgen.core.Equipment in project pcgen by PCGen.
the class WeaponToken method getAmmunitionCountToken.
/**
* Get ammunition count sub token
* @param pc
* @param eq
* @return ammunition count sub token
*/
public static int getAmmunitionCountToken(PlayerCharacter pc, Equipment eq) {
int ammoCount = 0;
String containerCapacity = eq.getContainerCapacityString().toUpperCase();
for (Equipment equip : pc.getEquipmentListInOutputOrder()) {
for (String type : equip.typeList()) {
if (containerCapacity.indexOf(type) >= 0) {
++ammoCount;
break;
}
}
}
return ammoCount;
}
Aggregations