Handle invalid cargo. Noticed that cargo nor drones are removed from the database with these methods. Not sure why - projected drones and modules are correctly removed in similar ways
This commit is contained in:
@@ -167,13 +167,11 @@ class HandledDroneList(HandledList):
|
||||
HandledList.append(self, drone)
|
||||
|
||||
if drone.isInvalid:
|
||||
# @todo figure out why this DOES NOT remove drone from database
|
||||
self.remove(drone)
|
||||
|
||||
|
||||
class HandledCargoList(HandledList):
|
||||
# shameless copy of HandledDroneList
|
||||
# I have no idea what this does, but I needed it
|
||||
# @todo: investigate this
|
||||
def find(self, item):
|
||||
for d in self:
|
||||
if d.item == item:
|
||||
@@ -184,32 +182,12 @@ class HandledCargoList(HandledList):
|
||||
return d
|
||||
|
||||
def append(self, cargo):
|
||||
list.append(self, cargo)
|
||||
HandledList.append(self, cargo)
|
||||
|
||||
def remove(self, cargo):
|
||||
HandledList.remove(self, cargo)
|
||||
if cargo.isInvalid:
|
||||
# @todo figure out why this DOES NOT remove the cargo from database
|
||||
self.remove(cargo)
|
||||
|
||||
def appendItem(self, item, qty = 1):
|
||||
if qty < 1: ValueError("Amount of cargo to add should be >= 1")
|
||||
d = self.findFirst(item)
|
||||
|
||||
if d is None:
|
||||
d = eos.types.Cargo(item)
|
||||
self.append(d)
|
||||
|
||||
d.qty += qty
|
||||
return d
|
||||
|
||||
def removeItem(self, item, qty):
|
||||
if qty < 1: ValueError("Amount of cargo to remove should be >= 1")
|
||||
d = self.findFirst(item)
|
||||
if d is None: return
|
||||
d.qty -= qty
|
||||
if d.qty <= 0:
|
||||
self.remove(d)
|
||||
return None
|
||||
|
||||
return d
|
||||
|
||||
class HandledImplantBoosterList(HandledList):
|
||||
def __init__(self):
|
||||
|
||||
@@ -20,40 +20,47 @@
|
||||
from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut, ChargeAttrShortcut
|
||||
from eos.effectHandlerHelpers import HandledItem, HandledCharge
|
||||
from sqlalchemy.orm import validates, reconstructor
|
||||
import eos.db
|
||||
|
||||
|
||||
# Cargo class copied from Implant class and hacked to make work. \o/
|
||||
# @todo: clean me up, Scotty
|
||||
class Cargo(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
|
||||
|
||||
def __init__(self, item):
|
||||
"""Initialize cargo from the program"""
|
||||
self.__item = item
|
||||
self.itemID = item.ID
|
||||
self.__invalid = False
|
||||
self.itemID = item.ID if item is not None else None
|
||||
self.amount = 0
|
||||
self.__itemModifiedAttributes = ModifiedAttributeDict()
|
||||
self.__itemModifiedAttributes.original = self.item.attributes
|
||||
self.__itemModifiedAttributes.original = item.attributes
|
||||
|
||||
@reconstructor
|
||||
def init(self):
|
||||
"""Initialize cargo from the database and validate"""
|
||||
self.__item = None
|
||||
|
||||
def __fetchItemInfo(self):
|
||||
import eos.db
|
||||
self.__item = eos.db.getItem(self.itemID)
|
||||
self.__invalid = False
|
||||
self.__itemModifiedAttributes = ModifiedAttributeDict()
|
||||
self.__itemModifiedAttributes.original = self.__item.attributes
|
||||
|
||||
if self.itemID:
|
||||
# if item does not exist, set invalid
|
||||
item = eos.db.getItem(self.itemID)
|
||||
if item is None:
|
||||
self.__invalid = True
|
||||
self.__item = item
|
||||
|
||||
if self.__item:
|
||||
self.__itemModifiedAttributes.original = self.__item.attributes
|
||||
|
||||
@property
|
||||
def itemModifiedAttributes(self):
|
||||
if self.__item is None:
|
||||
self.__fetchItemInfo()
|
||||
|
||||
return self.__itemModifiedAttributes
|
||||
|
||||
@property
|
||||
def item(self):
|
||||
if self.__item is None:
|
||||
self.__fetchItemInfo()
|
||||
def isInvalid(self):
|
||||
return self.__invalid
|
||||
|
||||
@property
|
||||
def item(self):
|
||||
return self.__item
|
||||
|
||||
def clear(self):
|
||||
|
||||
Reference in New Issue
Block a user