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

structure.py (10112B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\spaceObject\structure.py
      2 import blue
      3 import uthread
      4 import structures
      5 import evetypes
      6 from carbon.common.lib import const
      7 from eve.client.script.environment.spaceObject.buildableStructure import BuildableStructure
      8 from eve.client.script.environment.model.turretSet import TurretSet
      9 from evegraphics.logoLoader import LogoLoader
     10 STATE_CONSTRUCT = 'construct'
     11 STATE_INVULNERABLE = 'invulnerable'
     12 STATE_VULNERABLE_ACTIVE = 'vulnerable_active'
     13 STATE_VULNERABLE_INACTIVE = 'vulnerable_inactive'
     14 STATE_SIEGED_ACTIVE = 'sieged_active'
     15 STATE_SIEGED_INACTIVE = 'sieged_inactive'
     16 STATE_DECONSTRUCT = 'deconstruct'
     17 STATES = {structures.STATE_UNKNOWN: (STATE_INVULNERABLE, STATE_INVULNERABLE),
     18  structures.STATE_UNANCHORED: (STATE_DECONSTRUCT, STATE_DECONSTRUCT),
     19  structures.STATE_ANCHORING: (STATE_CONSTRUCT, STATE_CONSTRUCT),
     20  structures.STATE_ONLINE_DEPRECATED: (STATE_INVULNERABLE, STATE_INVULNERABLE),
     21  structures.STATE_FITTING_INVULNERABLE: (STATE_INVULNERABLE, STATE_INVULNERABLE),
     22  structures.STATE_ONLINING_VULNERABLE: (STATE_VULNERABLE_INACTIVE, STATE_VULNERABLE_ACTIVE),
     23  structures.STATE_SHIELD_VULNERABLE: (STATE_VULNERABLE_INACTIVE, STATE_VULNERABLE_ACTIVE),
     24  structures.STATE_ARMOR_REINFORCE: (STATE_SIEGED_INACTIVE, STATE_SIEGED_ACTIVE),
     25  structures.STATE_ARMOR_VULNERABLE: (STATE_VULNERABLE_INACTIVE, STATE_VULNERABLE_ACTIVE),
     26  structures.STATE_HULL_REINFORCE: (STATE_SIEGED_INACTIVE, STATE_SIEGED_ACTIVE),
     27  structures.STATE_HULL_VULNERABLE: (STATE_VULNERABLE_INACTIVE, STATE_VULNERABLE_ACTIVE),
     28  structures.STATE_ANCHOR_VULNERABLE: (STATE_CONSTRUCT, STATE_CONSTRUCT),
     29  structures.STATE_DEPLOY_VULNERABLE: (STATE_CONSTRUCT, STATE_CONSTRUCT),
     30  structures.STATE_FOB_INVULNERABLE: (STATE_INVULNERABLE, STATE_INVULNERABLE)}
     31 
     32 class Structure(BuildableStructure):
     33     __unloadable__ = True
     34     __notifyevents__ = ['OnAllianceLogoReady', 'OnCorpLogoReady', 'OnPortraitCreated']
     35 
     36     def __init__(self):
     37         BuildableStructure.__init__(self)
     38         self.logoLoader = LogoLoader((LogoLoader.ALLIANCE, LogoLoader.CORP, LogoLoader.CEO))
     39         sm.RegisterNotify(self)
     40         self.Init()
     41 
     42     def Release(self, origin = None):
     43         BuildableStructure.Release(self, origin)
     44         self.Init()
     45 
     46     def Init(self):
     47         self.fitted = False
     48         self.state = None
     49         self.timer = None
     50         self.upkeepState = None
     51         self.turrets = []
     52         self.modules = {}
     53 
     54     def Assemble(self):
     55         self.SetStaticRotation()
     56         self.SetupSharedAmbientAudio()
     57 
     58         def runInTasklet(func, *args):
     59             func(*args)
     60 
     61         self._OnSlimItemUpdated(self.typeData.get('slimItem'), runInTasklet)
     62 
     63     def OnSlimItemUpdated(self, item):
     64         BuildableStructure.OnSlimItemUpdated(self, item)
     65         self._OnSlimItemUpdated(item, uthread.new)
     66 
     67     def _OnSlimItemUpdated(self, item, taskletSpawner):
     68         if item is None:
     69             return
     70         self.typeData['slimItem'] = item
     71         if self.unloaded or self.model is None:
     72             return
     73         if item.state and (item.state != self.state or item.timer != self.timer or item.upkeepState != self.upkeepState):
     74             duration = 0
     75             elapsed = 0
     76             if item.timer and item.state == structures.STATE_ANCHORING:
     77                 start, end, paused = item.timer
     78                 duration = (end - start) / const.SEC
     79                 elapsed = duration - max(end - blue.os.GetWallclockTime(), 0) / const.SEC
     80             elif item.state == structures.STATE_ANCHOR_VULNERABLE:
     81                 duration = 86400
     82                 elapsed = 0
     83             elif item.state == structures.STATE_DEPLOY_VULNERABLE:
     84                 if item.deployTimes is not None:
     85                     start, end = item.deployTimes
     86                     duration = (end - start) / const.SEC
     87                     elapsed = duration - max(end - blue.os.GetWallclockTime(), 0) / const.SEC
     88             self.state = item.state
     89             self.timer = item.timer
     90             self.upkeepState = item.upkeepState
     91             isActiveUpkeep = self.upkeepState == structures.UPKEEP_STATE_FULL_POWER
     92             self._GotoState(STATES[self.state][int(isActiveUpkeep)], duration, elapsed, taskletSpawner)
     93         uthread.new(self.logoLoader.Load, self.model, item)
     94         if not item.state and set([ i[0] for i in item.modules or [] if evetypes.GetGraphicID(i[1]) is not None ]) != set(self.modules.keys()):
     95             uthread.new(self.ReloadHardpoints)
     96 
     97     def _GotoState(self, state, totalTime = 0, elapsedTime = 0, taskletSpawner = uthread.new):
     98         if state == STATE_CONSTRUCT:
     99             taskletSpawner(self.BuildStructure, float(totalTime), float(elapsedTime))
    100         elif state == STATE_DECONSTRUCT:
    101             taskletSpawner(self.TearDownStructure, float(totalTime), float(elapsedTime))
    102         else:
    103             taskletSpawner(self.LoadModelWithState, state)
    104 
    105     def LoadModelWithState(self, newState):
    106         if self.model is None:
    107             self.LoadModel()
    108         self.SetControllerVariable('BuildDuration', 0)
    109         self.SetControllerVariable('BuildElapsedTime', 0)
    110         self.SetControllerVariable('IsBuilt', True)
    111         self.ClearAnimationStateObjects()
    112         self.TriggerStateObject(newState)
    113         self.FitHardpoints()
    114         self._SetCorruptionAndSuppression()
    115 
    116     def _SetCorruptionAndSuppression(self):
    117         css = sm.GetService('corruptionSuppressionSvc')
    118         if css is not None:
    119             maximumSuppressionStages = max(len(css.GetSuppressionStages()), 1)
    120             maximumCorruptionStages = max(len(css.GetCorruptionStages()), 1)
    121             suppressionStage = css.GetSystemSuppressionStage(session.solarsystemid) or 0.0
    122             corruptionStage = css.GetSystemCorruptionStage(session.solarsystemid) or 0.0
    123             suppression = float(suppressionStage) / float(maximumSuppressionStages)
    124             corruption = float(corruptionStage) / float(maximumCorruptionStages)
    125             self.SetControllerVariable('suppression', suppression)
    126             self.SetControllerVariable('corruption', corruption)
    127 
    128     def LoadModel(self, fileName = None, loadedModel = None, notify = True, addToScene = True):
    129         self.model = self.GetStructureModel()
    130         self.logoLoader.Load(self.model, self.typeData['slimItem'])
    131         self.NotifyModelLoaded()
    132 
    133     def OnPortraitCreated(self, charID, _size):
    134         if self.logoLoader.HasID(charID):
    135             self.logoLoader.Update(self.model)
    136 
    137     def OnAllianceLogoReady(self, allianceID, _size):
    138         if self.logoLoader.HasID(allianceID):
    139             self.logoLoader.Update(self.model)
    140 
    141     def OnCorpLogoReady(self, corpID, _size):
    142         if self.logoLoader.HasID(corpID):
    143             self.logoLoader.Update(self.model)
    144 
    145     def ReloadHardpoints(self):
    146         self.UnfitHardpoints()
    147         self.FitHardpoints()
    148 
    149     def UnfitHardpoints(self):
    150         if not self.fitted:
    151             return
    152         self.logger.debug('Unfitting hardpoints')
    153         newModules = {}
    154         for key, val in self.modules.iteritems():
    155             if val not in self.turrets:
    156                 newModules[key] = val
    157 
    158         self.modules = newModules
    159         del self.turrets[:]
    160         self.fitted = False
    161 
    162     def FitHardpoints(self, blocking = False):
    163         if self.fitted:
    164             return
    165         if self.model is None:
    166             self.logger.warning('FitHardpoints - No model')
    167             return
    168         self.logger.debug('Fitting hardpoints')
    169         self.fitted = True
    170         newTurretSetDict = TurretSet.FitTurrets(self.id, self.model, self.typeData.get('sofFactionName', None))
    171         self.turrets = []
    172         for key, val in newTurretSetDict.iteritems():
    173             self.modules[key] = val
    174             self.turrets.append(val)
    175 
    176     def LookAtMe(self):
    177         if not self.model:
    178             return
    179         if not self.fitted:
    180             self.FitHardpoints()
    181 
    182     def StopStructureLoopAnimation(self):
    183         animationUpdater = self.GetStructureModel().animationUpdater
    184         if animationUpdater is not None:
    185             animationUpdater.PlayLayerAnimation('TrackMaskLayer1', 'Layer1Loop', False, 1, 0, 1, True)
    186 
    187     def IsValidSleep(self, delay):
    188         return delay < 86400000
    189 
    190     def BuildStructure(self, anchoringTime, elapsedTime):
    191         self.LoadUnLoadedModels()
    192         self.logger.debug('Structure: BuildStructure %s', self.GetTypeID())
    193         self.PreBuildingSteps()
    194         delay = int((anchoringTime - elapsedTime) * 1000)
    195         if self.IsValidSleep(delay):
    196             uthread.new(self._EndStructureBuild, delay)
    197         self.SetControllerVariable('BuildDuration', anchoringTime)
    198         self.SetControllerVariable('BuildElapsedTime', elapsedTime)
    199         self.SetControllerVariable('IsBuilt', True)
    200 
    201     def _EndStructureBuild(self, delay):
    202         blue.pyos.synchro.SleepSim(delay)
    203         if self.released or self.exploded:
    204             return
    205         self.PostBuildingSteps(True)
    206         self.SetupModel(False)
    207 
    208     def TearDownStructure(self, unanchoringTime, elapsedTime):
    209         self.LoadUnLoadedModels()
    210         self.logger.debug('Structure: TearDownStructure %s', self.GetTypeID())
    211         self.StopStructureLoopAnimation()
    212         self.PreBuildingSteps()
    213         delay = int((unanchoringTime - elapsedTime) * 1000)
    214         if self.IsValidSleep(delay):
    215             uthread.new(self._EndStructureTearDown, delay)
    216         self.SetControllerVariable('BuildDuration', unanchoringTime)
    217         self.SetControllerVariable('BuildElapsedTime', elapsedTime)
    218         self.SetControllerVariable('IsBuilt', False)
    219 
    220     def _EndStructureTearDown(self, delay):
    221         blue.pyos.synchro.SleepSim(delay)
    222         if self.released or self.exploded:
    223             return
    224         self.PostBuildingSteps(False)
    225         self.SetupModel(True)
    226 
    227     def PostSkinChangeCallback(self, oldModel, newModel):
    228         super(BuildableStructure, self).PostSkinChangeCallback(oldModel, newModel)
    229 
    230         def runInTasklet(func, *args):
    231             func(*args)
    232 
    233         self._OnSlimItemUpdated(self.typeData.get('slimItem'), runInTasklet)