Search in sources :

Example 11 with DamageReduction

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;
}
Also used : DamageReduction(pcgen.cdom.content.DamageReduction)

Example 12 with DamageReduction

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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) DamageReduction(pcgen.cdom.content.DamageReduction) CaseInsensitiveMap(pcgen.base.util.CaseInsensitiveMap) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map) CaseInsensitiveMap(pcgen.base.util.CaseInsensitiveMap)

Example 13 with DamageReduction

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();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) CharID(pcgen.cdom.enumeration.CharID) DamageReduction(pcgen.cdom.content.DamageReduction) PCStat(pcgen.core.PCStat) PCTemplate(pcgen.core.PCTemplate)

Aggregations

DamageReduction (pcgen.cdom.content.DamageReduction)13 CDOMObject (pcgen.cdom.base.CDOMObject)4 Set (java.util.Set)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 TreeSet (java.util.TreeSet)2 CharID (pcgen.cdom.enumeration.CharID)2 PCTemplate (pcgen.core.PCTemplate)2 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Formula (pcgen.base.formula.Formula)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 Ungranted (pcgen.cdom.base.Ungranted)1 PCStat (pcgen.core.PCStat)1 Race (pcgen.core.Race)1 BonusObj (pcgen.core.bonus.BonusObj)1 Prerequisite (pcgen.core.prereq.Prerequisite)1