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

StellarHarvester.py (6868B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\StellarHarvester.py
      2 import trinity
      3 import geo2
      4 import blue
      5 from eve.client.script.environment.effects.GenericEffect import GenericEffect, STOP_REASON_DEFAULT
      6 
      7 class StellarHarvester(GenericEffect):
      8     __guid__ = 'effects.StellarHarvester'
      9 
     10     def __init__(self, trigger, effect = None, graphicFile = None):
     11         super(StellarHarvester, self).__init__(trigger, effect, graphicFile)
     12         self.sunRotComponent = None
     13         self.sunSuckerZScaleComponent = None
     14         self.graphicFile = 'res:/fisfx/module/tg_starharvestinglaser_st_01a.red'
     15         self.secondaryGraphicFile = 'res:/fisfx/environment/celestial/multieffect/small_blue_star_stages_multieffect.red'
     16 
     17     def Stop(self, reason = STOP_REASON_DEFAULT):
     18         if self.gfx is None:
     19             raise RuntimeError('StellarHarvester: no effect defined: ' + str(getattr(self, 'graphicFile', 'None')))
     20         if hasattr(self, 'gfx'):
     21             self.RemoveFromScene(self.gfx)
     22         if hasattr(self, 'flickerEffect'):
     23             self.RemoveFromScene(self.flickerEffect)
     24         self.flickerEffect = None
     25         self.gfx.source = None
     26         self.gfx.dest = None
     27         self.gfx.sourceObject = None
     28         self.gfx = None
     29         self.gfxModel = None
     30         if self.sunSuckerZScaleComponent is not None:
     31             tmp = self.sunSuckerZScaleComponent.scaling
     32             self.sunSuckerZScaleComponent.scaling = (tmp[0], tmp[1], 0.0)
     33         self.sunRotComponent = None
     34         self.sunSuckerZScaleComponent = None
     35 
     36     def IsExplodingSystem(self, solarsystemID):
     37         explodingSystems = [30002086]
     38         return solarsystemID in explodingSystems
     39 
     40     def Prepare(self):
     41         self.DoPrepare()
     42 
     43     def DoPrepare(self):
     44         harvesterBall = self.GetEffectShipBall()
     45         scm = sm.GetService('sceneManager')
     46         scene = scm.GetRegisteredScene('default')
     47         targetBall = scene.sunBall if scene else None
     48         self.gfx = self.RecycleOrLoad(self.graphicFile)
     49         if harvesterBall is None:
     50             raise RuntimeError('StellarHarvester: no ball found')
     51         if not getattr(harvesterBall, 'model', None):
     52             raise RuntimeError('StellarHarvester: no model found')
     53         if targetBall is None:
     54             raise RuntimeError('StellarHarvester: no target ball found')
     55         if self.gfx is None:
     56             raise RuntimeError('StellarHarvester: no effect defined: %s' % getattr(self, 'graphicFile', 'None'))
     57         bp = sm.GetService('michelle').GetBallpark()
     58         solarsystemid = bp.solarsystemID
     59         if self.IsExplodingSystem(solarsystemid):
     60             self.secondaryGraphicFile = 'res:/fisfx/environment/celestial/multieffect/small_blue_star_flickering_multieffect.red'
     61         self.flickerEffect = self.RecycleOrLoad(self.secondaryGraphicFile)
     62         for each in self.flickerEffect.parameters:
     63             if each.name == 'Sun':
     64                 each.object = scene.sunBall.GetModel()
     65             elif each.name == 'LensFlare':
     66                 each.object = scene.lensflares[0]
     67 
     68         self.AddToScene(self.flickerEffect)
     69         self.flickerEffect.StartControllers()
     70         self.AddToScene(self.gfx)
     71         self._SetupLaserEndpoints(harvesterBall, targetBall)
     72         self.gfx.SetControllerVariable('star_state', 2)
     73         for controller in self.gfx.controllers:
     74             controller.Start()
     75 
     76         harvesterBall.model.StartControllers()
     77         targetBall.model.StartControllers()
     78 
     79     def Start(self, duration):
     80         if self.gfx is None:
     81             raise RuntimeError('StellarHarvester: no effect defined: %s' % getattr(self, 'graphicFile', 'None'))
     82         self.UpdateGraphicInfo(self.graphicInfo)
     83 
     84     def UpdateGraphicInfo(self, newGraphicInfo):
     85         self.graphicInfo = newGraphicInfo
     86         poseID = self._GetPoseID()
     87         self.gfx.StartFiring(0.0)
     88         self.gfx.SetControllerVariable('star_state', poseID)
     89         sun = self.GetEffectTargetBall()
     90         sun.SetControllerVariable('star_state', poseID)
     91         sun.model.StartControllers()
     92 
     93     def _SetupLaserEndpoints(self, sourceBall, targetBall):
     94         positionCurve = trinity.EveLocalPositionCurve()
     95         positionCurve.parent = sourceBall.GetModel()
     96         positionCurve.locatorSetName = 'triglavian_starharvest_source'
     97         positionCurve.behavior = trinity.EveLocalPositionBehavior.nearestFiringLocator
     98         positionCurve.locatorIndex = 0
     99         self.gfx.source = positionCurve
    100         self.gfx.dest = targetBall
    101         sun = targetBall.GetModel()
    102         sunLaser = sun.effectChildren.FindByName('Lazer')
    103         if sunLaser is None:
    104             return
    105         self.sunRotComponent = sunLaser
    106         sunSuckerXYScaleComponent = self.sunRotComponent.objects.FindByName('Scale_X_Y')
    107         self.sunSuckerZScaleComponent = sunSuckerXYScaleComponent.objects.FindByName('Scale_Z')
    108         self.RotateSunSucker(sourceBall, targetBall)
    109         self.ScaleSunSuckerZ(sourceBall, targetBall)
    110 
    111     def _GetPoseID(self):
    112         defaultPoseID = 0
    113         if not isinstance(self.graphicInfo, dict):
    114             return defaultPoseID
    115         return self.graphicInfo.get('poseID', defaultPoseID)
    116 
    117     def _GetStationPosInSunSpace(self, stationBall):
    118         station = stationBall
    119         stationModel = station.GetModel()
    120         offset = (0.0, 0.0, 0.0)
    121         locatorSet = stationModel.locatorSets.FindByName('triglavian_starharvest_source')
    122         if locatorSet:
    123             offset = locatorSet.locators[0][0]
    124         rotationCurve = stationModel.modelRotationCurve
    125         if rotationCurve:
    126             r = rotationCurve.GetQuaternionAt(blue.os.GetSimTime())
    127             offset = geo2.QuaternionTransformVector((r.x,
    128              r.y,
    129              r.z,
    130              r.w), offset)
    131         translation = (station.x, station.y, station.z)
    132         offset = geo2.Vec3AddD(offset, translation)
    133         sunBall = self.GetEffectTargetBall()
    134         sunScale = sunBall.GetModel().scaling[0]
    135         return geo2.Vec3ScaleD(offset, 1.0 / sunScale)
    136 
    137     def RotateSunSucker(self, sourceBall, targetBall):
    138         sunBall = targetBall
    139         sunPos = (sunBall.x, sunBall.y, sunBall.z)
    140         stationPos = self._GetStationPosInSunSpace(sourceBall)
    141         z = geo2.VectorD(0.0, 0.0, 1.0)
    142         direction = geo2.Vec3NormalizeD(geo2.Vec3SubtractD(sunPos, stationPos))
    143         self.sunRotComponent.rotation = geo2.QuaternionRotationArc(z, direction)
    144 
    145     def ScaleSunSuckerZ(self, sourceBall, targetBall):
    146         sunBall = targetBall
    147         sunPos = (sunBall.x, sunBall.y, sunBall.z)
    148         stationPos = self._GetStationPosInSunSpace(sourceBall)
    149         tmpScale = self.sunSuckerZScaleComponent.scaling
    150         zScale = geo2.Vec3DistanceD(sunPos, stationPos) - 0.5
    151         self.sunSuckerZScaleComponent.scaling = (tmpScale[0], tmpScale[1], zScale)