Search in sources :

Example 56 with CDOMObject

use of pcgen.cdom.base.CDOMObject 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 57 with CDOMObject

use of pcgen.cdom.base.CDOMObject 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 58 with CDOMObject

use of pcgen.cdom.base.CDOMObject 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)

Example 59 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class BonusManager method buildActiveBonusMap.

/**
	 * Build the bonus HashMap from all active BonusObj's
	 */
void buildActiveBonusMap() {
    activeBonusMap = new ConcurrentHashMap<>();
    cachedActiveBonusSumsMap = new ConcurrentHashMap<>();
    Map<String, String> nonStackMap = new ConcurrentHashMap<>();
    Map<String, String> stackMap = new ConcurrentHashMap<>();
    Set<BonusObj> processedBonuses = new WrappedMapSet<>(IdentityHashMap.class);
    //Logging.log(Logging.INFO, "=== Start bonus processing.");
    //
    // We do a first pass of just the "static" bonuses
    // as they require less computation and no recursion
    List<BonusObj> bonusListCopy = new ArrayList<>();
    bonusListCopy.addAll(getActiveBonusList());
    for (BonusObj bonus : bonusListCopy) {
        if (!bonus.isValueStatic()) {
            continue;
        }
        final Object source = getSourceObject(bonus);
        if (source == null) {
            if (Logging.isDebugMode()) {
                Logging.debugPrint("BONUS: " + bonus + " ignored due to no creator");
            }
            continue;
        }
        // Keep track of which bonuses have been calculated
        //Logging.log(Logging.INFO, "Processing bonus " + bonus + " - static.");
        processedBonuses.add(bonus);
        for (BonusPair bp : getStringListFromBonus(bonus)) {
            final double iBonus = bp.resolve(pc).doubleValue();
            setActiveBonusStack(iBonus, bp.fullyQualifiedBonusType, nonStackMap, stackMap);
            totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, activeBonusMap);
            if (Logging.isDebugMode()) {
                String id;
                if (source instanceof CDOMObject) {
                    id = ((CDOMObject) source).getDisplayName();
                } else {
                    id = source.toString();
                }
                Logging.debugPrint("BONUS: " + id + " : " + iBonus + " : " + bp.fullyQualifiedBonusType);
            }
        }
    }
    //
    // Now we do all the BonusObj's that require calculations
    bonusListCopy = new ArrayList<>();
    bonusListCopy.addAll(getActiveBonusList());
    for (BonusObj bonus : getActiveBonusList()) {
        if (processedBonuses.contains(bonus)) {
            continue;
        }
        final CDOMObject anObj = (CDOMObject) getSourceObject(bonus);
        if (anObj == null) {
            continue;
        }
        try {
            processBonus(bonus, new WrappedMapSet<>(IdentityHashMap.class), processedBonuses, nonStackMap, stackMap);
        } catch (Exception e) {
            Logging.errorPrint(e.getLocalizedMessage(), e);
            continue;
        }
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) BonusPair(pcgen.core.bonus.BonusPair) CDOMObject(pcgen.cdom.base.CDOMObject) WrappedMapSet(pcgen.base.util.WrappedMapSet) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 60 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class Gui2InfoFactory method getHTMLInfo.

@Override
public String getHTMLInfo(TempBonusFacade tempBonusFacade) {
    if (tempBonusFacade == null) {
        return EMPTY_STRING;
    }
    if (!(tempBonusFacade instanceof TempBonusFacadeImpl)) {
        final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
        infoText.appendTitleElement(tempBonusFacade.toString());
        return infoText.toString();
    }
    TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
    CDOMObject originObj = tempBonus.getOriginObj();
    final HtmlInfoBuilder infoText;
    if (originObj instanceof Equipment) {
        infoText = getEquipmentHtmlInfo((Equipment) originObj);
    } else {
        infoText = new HtmlInfoBuilder();
        infoText.appendTitleElement(OutputNameFormatting.piString(originObj, false));
        //$NON-NLS-1$ //$NON-NLS-2$
        infoText.append(" (").append(tempBonus.getOriginType()).append(")");
    }
    if (tempBonus.getTarget() != null) {
        String targetName = charDisplay.getName();
        if (tempBonus.getTarget() instanceof CDOMObject) {
            targetName = ((CDOMObject) tempBonus.getTarget()).getKeyName();
        }
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_itmInfoLabelTextTarget", targetName);
        StringBuilder bonusValues = new StringBuilder(100);
        Map<BonusObj, TempBonusInfo> bonusMap = pc.getTempBonusMap(originObj.getKeyName(), targetName);
        boolean first = true;
        List<BonusObj> bonusList = new ArrayList<>(bonusMap.keySet());
        bonusList.sort(new BonusComparator());
        for (BonusObj bonusObj : bonusList) {
            if (!first) {
                //$NON-NLS-1$
                bonusValues.append(", ");
            }
            first = false;
            //$NON-NLS-1$
            String adj = ADJ_FMT.format(bonusObj.resolve(pc, ""));
            //$NON-NLS-1$
            bonusValues.append(adj + " " + bonusObj.getDescription());
        }
        if (bonusValues.length() > 0) {
            infoText.appendLineBreak();
            infoText.appendI18nElement(//$NON-NLS-1$
            "in_itmInfoLabelTextEffect", bonusValues.toString());
        }
    }
    if (originObj instanceof Spell) {
        Spell aSpell = (Spell) originObj;
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellDuration", aSpell.getListAsString(ListKey.DURATION));
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellRange", aSpell.getListAsString(ListKey.RANGE));
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellTarget", aSpell.getSafe(StringKey.TARGET_AREA));
    }
    String aString = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
    if (StringUtils.isEmpty(aString) && originObj instanceof Spell) {
        Spell sp = (Spell) originObj;
        aString = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
    } else if (StringUtils.isEmpty(aString) && originObj instanceof Ability) {
        Ability ab = (Ability) originObj;
        List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
        aString = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
    }
    if (!aString.isEmpty()) {
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_itmInfoLabelTextDesc", aString);
    }
    aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, originObj.getPrerequisiteList(), false);
    if (!aString.isEmpty()) {
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_requirements", aString);
    }
    infoText.appendLineBreak();
    infoText.appendI18nElement(//$NON-NLS-1$
    "in_itmInfoLabelTextSource", SourceFormat.getFormattedString(originObj, Globals.getSourceDisplay(), true));
    return infoText.toString();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9