Gracefully handle invalid boosters in database (both itemIDs that don't exist as well as non-booster items). Implants need a little more work

This commit is contained in:
blitzmann
2015-06-30 13:51:15 -04:00
parent 646f3afd27
commit aaa5a6ae18
2 changed files with 15 additions and 7 deletions

View File

@@ -233,10 +233,14 @@ class HandledImplantBoosterList(HandledList):
self.__slotCache = {}
def append(self, implant):
if self.__slotCache.has_key(implant.slot):
raise ValueError("Implant/Booster slot already in use, remove the old one first or set replace = True")
self.__slotCache[implant.slot] = implant
HandledList.append(self, implant)
try:
if self.__slotCache.has_key(implant.slot):
raise ValueError("Implant/Booster slot already in use, remove the old one first or set replace = True")
self.__slotCache[implant.slot] = implant
HandledList.append(self, implant)
except:
# if anything goes wrong, simply remove the item
eos.db.remove(implant)
def remove(self, implant):
HandledList.remove(self, implant)

View File

@@ -46,9 +46,13 @@ class Booster(HandledItem, ItemAttrShortcut):
def __fetchItemInfo(self):
import eos.db
self.__item = eos.db.getItem(self.itemID)
self.__slot = self.__calculateSlot(self.__item)
self.build()
item = eos.db.getItem(self.itemID)
if item:
self.__item = item
self.__slot = self.__calculateSlot(self.__item)
self.build()
else:
raise ValueError("Invalid item as Booster:", self.itemID)
def iterSideEffects(self):
return self.__sideEffects.__iter__()