NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

baseDogmaItem.py (6880B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dogma\items\baseDogmaItem.py
      2 from __future__ import absolute_import
      3 from .slimDogmaItem import SlimDogmaItem
      4 from dogma import dogmaLogging as log
      5 import sys
      6 import inventorycommon.const as invconst
      7 import dogma.const as dgmconst
      8 from ccpProfile import TimedFunction
      9 from utillib import KeyVal
     10 from .slimDogmaItem import RESISTANCEMATRIX
     11 
     12 class BaseDogmaItem(SlimDogmaItem):
     13 
     14     @TimedFunction('BaseDogmaItem::__init__')
     15     def __init__(self, dogmaLocation, item, eveCfg, clientIDFunc):
     16         SlimDogmaItem.__init__(self, dogmaLocation, item, clientIDFunc)
     17         self.flagID = None
     18         self.isDirty = False
     19         self.fittingFlags = set()
     20         self.cfg = eveCfg
     21 
     22     @TimedFunction('BaseDogmaItem::Load')
     23     def Load(self, item, instanceRow):
     24         categoryID = item.categoryID
     25         typeID = item.typeID
     26         groupID = item.groupID
     27         ownerID = item.ownerID
     28         flag = item.flagID
     29         if ownerID:
     30             ownerOb = self.cfg.eveowners.Get(ownerID)
     31             if ownerOb.typeID == invconst.typeCorporation or ownerOb.IsNPC() or ownerOb.IsSystem():
     32                 ownerID = None
     33         self.flagID = None
     34         attrs = self.attributes
     35         for attrID, value in self.dogmaLocation.GetAttributesForItem(item.itemID, typeID).iteritems():
     36             attrs[attrID].SetBaseValue(value)
     37 
     38         attributesByIdx = self.dogmaLocation.GetAttributesByIndex()
     39         for attributeIdx, attributeID in attributesByIdx.iteritems():
     40             value = instanceRow[attributeIdx]
     41             if value != 0:
     42                 if type(value) is bool:
     43                     value = int(value)
     44                 attrs[attributeID].SetBaseValue(value)
     45 
     46     def PostLoadAction(self):
     47         pass
     48 
     49     def GetLocationInfo(self):
     50         return (self.invItem.ownerID, self.invItem.locationID, self.flagID)
     51 
     52     def GetItemInfo(self):
     53         ownerID, locationID, flagID = self.GetLocationInfo()
     54         return (self.invItem.typeID,
     55          self.invItem.groupID,
     56          self.invItem.categoryID,
     57          ownerID,
     58          locationID,
     59          flagID)
     60 
     61     def GetPilot(self):
     62         return self.invItem.ownerID
     63 
     64     def GetShip(self):
     65         pilotID = self.GetPilot()
     66         return self.dogmaLocation.shipsByPilotID.get(pilotID, None)
     67 
     68     def SetLocation(self, locationID, locationDogmaItem, flagID):
     69         self.flagID = flagID
     70 
     71     def UnsetLocation(self, locationDogmaItem):
     72         pass
     73 
     74     def MarkDirty(self):
     75         self.isDirty = True
     76 
     77     def UnmarkDirty(self):
     78         self.isDirty = False
     79 
     80     def RegisterEffect(self, effectID, effectStart, duration, environment, repeat):
     81         self.activeEffects[effectID] = [effectStart,
     82          duration,
     83          environment,
     84          repeat]
     85 
     86     def UnregisterEffect(self, effectID, environment):
     87         del self.activeEffects[effectID]
     88         if self.itemID in self.dogmaLocation.activeDungeonEffectsByItem:
     89             if effectID in self.dogmaLocation.activeDungeonEffectsByItem[self.itemID]:
     90                 try:
     91                     self.dogmaLocation.activeDungeonEffectsByItem[self.itemID][effectID].remove(environment.itemID)
     92                 except ValueError:
     93                     pass
     94 
     95                 if len(self.dogmaLocation.activeDungeonEffectsByItem[self.itemID][effectID]) == 0:
     96                     del self.dogmaLocation.activeDungeonEffectsByItem[self.itemID][effectID]
     97             if len(self.dogmaLocation.activeDungeonEffectsByItem[self.itemID]) == 0:
     98                 del self.dogmaLocation.activeDungeonEffectsByItem[self.itemID]
     99 
    100     def IsEffectRegistered(self, effectID, environment):
    101         return effectID in self.activeEffects
    102 
    103     def Unload(self):
    104         SlimDogmaItem.Unload(self)
    105         self.dogmaLocation.LogInfo('BaseDogmaItem calling FlushEffects')
    106         stackTraceCount = self.FlushEffects()
    107         if stackTraceCount:
    108             log.LogTraceback('FlushEffectsFromItem %s stack traced %s times, this is to provide higher context' % (self.itemID, stackTraceCount))
    109 
    110     def OnItemLoaded(self):
    111         self.dogmaLocation.HandleDogmaLocationEffectsOnItem(self)
    112 
    113     def GetEnvironmentInfo(self):
    114         return KeyVal(itemID=self.GetItemID(), shipID=self.GetShipID(), charID=self.GetCharacterID(), otherID=self.GetOtherID(), targetID=self.GetTargetID(), effectID=self.GetEffectID(), structureID=self.GetStructureID())
    115 
    116     def GetPersistables(self):
    117         return set([self.itemID])
    118 
    119     def IsOnline(self):
    120         return False
    121 
    122     def IsActive(self):
    123         return False
    124 
    125     def FlushEffects(self):
    126         flushAddedToUnloading = False
    127         unloadingItems = self.dogmaLocation.unloadingItems
    128         itemID = self.itemID
    129         if itemID not in unloadingItems:
    130             unloadingItems.add(itemID)
    131             flushAddedToUnloading = True
    132         try:
    133             stackTraceCount = self._FlushEffects()
    134         finally:
    135             if flushAddedToUnloading and itemID in unloadingItems:
    136                 unloadingItems.remove(itemID)
    137 
    138         return stackTraceCount
    139 
    140     @TimedFunction('BaseDogmaItem::_FlushEffects')
    141     def _FlushEffects(self):
    142         stackTraceCount = 0
    143         itemID = self.itemID
    144         dogmaLM = self.dogmaLocation
    145         for effectID in self.activeEffects.keys():
    146             if isinstance(effectID, tuple):
    147                 effectID, shipID = effectID
    148             effect = dogmaLM.dogmaStaticMgr.effects[effectID]
    149             try:
    150                 if effect.effectCategory == dgmconst.dgmEffDungeon:
    151                     dogmaLM.StopDungeonEffect(itemID, effectID)
    152                 elif effect.effectCategory == dgmconst.dgmEffSystem:
    153                     dogmaLM.StopMultiEffect(itemID, effectID)
    154                 else:
    155                     dogmaLM.StopEffect(effectID, itemID, forced=True)
    156             except Exception:
    157                 stackTraceCount += 1
    158                 log.LogException()
    159                 sys.exc_clear()
    160 
    161         return stackTraceCount
    162 
    163     def CanFitItem(self, dogmaItem, flagID):
    164         return False
    165 
    166     def GetResistanceMatrix(self):
    167         try:
    168             return self.resistanceMatrix
    169         except AttributeError:
    170             self.resistanceMatrix = RESISTANCEMATRIX.copy()
    171             for attributeID, resAttribs in self.dogmaLocation.dogmaStaticMgr.resistanceAttributesByLayer.iteritems():
    172                 self.resistanceMatrix[attributeID] = [ self.GetValue(resAttributeID) for resAttributeID in resAttribs ]
    173 
    174             return self.resistanceMatrix
    175 
    176     def GetItemID(self):
    177         return self.itemID
    178 
    179     def GetShipID(self):
    180         return self.itemID
    181 
    182     def GetCharacterID(self):
    183         return None
    184 
    185     def GetOtherID(self):
    186         return None
    187 
    188     def GetTargetID(self):
    189         return None
    190 
    191     def GetEffectID(self):
    192         return None
    193 
    194     def GetStructureID(self):
    195         return None