|
29 | 29 |
|
30 | 30 |
|
31 | 31 | defaultValuesCache = {} |
32 | | -cappingAttrKeyCache = {} |
| 32 | +minLimitAttrKeyCache = {} |
| 33 | +maxLimitAttrKeyCache = {} |
33 | 34 | resistanceCache = {} |
34 | 35 |
|
35 | 36 |
|
@@ -307,34 +308,57 @@ def __len__(self): |
307 | 308 |
|
308 | 309 | def __calculateValue(self, key, extraMultipliers=None, preIncAdj=None, multAdj=None, postIncAdj=None, ignorePenMult=None): |
309 | 310 | # It's possible that various attributes are capped by other attributes, |
310 | | - # it's defined by reference maxAttributeID |
| 311 | + # it's defined by reference min/maxAttributeID |
| 312 | + # Min |
311 | 313 | try: |
312 | | - cappingKey = cappingAttrKeyCache[key] |
| 314 | + minLimitKey = minLimitAttrKeyCache[key] |
313 | 315 | except KeyError: |
314 | 316 | attrInfo = getAttributeInfo(key) |
315 | 317 | if attrInfo is None: |
316 | | - cappingId = cappingAttrKeyCache[key] = None |
| 318 | + cappingId = minLimitAttrKeyCache[key] = None |
| 319 | + else: |
| 320 | + cappingId = attrInfo.minAttributeID |
| 321 | + if cappingId is None: |
| 322 | + minLimitKey = None |
| 323 | + else: |
| 324 | + cappingAttrInfo = getAttributeInfo(cappingId) |
| 325 | + minLimitKey = None if cappingAttrInfo is None else cappingAttrInfo.name |
| 326 | + minLimitAttrKeyCache[key] = minLimitKey |
| 327 | + if minLimitKey: |
| 328 | + minLimitValue = self[minLimitKey] |
| 329 | + minLimitValue = minLimitValue.value if hasattr(minLimitValue, "value") else minLimitValue |
| 330 | + else: |
| 331 | + minLimitValue = None |
| 332 | + # Max |
| 333 | + try: |
| 334 | + maxLimitKey = maxLimitAttrKeyCache[key] |
| 335 | + except KeyError: |
| 336 | + attrInfo = getAttributeInfo(key) |
| 337 | + if attrInfo is None: |
| 338 | + cappingId = maxLimitAttrKeyCache[key] = None |
317 | 339 | else: |
318 | 340 | cappingId = attrInfo.maxAttributeID |
319 | 341 | if cappingId is None: |
320 | | - cappingKey = None |
| 342 | + maxLimitKey = None |
321 | 343 | else: |
322 | 344 | cappingAttrInfo = getAttributeInfo(cappingId) |
323 | | - cappingKey = None if cappingAttrInfo is None else cappingAttrInfo.name |
324 | | - cappingAttrKeyCache[key] = cappingKey |
| 345 | + maxLimitKey = None if cappingAttrInfo is None else cappingAttrInfo.name |
| 346 | + maxLimitAttrKeyCache[key] = maxLimitKey |
325 | 347 |
|
326 | | - if cappingKey: |
327 | | - cappingValue = self[cappingKey] |
328 | | - cappingValue = cappingValue.value if hasattr(cappingValue, "value") else cappingValue |
| 348 | + if maxLimitKey: |
| 349 | + maxLimitValue = self[maxLimitKey] |
| 350 | + maxLimitValue = maxLimitValue.value if hasattr(maxLimitValue, "value") else maxLimitValue |
329 | 351 | else: |
330 | | - cappingValue = None |
| 352 | + maxLimitValue = None |
331 | 353 |
|
332 | 354 | # If value is forced, we don't have to calculate anything, |
333 | 355 | # just return forced value instead |
334 | 356 | force = self.__forced[key] if key in self.__forced else None |
335 | 357 | if force is not None: |
336 | | - if cappingValue is not None: |
337 | | - force = min(force, cappingValue) |
| 358 | + if minLimitValue is not None: |
| 359 | + force = max(force, minLimitValue) |
| 360 | + if maxLimitValue is not None: |
| 361 | + force = min(force, maxLimitValue) |
338 | 362 | if key in ("cpu", "power", "cpuOutput", "powerOutput"): |
339 | 363 | force = round(force, 2) |
340 | 364 | return force |
@@ -409,8 +433,10 @@ def __calculateValue(self, key, extraMultipliers=None, preIncAdj=None, multAdj=N |
409 | 433 | val += postIncAdj |
410 | 434 |
|
411 | 435 | # Cap value if we have cap defined |
412 | | - if cappingValue is not None: |
413 | | - val = min(val, cappingValue) |
| 436 | + if minLimitValue is not None: |
| 437 | + val = max(val, minLimitValue) |
| 438 | + if maxLimitValue is not None: |
| 439 | + val = min(val, maxLimitValue) |
414 | 440 | if key in ("cpu", "power", "cpuOutput", "powerOutput"): |
415 | 441 | val = round(val, 2) |
416 | 442 | return val |
|
0 commit comments