use of pcgen.core.bonus.BonusObj 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;
}
}
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class Equipment method getInterestingDisplayString.
/**
* Get display information for all "interesting" properties.
*
* @param aPC The PC with the Equipment
*
* @return display string of bonuses and special properties
*/
public String getInterestingDisplayString(final PlayerCharacter aPC) {
final StringBuilder s = new StringBuilder(100);
String t = getSpecialProperties(aPC);
if (t == null) {
t = "";
}
for (BonusObj aBonus : getActiveBonuses(aPC)) {
final String eqBonus = aBonus.toString();
if ((!eqBonus.isEmpty()) && !eqBonus.startsWith("EQM")) {
if (s.length() != 0) {
s.append(", ");
}
s.append(eqBonus);
}
}
// }
if (!t.isEmpty()) {
if (s.length() != 0) {
s.append('|');
}
s.append(t);
}
return s.toString();
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class AgeSet method getLSTformat.
public String getLSTformat() {
StringBuilder sb = new StringBuilder();
sb.append(index).append('|').append(name);
if (bonuses != null) {
for (BonusObj bo : bonuses) {
sb.append('\t').append(bo.getLSTformat());
}
}
if (kits != null) {
for (TransitionChoice<Kit> tc : kits) {
sb.append('\t').append(tc.getCount()).append(Constants.PIPE);
sb.append(tc.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
}
}
return sb.toString();
}
use of pcgen.core.bonus.BonusObj 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();
}
use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.
the class StatBonusFacet method getStatBonusTo.
/**
* Returns the aggregate Bonus value for the given Bonus type and given
* Bonus name which are applied by PCStat objects to the Player Character
* identified by the given CharID.
*
* @param id
* The CharID identifying the Player Character for which the
* aggregate Bonus value is to be calculated
* @param type
* The Bonus type for which the aggregate Bonus value is to be
* calculated
* @param name
* The Bonus name for which the aggregate Bonus value is to be
* calculated
* @return The aggregate Bonus value for the given Bonus type and given
* Bonus name which are applied by PCStat objects to the Player
* Character identified by the given CharID
*/
public double getStatBonusTo(CharID id, String type, String name) {
final Map<BonusObj, PCStat> map = getBonusListOfType(id, type.toUpperCase(), name.toUpperCase());
for (Iterator<Map.Entry<BonusObj, PCStat>> it = map.entrySet().iterator(); it.hasNext(); ) {
Entry<BonusObj, PCStat> me = it.next();
BonusObj bo = me.getKey();
if (!prerequisiteFacet.qualifies(id, bo, me.getValue())) {
it.remove();
}
}
return bonusCheckingFacet.calcBonus(id, map);
}
Aggregations