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

SunHarvestingBeam.py (5351B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\SunHarvestingBeam.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 SunHarvestingBeam(GenericEffect):
      8     __guid__ = 'effects.SunHarvestingBeam'
      9 
     10     def __init__(self, trigger, effect = None, graphicFile = None):
     11         super(SunHarvestingBeam, self).__init__(trigger, effect, graphicFile)
     12         self.sunRotComponent = None
     13         self.sunSuckerZScaleComponent = None
     14 
     15     def Stop(self, reason = STOP_REASON_DEFAULT):
     16         if self.gfx is None:
     17             raise RuntimeError('SunHarvestingBeam: no effect defined: ' + str(getattr(self, 'graphicFile', 'None')))
     18         self.RemoveFromScene(self.gfx)
     19         self.gfx.source = None
     20         self.gfx.dest = None
     21         self.gfx.sourceObject = None
     22         self.gfx = None
     23         self.gfxModel = None
     24         tmp = self.sunSuckerZScaleComponent.scaling
     25         self.sunSuckerZScaleComponent.scaling = (tmp[0], tmp[1], 0.0)
     26         self.sunRotComponent = None
     27         self.sunSuckerZScaleComponent = None
     28 
     29     def Prepare(self):
     30         self.DoPrepare()
     31 
     32     def DoPrepare(self):
     33         harvesterBall = self.GetEffectShipBall()
     34         targetBall = self.GetEffectTargetBall()
     35         self.gfx = self.RecycleOrLoad(self.graphicFile)
     36         if harvesterBall is None:
     37             raise RuntimeError('SunHarvestingBeam: no ball found')
     38         if not getattr(harvesterBall, 'model', None):
     39             raise RuntimeError('SunHarvestingBeam: no model found')
     40         if targetBall is None:
     41             raise RuntimeError('SunHarvestingBeam: no target ball found')
     42         if self.gfx is None:
     43             raise RuntimeError('SunHarvestingBeam: no effect defined: %s' % getattr(self, 'graphicFile', 'None'))
     44         sceneManager = sm.GetService('sceneManager')
     45         scene = sceneManager.registeredScenes['default']
     46         self._SetupLaserEndpoints(harvesterBall, scene.sunBall)
     47         self.AddToScene(self.gfx)
     48 
     49     def Start(self, duration):
     50         if self.gfx is None:
     51             raise RuntimeError('SunHarvestingBeam: no effect defined: %s' % getattr(self, 'graphicFile', 'None'))
     52         self.UpdateGraphicInfo(self.graphicInfo)
     53 
     54     def UpdateGraphicInfo(self, newGraphicInfo):
     55         self.graphicInfo = newGraphicInfo
     56         poseID = self._GetPoseID()
     57         self.gfx.StartFiring(0.0)
     58         self.gfx.SetControllerVariable('star_state', poseID)
     59         sun = self.GetEffectTargetBall()
     60         sun.SetControllerVariable('star_state', poseID)
     61 
     62     def _SetupLaserEndpoints(self, sourceBall, targetBall):
     63         positionCurve = trinity.EveLocalPositionCurve()
     64         positionCurve.parent = sourceBall.GetModel()
     65         positionCurve.locatorSetName = 'triglavian_starharvest_source'
     66         positionCurve.behavior = trinity.EveLocalPositionBehavior.nearestFiringLocator
     67         positionCurve.locatorIndex = 0
     68         self.gfx.source = positionCurve
     69         self.gfx.dest = targetBall
     70         sun = targetBall.GetModel()
     71         sunLaser = sun.effectChildren.FindByName('Laser')
     72         if sunLaser is not None:
     73             self.sunRotComponent = sunLaser.objects.FindByName('HarvestLaserEnd_RotMe')
     74             sunSuckerXYScaleComponent = self.sunRotComponent.objects.FindByName('Scale_X_Y')
     75             self.sunSuckerZScaleComponent = sunSuckerXYScaleComponent.objects.FindByName('Scale_Z')
     76             self.RotateSunSucker()
     77             self.ScaleSunSuckerZ()
     78 
     79     def _GetPoseID(self):
     80         defaultPosID = 0
     81         if not isinstance(self.graphicInfo, dict):
     82             return defaultPosID
     83         return self.graphicInfo.get('poseID', defaultPosID)
     84 
     85     def _GetStationPosInSunSpace(self):
     86         station = self.GetEffectShipBall()
     87         stationModel = station.GetModel()
     88         offset = (0.0, 0.0, 0.0)
     89         locatorSet = stationModel.locatorSets.FindByName('triglavian_starharvest_source')
     90         if locatorSet:
     91             offset = locatorSet.locators[0][0]
     92         rotationCurve = stationModel.modelRotationCurve
     93         if rotationCurve:
     94             r = rotationCurve.GetQuaternionAt(blue.os.GetSimTime())
     95             offset = geo2.QuaternionTransformVector((r.x,
     96              r.y,
     97              r.z,
     98              r.w), offset)
     99         translation = (station.x, station.y, station.z)
    100         offset = geo2.Vec3AddD(offset, translation)
    101         sunBall = self.GetEffectTargetBall()
    102         sunScale = sunBall.GetModel().scaling[0]
    103         return geo2.Vec3ScaleD(offset, 1.0 / sunScale)
    104 
    105     def RotateSunSucker(self):
    106         sunBall = self.GetEffectTargetBall()
    107         sunPos = (sunBall.x, sunBall.y, sunBall.z)
    108         stationPos = self._GetStationPosInSunSpace()
    109         z = geo2.VectorD(0.0, 0.0, 1.0)
    110         direction = geo2.Vec3NormalizeD(geo2.Vec3SubtractD(sunPos, stationPos))
    111         self.sunRotComponent.rotation = geo2.QuaternionRotationArc(z, direction)
    112 
    113     def ScaleSunSuckerZ(self):
    114         sunBall = self.GetEffectTargetBall()
    115         sunPos = (sunBall.x, sunBall.y, sunBall.z)
    116         stationPos = self._GetStationPosInSunSpace()
    117         tmpScale = self.sunSuckerZScaleComponent.scaling
    118         zScale = geo2.Vec3DistanceD(sunPos, stationPos) - 0.5
    119         self.sunSuckerZScaleComponent.scaling = (tmpScale[0], tmpScale[1], zScale)