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

WarpFlash.py (10763B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\WarpFlash.py
      2 from eve.client.script.environment.effects.GenericEffect import GenericEffect, STOP_REASON_DEFAULT, STOP_REASON_BALL_REMOVED
      3 import destiny
      4 import geo2
      5 import trinity
      6 import blue
      7 import uthread
      8 import random
      9 
     10 class WarpFlashIn(GenericEffect):
     11     _bigGlows = 0
     12 
     13     def __init__(self, trigger, *args):
     14         GenericEffect.__init__(self, trigger, *args)
     15         self.gfxBall = None
     16         self.gfxModel = None
     17         self.gfxModel_ship = None
     18         self.observer = None
     19 
     20     def Prepare(self, addToScene = True):
     21         shipBall = self.GetEffectShipBall()
     22         if WarpFlashIn._bigGlows < 5:
     23             gfx = trinity.Load('res:/fisfx/jump/warp/warp_in_glow.red')
     24             WarpFlashIn._bigGlows += 1
     25             self.useBigGlow = True
     26         else:
     27             gfx = trinity.Load('res:/fisfx/jump/warp/warp_in_noglow.red')
     28             self.useBigGlow = False
     29         if gfx is None:
     30             return
     31         self.gfx = gfx
     32         model = getattr(shipBall, 'model', None)
     33         if model is None:
     34             return
     35         s = 0.7778 * model.GetBoundingSphereRadius() ** 0.3534
     36         self.gfx.scaling = (s, s, s)
     37         self.gfx_ship = trinity.Load('res:/fisfx/jump/warp/warp_glow.red')
     38 
     39         def _glowScale(x):
     40             return 9e-08 * x * x + 0.005 * x + 0.6898
     41 
     42         self.gfxModel_ship = trinity.EveRootTransform()
     43         self.gfxModel_ship.children.append(self.gfx_ship)
     44         r = 0.125 * _glowScale(model.boundingSphereRadius)
     45         self.gfxModel_ship.scaling = (r, r, r * 3)
     46         self.soundEvent = 'warp_in_frig_play'
     47         if model.GetBoundingSphereRadius() > 350:
     48             self.soundEvent = 'warp_in_battle_play'
     49         self.AddSoundToEffect(0.001)
     50 
     51     def Start(self, duration):
     52         shipBall = self.GetEffectShipBall()
     53         if shipBall is None or not self._IsAtWarpInAcceleration(shipBall):
     54             if self.useBigGlow:
     55                 WarpFlashIn._bigGlows -= 1
     56             self._Cleanup()
     57             return
     58         uthread.new(self._RunEffect)
     59 
     60     def _IsAtWarpInAcceleration(self, ball):
     61         a = ball.GetVectorDoubleDotAt(blue.os.GetSimTime())
     62         a = (a.x, a.y, a.z)
     63         return geo2.Vec3Length(a) > 5000.0
     64 
     65     def _WaitForDecceleration(self, limit = 215000.0):
     66         shipBall = self.GetEffectShipBall()
     67         speedL = 0
     68         timeL = blue.os.GetSimTime()
     69         acc = None
     70         while True:
     71             timeN = blue.os.GetSimTime()
     72             v = shipBall.GetVectorDotAt(timeN)
     73             speed = geo2.Vec3Length((v.x, v.y, v.z))
     74             timeDiffSec = blue.os.TimeDiffInMs(timeL, timeN) / 1000.0
     75             if timeDiffSec != 0.0:
     76                 acc = (speed - speedL) / timeDiffSec
     77             speedL = speed
     78             timeL = timeN
     79             if acc is not None and acc > -limit:
     80                 break
     81             blue.synchro.Yield()
     82 
     83         return speedL
     84 
     85     def _RunEffect(self):
     86         shipBall = self.GetEffectShipBall()
     87         if shipBall is None:
     88             self._Cleanup()
     89             return
     90         self._WaitForDecceleration()
     91         posNow = shipBall.GetVectorAt(blue.os.GetSimTime())
     92         posNow = (posNow.x, posNow.y, posNow.z)
     93         self.gfxBall = self._SpawnClientBall(posNow)
     94         for each in self.gfx.Find('trinity.EveTransform'):
     95             each.useLodLevel = False
     96 
     97         self.gfxModel = trinity.EveRootTransform()
     98         self.gfxModel.children.append(self.gfx)
     99         self.gfxModel.translationCurve = self.gfxBall
    100         if self.graphicInfo != 'npc':
    101             blue.synchro.SleepSim(random.random() * 200.0)
    102         shipBall = self.GetEffectShipBall()
    103         if shipBall is None:
    104             self._Cleanup()
    105             return
    106         self.AddToScene(self.gfxModel)
    107         self.gfx.curveSets[0].Play()
    108         self.observer.observer.SendEvent(self.soundEvent)
    109         self.gfxModel_ship.translationCurve = shipBall
    110         self.gfxModel_ship.rotationCurve = shipBall
    111         self.AddToScene(self.gfxModel_ship)
    112         self.gfx_ship.curveSets[0].Play()
    113         if self.useBigGlow:
    114             blue.synchro.SleepSim(300.0)
    115             WarpFlashIn._bigGlows -= 1
    116             blue.synchro.SleepSim(2700.0)
    117         else:
    118             blue.synchro.SleepSim(3000.0)
    119         self._Cleanup()
    120 
    121     def _Cleanup(self):
    122         if self.gfxBall is not None:
    123             self._DestroyClientBall(self.gfxBall)
    124             self.gfxBall = None
    125         if self.gfxModel is not None:
    126             self.RemoveFromScene(self.gfxModel)
    127             self.gfxModel = None
    128         if self.gfxModel_ship is not None:
    129             self.RemoveFromScene(self.gfxModel_ship)
    130             self.gfxModel_ship = None
    131         if self.observer is not None:
    132             self.observer.observer = None
    133             self.observer = None
    134         self.gfx_ship = None
    135         self.gfx = None
    136 
    137 
    138 class WarpFlashOut(GenericEffect):
    139     __guid__ = 'effects.WarpFlashOut'
    140 
    141     def __init__(self, trigger, *args):
    142         GenericEffect.__init__(self, trigger, *args)
    143         self.gfxModel_ship = None
    144         self.gfxModel_trace = None
    145         self.startPos = (0, 0, 0)
    146         self.lastPos = (0, 0, 0)
    147         self.gotStopCommand = False
    148         self.abort = False
    149         self.direction = (0, 0, 1)
    150         self.gfxBall = None
    151         self.observer = None
    152         self.isShortWarp = False
    153 
    154     def Prepare(self, addToScene = True):
    155         shipBall = self.GetEffectShipBall()
    156         self.isShortWarp = self._IsShortWarp(shipBall)
    157         if self.isShortWarp:
    158             return
    159         model = getattr(shipBall, 'model', None)
    160         if model is None:
    161             return
    162         self.startPos = shipBall.GetVectorAt(blue.os.GetSimTime())
    163         self.startPos = (self.startPos.x, self.startPos.y, self.startPos.z)
    164         self.lastPos = self.startPos
    165 
    166         def _sizeFunction(x):
    167             return 0.0039 * x + 2.5
    168 
    169         r = _sizeFunction(model.boundingSphereRadius)
    170         self.gfx_trace = trinity.Load('res:/fisfx/jump/warp/warp_out.red')
    171         self.gfxModel_trace = trinity.EveRootTransform()
    172         self.gfxModel_trace.children.append(self.gfx_trace)
    173         self.gfxModel_trace.scaling = (r, r, 8)
    174         self.gfx_ship = trinity.Load('res:/fisfx/jump/warp/warp_glow.red')
    175         self.gfxModel_ship = trinity.EveRootTransform()
    176         self.gfxModel_ship.children.append(self.gfx_ship)
    177         r *= 0.5
    178         self.gfxModel_ship.scaling = (r, r, 6)
    179         self.soundInsert = 'frig'
    180         if model.boundingSphereRadius > 350:
    181             self.soundInsert = 'battle'
    182         self.gfx = self.gfx_trace
    183         self.AddSoundToEffect(0.0007)
    184 
    185     def _IsShortWarp(self, ball):
    186         pos0 = (ball.x, ball.y, ball.z)
    187         pos1 = (ball.gotoX, ball.gotoY, ball.gotoZ)
    188         d = geo2.Vec3DistanceSq(pos0, pos1)
    189         return d < 1600000000000000.0
    190 
    191     def _WaitForAcceleration(self, accT = 215000.0):
    192         shipBall = self.GetEffectShipBall()
    193         shipPosL = shipBall.GetVectorAt(blue.os.GetSimTime())
    194         shipPosL = (shipPosL.x, shipPosL.y, shipPosL.z)
    195         speedL = 0
    196         timeL = blue.os.GetSimTime()
    197         acc = 0
    198         while not self.abort:
    199             timeN = blue.os.GetSimTime()
    200             v = shipBall.GetVectorDotAt(timeN)
    201             speed = geo2.Vec3Length((v.x, v.y, v.z))
    202             shipPos = shipBall.GetVectorAt(blue.os.GetSimTime())
    203             shipPos = (shipPos.x, shipPos.y, shipPos.z)
    204             self.direction = geo2.Vec3Subtract(shipPos, shipPosL)
    205             shipPosL = shipPos
    206             timeDiffSec = blue.os.TimeDiffInMs(timeL, timeN) / 1000.0
    207             if timeDiffSec != 0.0:
    208                 acc = (speed - speedL) / timeDiffSec
    209             speedL = speed
    210             timeL = timeN
    211             if acc > accT:
    212                 break
    213             blue.synchro.Yield()
    214 
    215         return speedL
    216 
    217     def _IsWarpingWithClient(self, speed):
    218         playerBall = self.fxSequencer.GetBall(session.shipid)
    219         if playerBall is None or playerBall.mode != destiny.DSTBALL_WARP:
    220             return False
    221         velo = playerBall.GetVectorDotAt(blue.os.GetSimTime())
    222         velo = (velo.x, velo.y, velo.z)
    223         playerSpeed = geo2.Vec3Length(velo)
    224         if playerSpeed == 0.0:
    225             return False
    226         return abs((playerSpeed - speed) / playerSpeed) < 0.1
    227 
    228     def _RunEffect(self):
    229         shipBall = self.GetEffectShipBall()
    230         if self.abort or shipBall is None:
    231             self._Cleanup()
    232             return
    233         speed = self._WaitForAcceleration(310000.0)
    234         if self.abort or self._IsWarpingWithClient(speed):
    235             self._Cleanup()
    236             return
    237         blue.synchro.SleepSim(random.random() * 250.0)
    238         direction = geo2.Vec3Normalize(self.direction)
    239         rotation = geo2.QuaternionRotationArc((0, 0, 1), direction)
    240         if self.abort:
    241             return
    242         posNow = shipBall.GetVectorAt(blue.os.GetSimTime())
    243         posNow = (posNow.x, posNow.y, posNow.z)
    244         self.gfxBall = self._SpawnClientBall(posNow)
    245         if self.gfxModel_trace is not None:
    246             soundEvent = 'warp_out_%s1_play' % (self.soundInsert,)
    247             self.observer.observer.SendEvent(soundEvent)
    248             self.gfxModel_trace.translationCurve = self.gfxBall
    249             self.gfxModel_trace.rotation = rotation
    250             self.AddToScene(self.gfxModel_trace)
    251             for each in self.gfx_trace.curveSets:
    252                 each.Play()
    253 
    254             self.gfxModel_ship.translationCurve = shipBall
    255             self.gfxModel_ship.rotation = rotation
    256             self.AddToScene(self.gfxModel_ship)
    257             for each in self.gfx_ship.curveSets:
    258                 each.Play()
    259 
    260         if shipBall.model is not None:
    261             shipBall.model.display = False
    262         blue.synchro.SleepSim(1500.0)
    263         self._Cleanup()
    264 
    265     def _Cleanup(self):
    266         if self.gfxBall is not None:
    267             self._DestroyClientBall(self.gfxBall)
    268             self.gfxBall = None
    269         self.gfxModel_start = None
    270         if self.gfxModel_trace is not None:
    271             self.RemoveFromScene(self.gfxModel_trace)
    272             self.gfxModel_trace = None
    273         self.gfx_trace = None
    274         if self.gfxModel_ship is not None:
    275             self.RemoveFromScene(self.gfxModel_ship)
    276             self.gfxModel_ship = None
    277         self.gfx_ship = None
    278         self.gfx = None
    279         if self.observer is not None:
    280             self.observer.observer = None
    281             self.observer = None
    282 
    283     def Start(self, duration):
    284         if self.isShortWarp:
    285             return
    286         uthread.new(self._RunEffect)
    287 
    288     def Stop(self, reason = STOP_REASON_DEFAULT):
    289         if reason == STOP_REASON_BALL_REMOVED:
    290             self.abort = True
    291             self._Cleanup()