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 = {} self.__slotCache = {}
def append(self, implant): def append(self, implant):
if self.__slotCache.has_key(implant.slot): try:
raise ValueError("Implant/Booster slot already in use, remove the old one first or set replace = True") if self.__slotCache.has_key(implant.slot):
self.__slotCache[implant.slot] = implant raise ValueError("Implant/Booster slot already in use, remove the old one first or set replace = True")
HandledList.append(self, implant) 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): def remove(self, implant):
HandledList.remove(self, implant) HandledList.remove(self, implant)

View File

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