Search in sources :

Example 1 with MissingObject

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;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BonusPair(pcgen.core.bonus.BonusPair) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MissingObject(pcgen.core.bonus.util.MissingObject)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 BonusObj (pcgen.core.bonus.BonusObj)1 BonusPair (pcgen.core.bonus.BonusPair)1 MissingObject (pcgen.core.bonus.util.MissingObject)1