fittableDogmaItem.py (4124B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dogma\items\fittableDogmaItem.py 2 from __future__ import absolute_import 3 from dogma.dogmaLogging import * 4 from .baseDogmaItem import BaseDogmaItem 5 from ccpProfile import TimedFunction 6 import weakref 7 import blue 8 9 class FittableDogmaItem(BaseDogmaItem): 10 11 def __init__(self, *args, **kwargs): 12 self._location = None 13 self.lastStopTime = None 14 BaseDogmaItem.__init__(self, *args, **kwargs) 15 16 @property 17 def location(self): 18 if self._location: 19 return self._location() 20 21 @location.setter 22 def location(self, location): 23 if location is None: 24 self._location = None 25 else: 26 self._location = weakref.ref(location) 27 28 @property 29 def ownerID(self): 30 if self.location: 31 return self.location.ownerID 32 33 @ownerID.setter 34 def ownerID(self, ownerID): 35 if self.location and self.location.ownerID != ownerID: 36 self.dogmaLocation.LogError('Setting ownerID on a FittableDogmaItem to something that disagrees with its location!', self.location.ownerID, ownerID) 37 38 @TimedFunction('FittableDogmaItem::Unload') 39 def Unload(self): 40 BaseDogmaItem.Unload(self) 41 if self.location: 42 try: 43 locationFittedItems = self.location.fittedItems 44 except AttributeError: 45 return 46 47 if self.itemID in locationFittedItems: 48 del locationFittedItems[self.itemID] 49 elif self.itemID in self.dogmaLocation.itemsMissingLocation: 50 del self.dogmaLocation.itemsMissingLocation[self.itemID] 51 52 def SetLastStopTime(self, lastStopTime): 53 self.lastStopTime = lastStopTime 54 55 def IsActive(self): 56 for effectID in self.activeEffects: 57 if effectID == const.effectOnline: 58 continue 59 effect = self.dogmaLocation.GetEffect(effectID) 60 if effect.effectCategory in (const.dgmEffActivation, const.dgmEffTarget): 61 return True 62 63 return False 64 65 @TimedFunction('FittableDogmaItem::SetLocation') 66 def SetLocation(self, locationID, location, flagID): 67 if location is None: 68 self.dogmaLocation.LogError('FittableDogmaItem.SetLocation :: Location dogma item is None') 69 return 70 if not self.IsValidFittingLocation(location): 71 self.dogmaLocation.LogError('FittableDogmaItem.SetLocation :: Invalid fitting location') 72 return 73 oldData = self.GetLocationInfo() 74 self.location = location 75 self.flagID = flagID 76 location.RegisterFittedItem(self, flagID) 77 return oldData 78 79 def IsValidFittingLocation(self, location): 80 return False 81 82 def UnsetLocation(self, locationDogmaItem): 83 locationDogmaItem.UnregisterFittedItem(self) 84 85 def GetShipID(self): 86 if self.location: 87 return self.location.itemID 88 89 def GetPilot(self): 90 if self.location: 91 return self.location.GetPilot() 92 93 def GetOtherID(self): 94 otherID = None 95 if self.location: 96 otherID = self.location.subLocations.get(self.flagID, None) 97 if otherID is None: 98 other = self.dogmaLocation.GetChargeNonDB(self.location.itemID, self.flagID) 99 if other is not None: 100 otherID = other.itemID 101 return otherID 102 103 def SerializeForPropagation(self): 104 retVal = BaseDogmaItem.SerializeForPropagation(self) 105 if self.lastStopTime: 106 retVal.lastStopTime = self.lastStopTime - blue.os.GetSimTime() + blue.os.GetWallclockTime() 107 else: 108 retVal.lastStopTime = None 109 return retVal 110 111 def UnpackPropagationData(self, propData, charID, shipID): 112 BaseDogmaItem.UnpackPropagationData(self, propData, charID, shipID) 113 if propData.lastStopTime: 114 lastStopTime = propData.lastStopTime - blue.os.GetWallclockTime() + blue.os.GetSimTime() 115 else: 116 lastStopTime = None 117 self.SetLastStopTime(lastStopTime)