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

stretchEffect.py (11506B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\stretchEffect.py
      2 import blue
      3 import geo2
      4 import trinity
      5 import uthread
      6 from eve.client.script.environment.effects.GenericEffect import GenericEffect, GetBoundingBox, STOP_REASON_DEFAULT, STOP_REASON_BALL_REMOVED
      7 
      8 class StretchEffect(GenericEffect):
      9     __guid__ = 'effects.StretchEffect'
     10 
     11     def Stop(self, reason = STOP_REASON_DEFAULT):
     12         if self.gfx is None:
     13             raise RuntimeError('StretchEffect: no effect defined: ' + str(getattr(self, 'graphicFile', 'None')))
     14         if self.gfx.curveSets is not None and len(self.gfx.curveSets) > 0:
     15             self.FadeOutAudio()
     16         self.RemoveFromScene(self.gfxModel)
     17         if isinstance(self.gfx.source, trinity.EveLocalPositionCurve):
     18             self.gfx.source.parentPositionCurve = None
     19             self.gfx.source.parentRotationCurve = None
     20             self.gfx.source.alignPositionCurve = None
     21         if isinstance(self.gfx.dest, trinity.EveLocalPositionCurve):
     22             self.gfx.dest.parentPositionCurve = None
     23             self.gfx.dest.parentRotationCurve = None
     24             self.gfx.dest.alignPositionCurve = None
     25         self.gfx = None
     26         self.gfxModel = None
     27 
     28     def Prepare(self):
     29         self.DoPrepare(trinity.EveLocalPositionBehavior.nearestBounds, trinity.EveLocalPositionBehavior.nearestBounds)
     30 
     31     def DoPrepare(self, sourceBehavior, destBehavior):
     32         shipBall = self.GetEffectShipBall()
     33         positionCurve = self.GetBallPositionCurve(shipBall)
     34         targetBall = self.GetEffectTargetBall()
     35         if shipBall is None:
     36             raise RuntimeError('StretchEffect: no ball found')
     37         if not getattr(shipBall, 'model', None):
     38             raise RuntimeError('StretchEffect: no model found')
     39         if targetBall is None:
     40             raise RuntimeError('StretchEffect: no target ball found')
     41         self.gfx = self.RecycleOrLoad(self.graphicFile)
     42         if self.gfx is None:
     43             raise RuntimeError('StretchEffect: no effect found: ' + str(getattr(self, 'graphicFile', 'None')))
     44         self.ScaleEffectAudioEmitters()
     45         self.gfxModel = self.gfx
     46         self.gfx.source = trinity.EveLocalPositionCurve(sourceBehavior)
     47         self.gfx.source.offset = self.sourceOffset
     48         self.gfx.dest = trinity.EveLocalPositionCurve(destBehavior)
     49         self.gfx.dest.offset = self.destinationOffset
     50         self.gfx.source.parentPositionCurve = positionCurve
     51         self.gfx.source.parentRotationCurve = shipBall
     52         self.gfx.source.alignPositionCurve = targetBall
     53         self.gfx.dest.parentPositionCurve = targetBall
     54         self.gfx.dest.parentRotationCurve = targetBall
     55         self.gfx.dest.alignPositionCurve = positionCurve
     56         sourceScale = GetBoundingBox(shipBall, scale=1.2)
     57         self.gfx.source.boundingSize = sourceScale
     58         targetScale = GetBoundingBox(targetBall, scale=1.2)
     59         self.gfx.dest.boundingSize = targetScale
     60         self.AddToScene(self.gfxModel)
     61 
     62     def Start(self, duration):
     63         if self.gfx is None:
     64             raise RuntimeError('StretchEffect: no effect defined: ' + str(getattr(self, 'graphicFile', 'None')))
     65         if self.gfx.curveSets is not None and len(self.gfx.curveSets) > 0:
     66             if self.scaleTime:
     67                 length = self.gfx.curveSets[0].GetMaxCurveDuration()
     68                 if length > 0.0:
     69                     scaleValue = length / (duration / 1000.0)
     70                     self.gfx.curveSets[0].scale = scaleValue
     71             self.gfx.Start()
     72 
     73     def FadeOutAudio(self):
     74         for curve in self.gfx.curveSets[0].curves:
     75             if curve.name.lower() in ('audioeventssource', 'audioeventsdest'):
     76                 if hasattr(curve, 'audioEmitter'):
     77                     curve.audioEmitter.SendEvent('fade_out')
     78 
     79     def Repeat(self, duration):
     80         if self.gfx is None:
     81             return
     82         if self.gfx.curveSets is not None and len(self.gfx.curveSets) > 0:
     83             self.FadeOutAudio()
     84             self.gfx.curveSets[0].Play()
     85 
     86     def ScaleEffectAudioEmitters(self):
     87         shipBall = self.GetEffectShipBall()
     88         targetBall = self.GetEffectTargetBall()
     89         if shipBall is None or targetBall is None:
     90             return
     91         srcRadius = shipBall.radius
     92         destRadius = targetBall.radius
     93         srcAudio = None
     94         destAudio = None
     95         if self.gfx.stretchObject and len(self.gfx.stretchObject.observers) > 0:
     96             srcAudio = self.gfx.stretchObject.observers[0].observer
     97         elif self.gfx.sourceObject and len(self.gfx.stretchObject.observers) > 0:
     98             srcAudio = self.gfx.sourceObject.observers[0].observer
     99         if self.gfx.destObject and len(self.gfx.destObject.observers) > 0:
    100             destAudio = self.gfx.destObject.observers[0].observer
    101         srcAttenuation = pow(srcRadius, 0.95) * 33
    102         destAttenuation = pow(destRadius, 0.95) * 33
    103         if srcAudio is not None and destAudio is not None:
    104             srcAudio.SetAttenuationScalingFactor(srcAttenuation)
    105             destAudio.SetAttenuationScalingFactor(destAttenuation)
    106 
    107 
    108 class LocatorStretchEffect(StretchEffect):
    109     __guid__ = 'effects.StretchEffect'
    110 
    111     @property
    112     def destinationBehaviour(self):
    113         return trinity.EveLocalPositionBehavior.damageLocator
    114 
    115     def Prepare(self):
    116         shipBall = self.GetEffectShipBall()
    117         positionCurve = self.GetBallPositionCurve(shipBall)
    118         targetBall = self.GetEffectTargetBall()
    119         if shipBall is None:
    120             raise RuntimeError('LocatorStretchEffect: no ball found')
    121         if not getattr(shipBall, 'model', None):
    122             raise RuntimeError('LocatorStretchEffect: no model found')
    123         if targetBall is None:
    124             raise RuntimeError('LocatorStretchEffect: no target ball found')
    125         if not getattr(targetBall, 'model', None):
    126             raise RuntimeError('LocatorStretchEffect: no target model found')
    127         self.gfx = self.RecycleOrLoad(self.graphicFile)
    128         if self.gfx is None:
    129             raise RuntimeError('StretchEffect: no effect found: ' + str(getattr(self, 'graphicFile', 'None')))
    130         self.ScaleEffectAudioEmitters()
    131         self.gfxModel = self.gfx
    132         sourceBehavior = trinity.EveLocalPositionBehavior.nearestBounds
    133         self.gfx.source = trinity.EveLocalPositionCurve(sourceBehavior)
    134         self.gfx.dest = trinity.EveLocalPositionCurve(self.destinationBehaviour)
    135         self.gfx.source.parentPositionCurve = positionCurve
    136         self.gfx.source.parentRotationCurve = shipBall
    137         self.gfx.source.alignPositionCurve = self.gfx.dest
    138         self.gfx.dest.parent = targetBall.model
    139         self.gfx.dest.alignPositionCurve = positionCurve
    140         sourceScale = GetBoundingBox(shipBall, scale=1.2)
    141         self.gfx.source.boundingSize = sourceScale
    142         self.AddToScene(self.gfxModel)
    143 
    144     def Stop(self, reason = STOP_REASON_DEFAULT):
    145         if self.gfx is None:
    146             return
    147         if self.gfx.curveSets is not None and len(self.gfx.curveSets) > 0:
    148             self.FadeOutAudio()
    149         self.RemoveFromScene(self.gfxModel)
    150         self.gfx.source.parentPositionCurve = None
    151         self.gfx.source.parentRotationCurve = None
    152         self.gfx.source.alignPositionCurve = None
    153         self.gfx.source = None
    154         self.gfx.dest.parent = None
    155         self.gfx.dest.alignPositionCurve = None
    156         self.gfx.dest = None
    157         self.gfx = None
    158         self.gfxModel = None
    159 
    160 
    161 class LocatorStretchEffectSwitching(LocatorStretchEffect):
    162     __guid__ = 'effects.StretchEffect'
    163 
    164     @LocatorStretchEffect.destinationBehaviour.getter
    165     def destinationBehaviour(self):
    166         return trinity.EveLocalPositionBehavior.damageLocator
    167 
    168     def Repeat(self, duration):
    169         if self.gfx is None:
    170             return
    171         shipBall = self.GetEffectShipBall()
    172         targetBall = self.GetEffectTargetBall()
    173         if targetBall is None or shipBall is None:
    174             self.Stop(STOP_REASON_BALL_REMOVED)
    175             return
    176         positionCurve = self.GetBallPositionCurve(shipBall)
    177         self.gfx.dest = trinity.EveLocalPositionCurve(self.destinationBehaviour)
    178         self.gfx.dest.parent = targetBall.model
    179         self.gfx.dest.alignPositionCurve = positionCurve
    180 
    181 
    182 class TurretStretchEffect(StretchEffect):
    183     __guid__ = 'effects.TurretStretchEffect'
    184 
    185     def __init__(self, trigger, effect = None, graphicFile = None):
    186         StretchEffect.__init__(self, trigger, effect, graphicFile)
    187         self.delayUntilDamageApplied = 13750.0
    188 
    189     def Prepare(self):
    190         StretchEffect.Prepare(self)
    191         shipBall = self.GetEffectShipBall()
    192         targetBall = self.GetEffectTargetBall()
    193         turret = shipBall.modules.get(self.moduleID, None)
    194         if turret is None:
    195             raise RuntimeError("StretchEffect: No module '%s' found" % self.moduleID)
    196         turretSet = turret.GetTurretSet()
    197         firingBoneWorldTransform = turretSet.GetFiringBoneWorldTransform(0)
    198         _, __, offsetPosition = geo2.MatrixDecompose(firingBoneWorldTransform)
    199         sourceOffsetCurve = trinity.Tr2TranslationAdapter()
    200         sourceOffsetCurve.value = offsetPosition
    201         self.gfx.source = sourceOffsetCurve
    202         destBehavior = trinity.EveLocalPositionBehavior.damageLocator
    203         self.gfx.dest = trinity.EveLocalPositionCurve(destBehavior)
    204         self.gfx.dest.parent = targetBall.model
    205         self.gfx.dest.alignPositionCurve = shipBall
    206         uthread.new(self.CreateImpact, targetBall, offsetPosition)
    207 
    208     def CreateImpact(self, targetBall, source):
    209         blue.synchro.Sleep(100)
    210         damageDuration = 3000
    211         targetPos = targetBall.GetVectorAt(blue.os.GetSimTime())
    212         target = geo2.Vector(targetPos.x, targetPos.y, targetPos.z)
    213         direction = geo2.Vec3Normalize(geo2.Vec3Subtract(source, target))
    214         targetBall.model.CreateImpact(self.gfx.dest.damageLocatorIndex, direction, damageDuration * 0.001, 2.0)
    215 
    216 
    217 class DamageLocatorToDamageLocatorStretchEffect(StretchEffect):
    218     __guid__ = 'effects.DamageLocatorToDamageLocatorStretchEffect'
    219 
    220     def Prepare(self):
    221         StretchEffect.Prepare(self)
    222         self.gfxModel.source.behavior = trinity.EveLocalPositionBehavior.damageLocator
    223         self.gfxModel.source.parent = self.GetEffectShipBall().model
    224         self.gfxModel.dest.behavior = trinity.EveLocalPositionBehavior.damageLocator
    225         self.gfxModel.dest.parent = self.GetEffectTargetBall().model
    226         p = self.GetEffectShipBall().GetVectorAt(blue.os.GetSimTime())
    227         sourcePos = geo2.Vector(p.x, p.y, p.z)
    228         p = self.GetEffectTargetBall().GetVectorAt(blue.os.GetSimTime())
    229         targetPos = geo2.Vector(p.x, p.y, p.z)
    230         sourceToTargetDir = geo2.Vec3Direction(sourcePos, targetPos)
    231         uthread.new(self.CreateImpact, sourceToTargetDir)
    232 
    233     def CreateImpact(self, sourceToTargetDir):
    234         blue.synchro.Sleep(50)
    235         damageDuration = 3000
    236         targetToSourceDir = geo2.Vec3Scale(sourceToTargetDir, -1)
    237         self.GetEffectTargetBall().model.CreateImpact(self.gfx.dest.damageLocatorIndex, sourceToTargetDir, damageDuration * 0.001, 2.0)
    238         self.GetEffectShipBall().model.CreateImpact(self.gfx.source.damageLocatorIndex, targetToSourceDir, damageDuration * 0.001, 2.0)
    239 
    240 
    241 class BoundsToCenterStretchEffect(StretchEffect):
    242     __guid__ = 'effects.BoundsToCenterStretchEffect'
    243 
    244     def Prepare(self):
    245         self.DoPrepare(trinity.EveLocalPositionBehavior.nearestBounds, trinity.EveLocalPositionBehavior.offsetPosition)