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

EMPWave.py (4983B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\EMPWave.py
      2 from eve.client.script.environment.effects.GenericEffect import GenericEffect, STOP_REASON_DEFAULT, STOP_REASON_BALL_REMOVED
      3 import trinity
      4 import audio2
      5 import uthread
      6 import evetypes
      7 import blue
      8 from fsdBuiltData.common.graphicIDs import GetGraphicFile
      9 from eve.common.lib import appConst as const
     10 
     11 class EMPWave(GenericEffect):
     12     __guid__ = 'effects.EMPWave'
     13 
     14     def __init__(self, trigger, *args):
     15         GenericEffect.__init__(self, trigger, *args)
     16         self.ballIDs = [trigger.shipID]
     17         self.gfx = None
     18         self.gfxModel = None
     19         self.radius = 5000.0
     20         self.moduleTypeID = trigger.moduleTypeID
     21         self.translationCurve = None
     22         self.trigger = trigger
     23         self.ballpark = sm.GetService('michelle').GetBallpark()
     24 
     25     def Stop(self, reason = STOP_REASON_DEFAULT):
     26         if self.gfx is None:
     27             raise RuntimeError('ShipEffect: no effect defined')
     28         scene = self.fxSequencer.GetScene()
     29         scene.objects.fremove(self.gfxModel)
     30         self.gfx = None
     31         self.translationCurve = None
     32         self.gfxModel = None
     33 
     34     def Prepare(self):
     35         shipID = self.ballIDs[0]
     36         shipBall = self.fxSequencer.GetBall(shipID)
     37         if shipBall is None:
     38             raise RuntimeError('EMPWave: no ball found')
     39         if self.moduleTypeID == 0:
     40             self.moduleTypeID = 15957
     41         graphicID = evetypes.GetGraphicID(self.moduleTypeID)
     42         if self.graphicInfo is not None and self.graphicInfo.graphicID:
     43             graphicID = self.graphicInfo.graphicID
     44         if graphicID is None:
     45             raise RuntimeError('EMPWave: no graphic ID')
     46         gfxString = GetGraphicFile(graphicID)
     47         self.gfx = trinity.Load(gfxString)
     48         if self.gfx is None:
     49             raise RuntimeError('EMPWave: no effect found')
     50         entity = audio2.AudEmitter('effect_' + str(shipID))
     51         obs = trinity.TriObserverLocal()
     52         obs.observer = entity
     53         if self.gfx.__bluetype__ in ('trinity.EveTransform',):
     54             self.gfx.observers.append(obs)
     55         for curveSet in self.gfx.curveSets:
     56             for curve in curveSet.curves:
     57                 if curve.__typename__ == 'TriEventCurve' and curve.name == 'audioEvents':
     58                     curve.eventListener = entity
     59 
     60         self.gfxModel = trinity.EveRootTransform()
     61         radius = self.fxSequencer.GetTypeAttribute(self.moduleTypeID, const.attributeEmpFieldRange)
     62         self.gfxModel.scaling = (radius / 1000, radius / 1000, radius / 1000)
     63         self.radius = radius
     64         self.gfxModel.name = self.__guid__
     65         self.gfxModel.children.append(self.gfx)
     66         self.gfxModel.translationCurve = shipBall
     67         scene = self.fxSequencer.GetScene()
     68         scene.objects.append(self.gfxModel)
     69 
     70     def Start(self, duration):
     71         if self.gfx is None:
     72             raise RuntimeError('ShipEffect: no effect defined')
     73         if self.scaleTime and len(self.gfxModel.curveSets) > 0:
     74             length = self.gfxModel.curveSets[0].GetMaxCurveDuration()
     75             if length > 0.0:
     76                 scaleValue = length / (duration / 1000.0)
     77                 self.gfxModel.curveSets[0].scale = scaleValue
     78         self.gfx.curveSets[0].Play()
     79         self.ApplyImpactEffectToTargets()
     80 
     81     def ApplyImpactEffectToTargets(self):
     82         sourceBall = sm.GetService('michelle').GetBall(self.ballIDs[0])
     83         targetIDs = self.ballpark.GetBallsInRange(self.trigger.shipID, self.radius)
     84         for targetId in targetIDs:
     85             targetBall = sm.GetService('michelle').GetBall(targetId)
     86             if getattr(targetBall, 'model', None) is not None:
     87                 uthread.new(self.ApplyImpactEffectToSingleTarget, sourceBall, targetBall)
     88 
     89     def ApplyImpactEffectToSingleTarget(self, sourceBall, targetBall):
     90         if targetBall is None or targetBall.model is None or not hasattr(targetBall.model, 'CreateImpactFromPosition'):
     91             return
     92         distance = self.ballpark.DistanceBetween(targetBall.id, sourceBall.id)
     93         if distance > self.radius:
     94             return
     95         timeUntilImpact = 500 * distance / self.radius
     96         blue.synchro.SleepSim(timeUntilImpact)
     97         if targetBall is None or targetBall.model is None:
     98             return
     99         source = sourceBall.GetVectorAt(blue.os.GetSimTime())
    100         target = targetBall.GetVectorAt(blue.os.GetSimTime())
    101         direction = source - target
    102         direction.Normalize()
    103         targetBall.model.CreateImpactFromPosition((source.x, source.y, source.z), (direction.x, direction.y, direction.z), 1, 1)
    104 
    105     def Repeat(self, duration):
    106         if self.gfx is None:
    107             return
    108         shipID = self.ballIDs[0]
    109         shipBall = self.fxSequencer.GetBall(shipID)
    110         if shipBall is None:
    111             self.Stop(STOP_REASON_BALL_REMOVED)
    112         self.gfx.curveSets[0].Play()
    113         self.ApplyImpactEffectToTargets()