use of pcgen.core.bonus.util.MissingObject 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