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

clientDogmaStaticSvc.py (1925B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\dogma\clientDogmaStaticSvc.py
      2 from collections import defaultdict
      3 from eve.common.lib import appConst as const
      4 import dogma.data as dogma_data
      5 import evetypes
      6 from eve.common.script.dogma.baseDogmaStaticSvc import BaseDogmaStaticSvc
      7 
      8 class AttributesByTypeLookupDict(defaultdict):
      9 
     10     def __init__(self, typeID, *args, **kwargs):
     11         defaultdict.__init__(self, *args, **kwargs)
     12         self.typeID = typeID
     13 
     14     def __missing__(self, attributeID):
     15         for attribute in dogma_data.get_type_attributes(self.typeID):
     16             if attribute.attributeID == attributeID:
     17                 return attribute.value
     18 
     19         ret = None
     20         if attributeID == const.attributeMass:
     21             ret = evetypes.GetMass(self.typeID)
     22         elif attributeID == const.attributeCapacity:
     23             ret = evetypes.GetCapacity(self.typeID)
     24         elif attributeID == const.attributeVolume:
     25             ret = evetypes.GetVolume(self.typeID)
     26         if ret is None:
     27             raise KeyError(attributeID)
     28         else:
     29             self[attributeID] = ret
     30             return ret
     31 
     32 
     33 class AttributesByTypeAttribute(defaultdict):
     34 
     35     def __missing__(self, typeID):
     36         if not dogma_data.has_type_attributes(typeID) and not evetypes.Exists(typeID):
     37             raise KeyError(typeID)
     38         return AttributesByTypeLookupDict(typeID)
     39 
     40 
     41 class ClientDogmaStaticSvc(BaseDogmaStaticSvc):
     42     __guid__ = 'svc.clientDogmaStaticSvc'
     43 
     44     def LoadTypeAttributes(self, *args, **kwargs):
     45         self.attributesByTypeAttribute = AttributesByTypeAttribute()
     46 
     47     def TypeHasAttribute(self, typeID, attributeID):
     48         try:
     49             for row in dogma_data.get_type_attributes(typeID):
     50                 if row.attributeID == attributeID:
     51                     return True
     52 
     53             return False
     54         except KeyError:
     55             return False