use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManager method calcBonusesWithCost.
public double calcBonusesWithCost(List<BonusObj> list) {
double totalBonus = 0;
for (BonusObj aBonus : list) {
final CDOMObject anObj = (CDOMObject) getSourceObject(aBonus);
if (anObj == null) {
continue;
}
double iBonus = 0;
if (aBonus.qualifies(pc, anObj)) {
iBonus = aBonus.resolve(pc, anObj.getQualifiedKey()).doubleValue();
}
int k;
if (ChooseActivation.hasNewChooseToken(anObj)) {
k = 0;
for (String aString : pc.getConsolidatedAssociationList(anObj)) {
if (aString.equalsIgnoreCase(aBonus.getBonusInfo())) {
++k;
}
}
} else {
k = 1;
}
if ((k == 0) && !CoreUtility.doublesEqual(iBonus, 0)) {
totalBonus += iBonus;
} else {
totalBonus += (iBonus * k);
}
}
return totalBonus;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManager method getNamedTempBonusDescList.
public List<String> getNamedTempBonusDescList() {
final List<String> aList = new ArrayList<>();
Map<BonusObj, TempBonusInfo> filteredTempBonusList = getFilteredTempBonusList();
for (Map.Entry<BonusObj, TempBonusInfo> me : filteredTempBonusList.entrySet()) {
BonusObj aBonus = me.getKey();
if (aBonus == null) {
continue;
}
if (!pc.isApplied(aBonus)) {
continue;
}
final CDOMObject aCreator = (CDOMObject) me.getValue().source;
if (aCreator == null) {
continue;
}
String aDesc = aCreator.getSafe(StringKey.DESCRIPTION);
if (!aList.contains(aDesc)) {
aList.add(aDesc);
}
}
return aList;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManager method getAllActiveBonuses.
private Map<BonusObj, Object> getAllActiveBonuses() {
Map<BonusObj, Object> ret = new IdentityHashMap<>();
for (final BonusContainer pobj : pc.getBonusContainerList()) {
// the equipment they belong to.
if (pobj != null && !(pobj instanceof EquipmentModifier)) {
boolean use = true;
if (pobj instanceof PCClass) {
// Class bonuses are only included if the level is greater
// than 0
// This is because 0 levels of a class can be added to
// access spell casting etc
use = pc.getLevel(((PCClass) pobj)) > 0;
}
if (use) {
pobj.activateBonuses(pc);
List<BonusObj> abs = pobj.getActiveBonuses(pc);
for (BonusObj bo : abs) {
ret.put(bo, pobj);
}
}
}
}
if (pc.getUseTempMods()) {
ret.putAll(getTempBonuses());
}
return ret;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManager method getNamedTempBonusList.
public List<String> getNamedTempBonusList() {
final List<String> aList = new ArrayList<>();
Map<BonusObj, TempBonusInfo> filteredTempBonusList = getFilteredTempBonusList();
for (Map.Entry<BonusObj, TempBonusInfo> me : filteredTempBonusList.entrySet()) {
BonusObj aBonus = me.getKey();
if (aBonus == null) {
continue;
}
if (!pc.isApplied(aBonus)) {
continue;
}
final CDOMObject aCreator = (CDOMObject) me.getValue().source;
if (aCreator == null) {
continue;
}
final String aName = aCreator.getKeyName();
if (!aList.contains(aName)) {
aList.add(aName);
}
}
return aList;
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class BonusManager method getPartialStatBonusFor.
public int getPartialStatBonusFor(PCStat stat, boolean useTemp, boolean useEquip) {
String statAbbr = stat.getKeyName();
final String prefix = "STAT." + statAbbr;
Map<String, String> bonusMap = new HashMap<>();
Map<String, String> nonStackMap = new ConcurrentHashMap<>();
Map<String, String> stackMap = new ConcurrentHashMap<>();
for (BonusObj bonus : getActiveBonusList()) {
if (pc.isApplied(bonus) && bonus.getBonusName().equals("STAT")) {
boolean found = false;
Object co = getSourceObject(bonus);
for (Object element : bonus.getBonusInfoList()) {
if (element instanceof PCStat && element.equals(stat)) {
found = true;
break;
}
// parisng.
if (element instanceof MissingObject) {
String name = ((MissingObject) element).getObjectName();
if (("%LIST".equals(name) || "LIST".equals(name)) && co instanceof CDOMObject) {
CDOMObject creator = (CDOMObject) co;
for (String assoc : pc.getConsolidatedAssociationList(creator)) {
//TODO Case sensitivity?
if (assoc.contains(statAbbr)) {
found = true;
break;
}
}
}
}
}
if (!found) {
continue;
}
// The bonus has been applied to the target stat
// Should it be included?
boolean addIt = false;
if (co instanceof Equipment || co instanceof EquipmentModifier) {
addIt = useEquip;
} else if (co instanceof Ability) {
List<String> types = ((Ability) co).getTypes();
if (types.contains("Equipment")) {
addIt = useEquip;
} else {
addIt = true;
}
} else if (tempBonusBySource.containsKey(bonus)) {
addIt = useTemp;
} else {
addIt = true;
}
if (addIt) {
// bonuses with the stacking rules applied.
for (BonusPair bp : getStringListFromBonus(bonus)) {
if (bp.fullyQualifiedBonusType.startsWith(prefix)) {
setActiveBonusStack(bp.resolve(pc).doubleValue(), bp.fullyQualifiedBonusType, nonStackMap, stackMap);
totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, bonusMap);
}
}
}
}
}
// Sum the included bonuses to the stat to get our result.
int total = 0;
for (String bKey : bonusMap.keySet()) {
total += Float.parseFloat(bonusMap.get(bKey));
}
return total;
}
Aggregations