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

baseContentProvider.py (6294B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\agencyNew\contentProviders\baseContentProvider.py
      2 import logging
      3 import blue
      4 import telemetry
      5 import uthread2
      6 from carbon.common.script.util.logUtil import LogInfo
      7 from eve.client.script.ui.shared.agencyNew import agencyConst, agencyFilters, agencySignals
      8 from eve.client.script.ui.shared.agencyNew.agencyUtil import GetNumberOfJumps, GetSystemsWithinJumpRange
      9 from eve.common.lib import appConst
     10 from eve.common.script.sys.idCheckers import IsVoidSpaceSystem, IsHiddenSpaceSystem
     11 from eve.common.script.sys.idCheckers import IsWormholeSystem, IsAbyssalSpaceSystem, IsKnownSpaceSystem
     12 logger = logging.getLogger(__name__)
     13 
     14 class BaseContentProvider(object):
     15     contentType = None
     16     contentGroup = None
     17     contentTypeFilters = (agencyConst.CONTENTTYPE_SUGGESTED,)
     18     __notifyevents__ = ['OnNewState']
     19 
     20     def __init__(self):
     21         self.contentPieces = None
     22         self.isConstructing = False
     23         agencyFilters.onFilterChanged.connect(self.OnAgencyFilterChanged)
     24         sm.RegisterNotify(self)
     25 
     26     def OnNewState(self, bp):
     27         self.InvalidateContentPieces()
     28 
     29     def OnAgencyFilterChanged(self, contentGroupID, filterType, value):
     30         if contentGroupID != self.contentGroup:
     31             return
     32         self.contentPieces = None
     33         uthread2.StartTasklet(self.ConstructContentPieces)
     34 
     35     def GetContentPieces(self):
     36         if self.contentPieces is None:
     37             self.ConstructContentPieces()
     38         return self.contentPieces or []
     39 
     40     def InvalidateContentPieces(self):
     41         self.contentPieces = None
     42         agencySignals.on_content_pieces_invalidated(self.contentGroup)
     43 
     44     def ConstructContentPieces(self):
     45         self.isConstructing = True
     46         self.contentPieces = []
     47         startTime = blue.os.GetWallclockTimeNow()
     48         try:
     49             self._ConstructContentPieces()
     50         except (AttributeError, KeyError, IndexError):
     51             logger.exception('Content Provider could not construct content pieces')
     52         else:
     53             updateTime = (blue.os.GetWallclockTimeNow() - startTime) / appConst.MSEC
     54             LogInfo('%.1f ms Update time (Agency: %s content provider)' % (updateTime, self.__class__.__name__))
     55         finally:
     56             self.isConstructing = False
     57             agencySignals.on_content_pieces_constructed(self.contentGroup)
     58 
     59     def _ConstructContentPieces(self):
     60         pass
     61 
     62     @telemetry.ZONE_METHOD
     63     def CheckDistanceCriteria(self, solarSystemID):
     64         distance = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_DISTANCE)
     65         if solarSystemID is None:
     66             return False
     67         elif IsAbyssalSpaceSystem(session.solarsystemid2) or IsVoidSpaceSystem(session.solarsystemid2) or IsHiddenSpaceSystem(session.solarsystemid2):
     68             return False
     69         elif distance == agencyConst.DISTANCE_REGION:
     70             return self.CheckRegionOrConstellationCriteria(solarSystemID)
     71         elif IsWormholeSystem(session.solarsystemid2) or distance == agencyConst.DISTANCE_CURRSYSTEM:
     72             return solarSystemID == session.solarsystemid2
     73         elif distance == agencyConst.DISTANCE_ANY:
     74             return True
     75         numJumps = self.GetNumJumpsToSystem(solarSystemID)
     76         if numJumps is None:
     77             return False
     78         else:
     79             return numJumps <= distance
     80 
     81     def CheckRegionOrConstellationCriteria(self, solarSystemID):
     82         constellationID = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_CONSTELLATION)
     83         if constellationID == agencyConst.CONSTELLATION_ANY:
     84             contentRegionID = cfg.mapSystemCache.Get(solarSystemID).regionID
     85             return contentRegionID == agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_REGION)
     86         else:
     87             contentConstellationID = cfg.mapSystemCache.Get(solarSystemID).constellationID
     88             return contentConstellationID == constellationID
     89 
     90     @telemetry.ZONE_METHOD
     91     def GetNumJumpsToSystem(self, solarSystemID):
     92         return GetNumberOfJumps(solarSystemID)
     93 
     94     @telemetry.ZONE_METHOD
     95     def IsInHighSec(self, solarSystemID):
     96         systemSec = sm.GetService('map').GetSecurityStatus(solarSystemID)
     97         return systemSec >= 0.5
     98 
     99     def AppendContentPiece(self, contentPiece):
    100         if self.contentPieces is not None:
    101             self.contentPieces.append(contentPiece)
    102 
    103     def ExtendContentPieces(self, contentPieces):
    104         if self.contentPieces is not None:
    105             self.contentPieces.extend(contentPieces)
    106 
    107     @telemetry.ZONE_METHOD
    108     def GetAllSolarSystemIDsWithinJumpRange(self, shouldIncludeAvoided = False):
    109         maxJumps = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_DISTANCE)
    110         if maxJumps == agencyConst.DISTANCE_REGION:
    111             region_id = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_REGION)
    112             return sorted(cfg.mapRegionCache[region_id].solarSystemIDs, key=lambda systemID: GetNumberOfJumps(systemID))
    113         if not IsKnownSpaceSystem(session.solarsystemid2):
    114             return [session.solarsystemid2]
    115         maxJumps = maxJumps + 1 if maxJumps > 0 else maxJumps
    116         systemsWithinJumpRange = GetSystemsWithinJumpRange(fromID=session.solarsystemid2, jumpCountMin=0, jumpCountMax=maxJumps, shouldIncludeAvoided=shouldIncludeAvoided)
    117         solarSystemIDsLists = systemsWithinJumpRange.values()
    118         return [ solarSystemID for solarSystemIDs in solarSystemIDsLists for solarSystemID in solarSystemIDs ]
    119 
    120     def ClearNewContent(self, contentPiece):
    121         pass
    122 
    123     def ApplyDefaultFilters(self):
    124         pass
    125 
    126     def CheckSecurityStatusFilterCriteria(self, solarSystemID):
    127         securityStatus = agencyFilters.GetFilterValue(self.contentGroup, agencyConst.FILTERTYPE_SECURITYSTATUS)
    128         if securityStatus == agencyConst.FILTERVALUE_ANY:
    129             return True
    130         systemSec = sm.GetService('map').GetSecurityStatus(solarSystemID)
    131         if securityStatus == agencyConst.SECURITYSTATUS_HIGHSEC:
    132             return systemSec >= 0.45
    133         elif securityStatus == agencyConst.SECURITYSTATUS_NULLSEC:
    134             return systemSec <= 0.0
    135         else:
    136             return 0.0 < systemSec < 0.45