Add proper support of attribute value limit

This fixes issue with blighted/polarized weapons getting resistances down to negative values
This commit is contained in:
DarkPhoenix
2014-11-07 12:49:34 +03:00
parent cb27efd5e1
commit 15087a290a
4 changed files with 891 additions and 866 deletions

View File

@@ -18,7 +18,7 @@
#===============================================================================
from sqlalchemy import Table, Column, Integer, Float, Unicode, ForeignKey, String, Boolean
from sqlalchemy.orm import relation, mapper, synonym, deferred
from sqlalchemy.orm import relation, mapper, synonym, deferred, remote
from sqlalchemy.ext.associationproxy import association_proxy
from eos.types import Attribute, Icon, AttributeInfo, Unit
from eos.db import gamedata_meta
@@ -31,6 +31,7 @@ attributes_table = Table("dgmattribs", gamedata_meta,
Column("attributeID", Integer, primary_key = True),
Column("attributeName", String),
Column("defaultValue", Float),
Column("maxAttributeID", Integer, ForeignKey("dgmattribs.attributeID")),
Column("description", Unicode),
Column("published", Boolean),
Column("displayName", String),

View File

@@ -21,6 +21,7 @@ from math import exp
import collections
defaultValuesCache = {}
cappingAttrKeyCache = {}
class ItemAttrShortcut(object):
def getModifiedItemAttr(self, key):
@@ -126,10 +127,29 @@ class ModifiedAttributeDict(collections.MutableMapping):
return len(keys)
def __calculateValue(self, key):
# It's possible that various attributes are capped by other attributes,
# it's defined by reference maxAttributeID
try:
cappingKey = cappingAttrKeyCache[key]
except KeyError:
from eos.db.gamedata.queries import getAttributeInfo
attrInfo = getAttributeInfo(key)
if attrInfo is None:
cappingId = cappingAttrKeyCache[key] = None
else:
cappingId = cappingAttrKeyCache[key] = attrInfo.maxAttributeID
if cappingId is None:
cappingKey = None
else:
cappingAttrInfo = getAttributeInfo(cappingId)
cappingKey = None if cappingAttrInfo is None else cappingAttrInfo.name
cappingValue = self.__calculateValue(cappingKey) if cappingKey is not None else None
# If value is forced, we don't have to calculate anything,
# just return forced value instead
force = self.__forced[key] if key in self.__forced else None
if force is not None:
if cappingValue is not None:
force = min(force, cappingValue)
return force
# Grab our values if they're there, otherwise we'll take default values
preIncrease = self.__preIncreases[key] if key in self.__preIncreases else 0
@@ -176,6 +196,10 @@ class ModifiedAttributeDict(collections.MutableMapping):
val *= 1 + (bonus - 1) * exp(- i ** 2 / 7.1289)
val += postIncrease
# Cap value if we have cap defined
if cappingValue is not None:
val = min(val, cappingValue)
return val
def getAfflictions(self, key):

File diff suppressed because it is too large Load Diff

Binary file not shown.