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

playerOwnedStructure.py (7337B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\spaceObject\playerOwnedStructure.py
      2 from carbon.common.lib.const import SEC
      3 import blue
      4 import uthread
      5 import eve.common.lib.appConst as const
      6 from eve.client.script.environment.spaceObject.buildableStructure import BuildableStructure
      7 import eve.common.script.mgt.posConst as pos
      8 CONSTRUCTION_MATERIAL = 'res:/Texture/MinmatarShared/Gradientbuild.dds'
      9 ONLINE_GLOW_OFF = (0.0, 0.0, 0.0)
     10 ONLINE_GLOW_MID = (0.004, 0.0, 0.0)
     11 CONTROL_TOWER = 'control_tower_type'
     12 PLAYER_OWNED_STRUCTURE = 'player_owned_structure_type'
     13 PLAY_EVENT = 'play_event_type'
     14 STOP_EVENT = 'stop_event_type'
     15 STATE_NONE = None
     16 STATE_UNBUILT = 'Unbuilt'
     17 STATE_OFFLINE = 0
     18 STATE_ONLINING = 1
     19 STATE_ONLINE = 2
     20 STATE_BUILT = 'Built'
     21 STATE_BUILDING = 'Building'
     22 STATE_TEARDOWN = 'TearDown'
     23 POS_STATES_TO_STATE = {pos.STRUCTURE_UNANCHORED: STATE_NONE,
     24  pos.STRUCTURE_ANCHORED: STATE_OFFLINE,
     25  pos.STRUCTURE_ONLINING: STATE_ONLINING,
     26  pos.STRUCTURE_REINFORCED: STATE_ONLINE,
     27  pos.STRUCTURE_ONLINE: STATE_ONLINE,
     28  pos.STRUCTURE_OPERATING: STATE_ONLINE,
     29  pos.STRUCTURE_VULNERABLE: STATE_ONLINE,
     30  pos.STRUCTURE_SHIELD_REINFORCE: STATE_ONLINE,
     31  pos.STRUCTURE_ARMOR_REINFORCE: STATE_ONLINE,
     32  pos.STRUCTURE_INVULNERABLE: STATE_ONLINE}
     33 POS_STATE_SOUNDS = {STATE_ONLINE: {CONTROL_TOWER: 'msg_ct_online_play',
     34                 PLAYER_OWNED_STRUCTURE: 'msg_pos_online_play'},
     35  STATE_OFFLINE: {CONTROL_TOWER: 'msg_ct_offline_play',
     36                  PLAYER_OWNED_STRUCTURE: 'msg_pos_offline_play'},
     37  STATE_BUILDING: {PLAY_EVENT: 'building_effect_play',
     38                   STOP_EVENT: 'building_effect_stop'},
     39  STATE_TEARDOWN: {PLAY_EVENT: 'building_teardown_effect_play',
     40                   STOP_EVENT: 'building_teardown_effect_stop'}}
     41 
     42 class PlayerOwnedStructure(BuildableStructure):
     43 
     44     def OnSlimItemUpdated(self, slimItem):
     45         oldPosState = self.GetPosState()
     46         newPosState = getattr(slimItem, 'posState', STATE_NONE)
     47         if newPosState is None or oldPosState == newPosState:
     48             return
     49         self.typeData['slimItem'].posState = newPosState
     50         self.PlaySounds(oldPosState, newPosState)
     51         if oldPosState == pos.STRUCTURE_ANCHORED and newPosState == pos.STRUCTURE_UNANCHORED or oldPosState == pos.STRUCTURE_UNANCHORED and newPosState == pos.STRUCTURE_ANCHORED:
     52             return
     53         uthread.new(self.LoadModel)
     54 
     55     def GetAnimationState(self, posState):
     56         return POS_STATES_TO_STATE.get(posState, STATE_NONE)
     57 
     58     def GetPosState(self):
     59         slimItem = self.typeData['slimItem']
     60         return getattr(slimItem, 'posState', None)
     61 
     62     def PlayStateSound(self, state, eventType):
     63         event = None
     64         state_events = POS_STATE_SOUNDS.get(state, None)
     65         if state_events is not None:
     66             event = state_events.get(eventType, None)
     67         if event is not None:
     68             self.PlayGeneralAudioEvent(event)
     69         else:
     70             self.logger.warning('PlayerOwnedStructure: No event found for state: %s of type: %s', state, eventType)
     71 
     72     def PlaySounds(self, oldState, posState):
     73         structure_type = CONTROL_TOWER if self.IsControlTower() else PLAYER_OWNED_STRUCTURE
     74         if oldState == pos.STRUCTURE_ONLINING and posState == pos.STRUCTURE_ONLINE:
     75             self.PlayStateSound(STATE_ONLINE, structure_type)
     76         elif oldState == pos.STRUCTURE_ONLINE and posState == pos.STRUCTURE_ANCHORED:
     77             self.PlayStateSound(STATE_OFFLINE, structure_type)
     78 
     79     def LoadModel(self, fileName = None, loadedModel = None):
     80         animationState = self.GetAnimationState(self.GetPosState())
     81         self.SetupModel(animationState is STATE_NONE and not self.IsAnchored())
     82         self.Assemble()
     83         if animationState is not STATE_NONE and not self.isConstructing:
     84             self.SetControllerVariable('posState', animationState)
     85         self.SetStaticRotation()
     86 
     87     def Assemble(self):
     88         slimItem = self.typeData.get('slimItem')
     89         if slimItem.groupID == const.groupMoonMining:
     90             direction = self.FindClosestMoonDir()
     91             self.AlignToDirection(direction)
     92 
     93     def Release(self, origin = None):
     94         self.PlayGeneralAudioEvent('fade_out')
     95         BuildableStructure.Release(self, origin)
     96 
     97     def StartBuildingEffect(self, isBuilding, dogmaBuildingLength, elapsedTime):
     98         curveLength = 1.0 * dogmaBuildingLength / 1000.0
     99         elapsedTime = 1.0 * elapsedTime / SEC
    100         self.PreBuildingSteps()
    101         if self.model.controllers and not self.model.controllers[0].isPlaying:
    102             self.SetControllerVariable('IsBuilt', not isBuilding)
    103             self.model.StartControllers()
    104         self.SetControllerVariable('BuildDuration', curveLength)
    105         self.SetControllerVariable('BuildElapsedTime', elapsedTime)
    106         self.SetControllerVariable('IsBuilt', isBuilding)
    107         uthread.new(self.EndBuildingEffect, isBuilding, int((curveLength - elapsedTime) * 1000))
    108         self.PlayStateSound(isBuilding, PLAY_EVENT)
    109 
    110     def EndBuildingEffect(self, isBuilding, delay):
    111         blue.pyos.synchro.SleepSim(delay)
    112         if self.released or self.exploded:
    113             return
    114         requiredFreeValue = isBuilding
    115         while self.isFree == requiredFreeValue:
    116             self.logger.debug('PlayerOwnedStructure: Yielding until self.isFree is correct')
    117             blue.synchro.Yield()
    118 
    119         self.PostBuildingSteps(isBuilding)
    120         self.PlayStateSound(STATE_BUILDING if isBuilding else STATE_TEARDOWN, STOP_EVENT)
    121         self.LoadModel()
    122 
    123     def BeginStructureAnchoring(self, timeSinceStart):
    124         self.LoadUnLoadedModels()
    125         self.logger.debug('PlayerOwnedStructure: BeginStructureAnchoring %s', self.GetTypeID())
    126         buildingLength = sm.GetService('godma').GetType(self.GetTypeID()).anchoringDelay
    127         self.StartBuildingEffect(True, buildingLength, timeSinceStart)
    128         self.PlaySounds(pos.STRUCTURE_UNANCHORED, pos.STRUCTURE_ANCHORED)
    129 
    130     def BeginStructureUnAnchoring(self, timeSinceStart):
    131         self.LoadUnLoadedModels()
    132         self.logger.debug('PlayerOwnedStructure: BeginStructureUnAnchoring %s', self.GetTypeID())
    133         godmaType = sm.GetService('godma').GetType(self.GetTypeID())
    134         if godmaType.AttributeExists('unanchoringDelay'):
    135             buildingLength = godmaType.unanchoringDelay
    136         else:
    137             buildingLength = godmaType.anchoringDelay
    138         self.StartBuildingEffect(False, buildingLength, timeSinceStart)
    139         self.PlaySounds(pos.STRUCTURE_ANCHORED, pos.STRUCTURE_UNANCHORED)
    140 
    141     def IsControlTower(self):
    142         slimItem = self.typeData.get('slimItem')
    143         if slimItem is not None:
    144             groupID = self.typeData.get('groupID')
    145             return groupID == const.groupControlTower
    146         return False
    147 
    148     def IsAnchored(self):
    149         self.logger.debug('PlayerOwnedStructure: Anchor State = %s', not self.isFree)
    150         return not self.isFree
    151 
    152     def IsOnline(self):
    153         slimItem = self.typeData.get('slimItem')
    154         res = self.sm.GetService('pwn').GetStructureState(slimItem)[0] in ('online', 'invulnerable', 'vulnerable', 'reinforced')
    155         self.logger.debug('PlayerOwnedStructure: Online State = %s', res)
    156         return res
    157 
    158     def OnlineAnimation(self, animate = 0):
    159         pass
    160 
    161     def OfflineAnimation(self, animate = 0):
    162         pass