Search in sources :

Example 1 with BonusObj

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;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 2 with BonusObj

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

Example 3 with BonusObj

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;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) IdentityHashMap(java.util.IdentityHashMap) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) BonusContainer(pcgen.cdom.base.BonusContainer)

Example 4 with BonusObj

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

Example 5 with BonusObj

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;
}
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

BonusObj (pcgen.core.bonus.BonusObj)126 LoadContext (pcgen.rules.context.LoadContext)48 PlayerCharacter (pcgen.core.PlayerCharacter)29 ArrayList (java.util.ArrayList)22 CDOMObject (pcgen.cdom.base.CDOMObject)18 PCClass (pcgen.core.PCClass)14 Prerequisite (pcgen.core.prereq.Prerequisite)13 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)13 EquipSet (pcgen.core.character.EquipSet)11 IdentityHashMap (java.util.IdentityHashMap)10 Map (java.util.Map)10 TreeSet (java.util.TreeSet)10 Ability (pcgen.core.Ability)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)8 Equipment (pcgen.core.Equipment)8 HashMap (java.util.HashMap)7 Race (pcgen.core.Race)7 StringTokenizer (java.util.StringTokenizer)6 CNAbility (pcgen.cdom.content.CNAbility)6