use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.
the class GlobalDrTest method containsExpected.
@Override
protected boolean containsExpected() {
DamageReduction dr = drFacet.getSet(id).iterator().next();
boolean bypassMatches = dr.getBypass().equals("Light");
boolean reductionMatches = dr.getReduction().equals(FormulaFactory.getFormulaFor("5"));
return bypassMatches && reductionMatches;
}
use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.
the class DamageReductionFacet method getDRMap.
private CaseInsensitiveMap<Integer> getDRMap(CharID id, Map<DamageReduction, Set<Object>> componentMap) {
CaseInsensitiveMap<Integer> andMap = new CaseInsensitiveMap<>();
if (componentMap == null || componentMap.isEmpty()) {
return andMap;
}
CaseInsensitiveMap<Integer> orMap = new CaseInsensitiveMap<>();
for (Map.Entry<DamageReduction, Set<Object>> me : componentMap.entrySet()) {
DamageReduction dr = me.getKey();
for (Object source : me.getValue()) {
if (prerequisiteFacet.qualifies(id, dr, source)) {
String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
int rawDrValue = formulaResolvingFacet.resolve(id, dr.getReduction(), sourceString).intValue();
String bypass = dr.getBypass();
if (OR_PATTERN.matcher(bypass).find()) {
Integer current = orMap.get(bypass);
if ((current == null) || (current.intValue() < rawDrValue)) {
orMap.put(dr.getBypass(), rawDrValue);
}
} else {
/*
* TODO Shouldn't this expansion be done in the DR
* token? (since it's static?)
*/
String[] splits = AND_PATTERN.split(bypass);
if (splits.length == 1) {
Integer current = andMap.get(dr.getBypass());
if ((current == null) || (current.intValue() < rawDrValue)) {
andMap.put(dr.getBypass(), rawDrValue);
}
} else {
for (String split : splits) {
Integer current = andMap.get(split);
if ((current == null) || (current.intValue() < rawDrValue)) {
andMap.put(split, rawDrValue);
}
}
}
}
}
}
}
// e.g. 10/magic or good or lawful + 5/good = 10/good; 5/magic or good
for (Map.Entry<Object, Integer> me : orMap.entrySet()) {
String origBypass = me.getKey().toString();
Integer reduction = me.getValue();
String[] orValues = OR_PATTERN.split(origBypass);
boolean shouldAdd = true;
for (String orValue : orValues) {
// See if we already have a value for this type from the 'and'
// processing.
Integer andDR = andMap.get(orValue);
if (andDR != null && andDR >= reduction) {
shouldAdd = false;
break;
}
}
if (shouldAdd) {
andMap.put(origBypass, reduction);
}
}
return andMap;
}
use of pcgen.cdom.content.DamageReduction in project pcgen by PCGen.
the class TemplateModifier method modifierString.
/**
* Generate a string that represents the changes this Template will apply.
*
* @param aPC
* the Pc we'd like the string generated with reference to
*
* @return a string explaining the Template
*/
public static String modifierString(PCTemplate pct, PlayerCharacter aPC) {
// More likely to be
StringBuilder mods = new StringBuilder(50);
// true than 16
// (the default)
CharID id = aPC.getCharID();
for (PCStat stat : statFacet.getSet(id)) {
if (NonAbilityDisplay.isNonAbilityForObject(stat, pct)) {
mods.append(stat.getKeyName()).append(":nonability ");
} else {
int statMod = BonusCalc.getStatMod(pct, stat, aPC);
if (statMod != 0) {
mods.append(stat.getKeyName()).append(':').append(statMod).append(' ');
}
}
}
Map<DamageReduction, Set<Object>> drMap = new IdentityHashMap<>();
CharacterDisplay display = aPC.getDisplay();
int totalLevels = display.getTotalLevels();
int totalHitDice = display.totalHitDice();
List<PCTemplate> templList = new ArrayList<>();
templList.add(pct);
templList.addAll(pct.getConditionalTemplates(totalLevels, totalHitDice));
for (PCTemplate subt : templList) {
List<DamageReduction> tList = subt.getListFor(ListKey.DAMAGE_REDUCTION);
if (tList != null) {
for (DamageReduction dr : tList) {
Set<Object> set = drMap.get(dr);
if (set == null) {
set = new HashSet<>();
drMap.put(dr, set);
}
set.add(pct);
}
}
}
if (!drMap.isEmpty()) {
mods.append("DR:").append(drFacet.getDRString(id, drMap));
}
if (!aPC.hasControl(CControl.ACVARTOTAL)) {
int nat = (int) BonusCalc.charBonusTo(pct, "COMBAT", "AC", aPC);
if (nat != 0) {
mods.append("AC BONUS:").append(nat);
}
}
float cr = pct.getCR(totalLevels, totalHitDice);
if (cr != 0) {
mods.append("CR:").append(cr).append(' ');
}
if (display.getTemplateSR(pct, totalLevels, totalHitDice) != 0) {
mods.append("SR:").append(display.getTemplateSR(pct, totalLevels, totalHitDice)).append(' ');
}
return mods.toString();
}
Aggregations