calcBonus adds together all the bonuses for aType of aName. @param po @param bString Either the entire BONUS:COMBAT|AC|2 string or part of a %LIST or %VAR bonus section @param aType Such as "COMBAT" @param aName Such as "AC" @param aTypePlusName "COMBAT.AC." @param obj
(PObject po, final String bString, final String aType, final String aName, String aTypePlusName, final Object obj, final int iTimes, final BonusObj aBonusObj, final PlayerCharacter aPC)
| 173 | * @return the value of the bonus |
| 174 | */ |
| 175 | private static double calcBonus(PObject po, final String bString, final String aType, final String aName, |
| 176 | String aTypePlusName, final Object obj, final int iTimes, final BonusObj aBonusObj, final PlayerCharacter aPC) |
| 177 | { |
| 178 | final StringTokenizer aTok = new StringTokenizer(bString, "|"); |
| 179 | |
| 180 | if (aTok.countTokens() < 3) |
| 181 | { |
| 182 | Logging.errorPrint("Badly formed BONUS:" + bString); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | String aString = aTok.nextToken(); |
| 188 | |
| 189 | if (!aString.equalsIgnoreCase(aType) || aString.endsWith("%LIST") || aName.equals("ALL")) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | final String aList = aTok.nextToken(); |
| 195 | |
| 196 | if (!aList.equals("LIST") && !aList.equals("ALL") && (!aList.toUpperCase().contains(aName.toUpperCase()))) |
| 197 | { |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | if (aList.equals("ALL") && ((aName.contains("STAT=")) || (aName.contains("TYPE=")) || (aName.contains("LIST")) |
| 202 | || (aName.contains("VAR")))) |
| 203 | { |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | if (aTok.hasMoreTokens()) |
| 208 | { |
| 209 | aString = aTok.nextToken(); |
| 210 | } |
| 211 | |
| 212 | double iBonus = 0; |
| 213 | |
| 214 | if (obj instanceof PlayerCharacter) |
| 215 | { |
| 216 | iBonus = ((PlayerCharacter) obj).getVariableValue(aString, "").doubleValue(); |
| 217 | } |
| 218 | else if (obj instanceof Equipment) |
| 219 | { |
| 220 | iBonus = ((Equipment) obj).getVariableValue(aString, "", aPC).doubleValue(); |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | try |
| 225 | { |
| 226 | iBonus = Float.parseFloat(aString); |
| 227 | } |
| 228 | catch (NumberFormatException e) |
| 229 | { |
| 230 | //Should this be ignored? |
| 231 | Logging.errorPrint("calcBonus NumberFormatException in BONUS: " + aString, e); |
| 232 | } |
no test coverage detected