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

insurgenceDashboardSvc.py (9672B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\services\insurgenceDashboardSvc.py
      2 from evePathfinder.core import IsUnreachableJumpCount
      3 import uthread
      4 import signals
      5 import uthread2
      6 from caching import Memoize
      7 from carbon.common.script.sys.service import Service
      8 from localization import GetByLabel
      9 from pirateinsurgency.client.dashboard.const import SUPPRESSION_STAGES, CORRUPTION_STAGES, ConstructErrorMessageCont
     10 from stackless_response_router.exceptions import UnpackException, TimeoutException
     11 
     12 class InsurgencyDashboardSvc(Service):
     13     __guid__ = 'svc.insurgencyDashboardSvc'
     14     __startupdependencies__ = ['insurgencyCampaignSvc',
     15      'corruptionSuppressionSvc',
     16      'clientPathfinderService',
     17      'facwar']
     18 
     19     def __init__(self):
     20         super(InsurgencyDashboardSvc, self).__init__()
     21         self.SIGNAL_solarSystemSelectedFromMap = signals.Signal(signalName='solarSystemSelected')
     22 
     23     def Run(self, memStream = None):
     24         super(InsurgencyDashboardSvc, self).Run(memStream=memStream)
     25 
     26     def GetPersonalStats(self):
     27         return self.facwar.GetStats_Personal()
     28 
     29     def GetCurrentRank(self):
     30         currentRank = 1
     31         currRank = self.facwar.GetCharacterRankInfo(session.charid)
     32         if currRank:
     33             currentRank = currRank.currentRank
     34         rankName, rankDescription = self.facwar.GetRankLabel(session.warfactionid, currentRank)
     35         return (rankName, rankDescription)
     36 
     37     def IsSystemAffectedByInsurgency(self, systemID):
     38         if self.GetCampaignSnapshotForSystem(systemID) is None:
     39             return False
     40         return True
     41 
     42     def GetCampaignSnapshotForSystem(self, systemID):
     43         snapshots = self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized()
     44         for s in snapshots:
     45             if systemID in s.coveredSolarsystemIDs:
     46                 return s
     47 
     48     def IsLocalSystemAffectedByInsurgency(self):
     49         snapshot = self.insurgencyCampaignSvc.GetLocalCampaignSnapshot()
     50         if snapshot is None:
     51             return False
     52         return True
     53 
     54     def GetLocalCampaignSnapshot(self):
     55         return self.insurgencyCampaignSvc.GetLocalCampaignSnapshot()
     56 
     57     def IsFOBSystem(self, systemID):
     58         snapshots = self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized()
     59         for s in snapshots:
     60             if systemID == s.originSolarsystemID:
     61                 return True
     62 
     63         return False
     64 
     65     def GetSystemWarzoneID(self, systemID):
     66         snapshots = self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized()
     67         for s in snapshots:
     68             if systemID in s.coveredSolarsystemIDs:
     69                 return s.warzoneID
     70 
     71     def OnSolarSystemSelectedFromMap(self, systemID):
     72         self.SIGNAL_solarSystemSelectedFromMap(systemID)
     73 
     74     def GetNumJumpsString(self, systemID):
     75         numJumps = self.clientPathfinderService.GetAutopilotJumpCount(session.solarsystemid2, systemID)
     76         if IsUnreachableJumpCount(numJumps):
     77             jumpsString = '-'
     78         else:
     79             jumpsString = str(numJumps)
     80         return GetByLabel('UI/FactionWarfare/frontlinesDashboard/jumps', numJumps=jumpsString)
     81 
     82     def GetCurrentCampaignSnapshots(self):
     83         return self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized()
     84 
     85     def GetCurrentCampaignSnapshotByID(self, campaignID):
     86         for snapshot in self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized():
     87             if snapshot.campaignID == campaignID:
     88                 return snapshot
     89 
     90     def RequestAllCorruptionAndSuppressionValuesForCampaignID(self, campaignID, callback):
     91 
     92         def run():
     93             try:
     94                 data = self._BlockingGetAllCorruptionAndSuppressionValues(campaignID)
     95             except (TimeoutException, UnpackException):
     96                 callback(None)
     97                 return
     98 
     99             callback(data)
    100 
    101         uthread2.StartTasklet(run)
    102 
    103     def RequestCurrentSuppressionStage(self, campaignID, callback):
    104 
    105         def calculation_callback(data):
    106             if data is None:
    107                 callback(None)
    108                 return
    109             values = [ d.stage for d in data ]
    110             result = self._GetNumberOfMaxes(values, SUPPRESSION_STAGES)
    111             callback(result)
    112 
    113         self.RequestAllCurrentSuppressionValues(campaignID, calculation_callback)
    114 
    115     def RequestCurrentCorruptionStage(self, campaignID, callback):
    116 
    117         def calculation_callback(data):
    118             if data is None:
    119                 callback(None)
    120                 return
    121             values = [ d.stage for d in data ]
    122             result = self._GetNumberOfMaxes(values, CORRUPTION_STAGES)
    123             callback(result)
    124 
    125         self.RequestAllCurrentCorruptionValues(campaignID, calculation_callback)
    126 
    127     def _GetNumberOfMaxes(self, values, max):
    128         n = 0
    129         for v in values:
    130             if v >= max:
    131                 n += 1
    132 
    133         return n
    134 
    135     def RequestAllCurrentSuppressionValues(self, campaignID, callback):
    136         snapshot = None
    137         for s in self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized():
    138             if s.campaignID == campaignID:
    139                 snapshot = s
    140 
    141         if snapshot is None:
    142             raise RuntimeError('no snapshot with campaignID %s' % campaignID)
    143         uthread2.StartTasklet(self._AsyncGetAllPerSystemData, snapshot, self.corruptionSuppressionSvc.GetSystemSuppression, callback)
    144 
    145     def RequestAllCurrentCorruptionValues(self, campaignID, callback):
    146         snapshot = None
    147         for s in self.insurgencyCampaignSvc.GetCurrentCampaignSnapshots_Memoized():
    148             if s.campaignID == campaignID:
    149                 snapshot = s
    150 
    151         if snapshot is None:
    152             raise RuntimeError('no snapshot with campaignID %s' % campaignID)
    153         uthread2.StartTasklet(self._AsyncGetAllPerSystemData, snapshot, self.corruptionSuppressionSvc.GetSystemCorruption, callback)
    154 
    155     def RequestSystemSuppression(self, systemID, callback):
    156 
    157         def run():
    158             try:
    159                 data = self.corruptionSuppressionSvc.GetSystemSuppression(systemID)
    160             except (TimeoutException, UnpackException):
    161                 callback(None)
    162                 return
    163 
    164             callback(data)
    165 
    166         uthread2.StartTasklet(run)
    167 
    168     def RequestSystemCorruption(self, systemID, callback):
    169 
    170         def run():
    171             try:
    172                 data = self.corruptionSuppressionSvc.GetSystemCorruption(systemID)
    173             except (TimeoutException, UnpackException):
    174                 callback(None)
    175                 return
    176 
    177             callback(data)
    178 
    179         uthread2.StartTasklet(run)
    180 
    181     def RequestLocalSystemCorruption(self, callback):
    182 
    183         def run():
    184             try:
    185                 data = self.corruptionSuppressionSvc.GetCurrentSystemCorruption_Cached()
    186             except (TimeoutException, UnpackException):
    187                 callback(None)
    188                 return
    189 
    190             callback(data)
    191 
    192         uthread2.StartTasklet(run)
    193 
    194     def RequestLocalSystemSuppression(self, callback):
    195 
    196         def run():
    197             try:
    198                 data = self.corruptionSuppressionSvc.GetCurrentSystemSuppression_Cached()
    199             except (TimeoutException, UnpackException):
    200                 callback(None)
    201                 return
    202 
    203             callback(data)
    204 
    205         uthread2.StartTasklet(run)
    206 
    207     def RequestSuppressionStages(self, callback):
    208 
    209         def run():
    210             try:
    211                 data = self.corruptionSuppressionSvc.GetSuppressionStages()
    212             except (TimeoutException, UnpackException):
    213                 callback(None)
    214                 return
    215 
    216             callback(data)
    217 
    218         uthread2.StartTasklet(run)
    219 
    220     def RequestCorruptionStages(self, callback):
    221 
    222         def run():
    223             try:
    224                 data = self.corruptionSuppressionSvc.GetCorruptionStages()
    225             except (TimeoutException, UnpackException):
    226                 callback(None)
    227                 return
    228 
    229             callback(data)
    230 
    231         uthread2.StartTasklet(run)
    232 
    233     def _BlockingGetAllCorruptionAndSuppressionValues(self, campaignID):
    234         snapshot = self.GetCurrentCampaignSnapshotByID(campaignID)
    235         rawData = uthread.parallel([(self._BlockingGetAllPerSystemData, (snapshot, self.corruptionSuppressionSvc.GetSystemCorruption)), (self._BlockingGetAllPerSystemData, (snapshot, self.corruptionSuppressionSvc.GetSystemSuppression))])
    236         data = {'corruption': {data.systemID:data for data in rawData[0]},
    237          'suppression': {data.systemID:data for data in rawData[1]}}
    238         return data
    239 
    240     def _AsyncGetAllPerSystemData(self, campaign, request_fun, callback):
    241         try:
    242             data = self._BlockingGetAllPerSystemData(campaign, request_fun)
    243         except (TimeoutException, UnpackException):
    244             callback(None)
    245             return
    246 
    247         callback(data)
    248 
    249     def _BlockingGetAllPerSystemData(self, campaign, request_fun):
    250         return uthread.parallel([ (request_fun, (systemID,)) for systemID in campaign.coveredSolarsystemIDs ])
    251 
    252     @Memoize(3)
    253     def GetIceHeistInstances_Memoized(self):
    254         return sm.RemoteSvc('dungeonInstanceCacheMgr').GetPirateInsurgencyIceHeistInstances()
    255 
    256 
    257 def WrapCallbackWithErrorHandling(callbackFun, parentContainer = None, errorMessageLabel = 'UI/PirateInsurgencies/insurgencyDataError', onErrorCallback = None, fullErrorBox = True):
    258 
    259     def _fun(data):
    260         if data is None:
    261             if onErrorCallback is not None:
    262                 onErrorCallback()
    263             if parentContainer is not None:
    264                 ConstructErrorMessageCont(parentContainer, errorMessageLabel, fullErrorBox=fullErrorBox)
    265         else:
    266             callbackFun(data)
    267 
    268     return _fun