Make sure getModifiedItemAttr always returns an int, unless otherwise wanting None

In py2, you could compare None to an int and it would always be less than. Unfortunately in py3, this is no longer the case. Returning getModifiedItemAttr as 0 allows us to not do a huge refactor.
This commit is contained in:
blitzmann
2017-11-04 18:20:00 -04:00
parent 56f34873a6
commit ce3b94696a
5 changed files with 9 additions and 8 deletions

View File

@@ -28,23 +28,23 @@ cappingAttrKeyCache = {}
class ItemAttrShortcut(object):
def getModifiedItemAttr(self, key, default=None):
def getModifiedItemAttr(self, key, default=0):
return_value = self.itemModifiedAttributes.get(key)
if return_value is None and default is not None:
return_value = default
return return_value
return return_value if default is not None else None
class ChargeAttrShortcut(object):
def getModifiedChargeAttr(self, key, default=None):
def getModifiedChargeAttr(self, key, default=0):
return_value = self.chargeModifiedAttributes.get(key)
if return_value is None and default is not None:
return_value = default
return return_value
return return_value if default is not None else None
class ModifiedAttributeDict(collections.MutableMapping):

View File

@@ -385,7 +385,7 @@ class Skill(HandledItem):
if key in self.item.attributes:
return self.item.attributes[key].value
else:
return None
return 0
def calculateModifiedAttributes(self, fit, runTime):
if self.__suppressed: # or not self.learned - removed for GH issue 101

View File

@@ -73,7 +73,8 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
self.__itemModifiedAttributes.overrides = self.__item.overrides
self.__chargeModifiedAttributes = ModifiedAttributeDict()
chargeID = self.getModifiedItemAttr("entityMissileTypeID")
# pheonix todo: check the attribute itself, not the modified. this will always return 0 now.
chargeID = self.getModifiedItemAttr("entityMissileTypeID", None)
if chargeID is not None:
charge = eos.db.getItem(int(chargeID))
self.__charge = charge

View File

@@ -213,7 +213,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
armorRep = self.getModifiedItemAttr("armorDamageAmount") or 0
shieldRep = self.getModifiedItemAttr("shieldBonus") or 0
if not cycles or (not armorRep and not shieldRep):
return None
return 0
hp = round((armorRep + shieldRep) * cycles)
return hp

View File

@@ -255,7 +255,7 @@ class Fit(object):
Projected is a recursion flag that is set to reduce recursions into projected fits
Basic is a flag to simply return the fit without any other processing
"""
pyfalog.debug("Getting fit for fit ID: {0}", fitID)
# pyfalog.debug("Getting fit for fit ID: {0}", fitID)
if fitID is None:
return None
fit = eos.db.getFit(fitID)