EveStretch3.py (8946B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\environment\effects\EveStretch3.py 2 import blue 3 import trinity 4 import uthread 5 import evetypes 6 import inventorycommon.const as invconst 7 from eve.client.script.environment.effects.GenericEffect import GenericEffect, GetBoundingBox, STOP_REASON_DEFAULT, STOP_REASON_BALL_REMOVED 8 from fsdBuiltData.common.graphicIDs import GetGraphicFile 9 10 class EveStretch3(GenericEffect): 11 __guid__ = 'effects.EveStretch3' 12 13 def __init__(self, trigger, effect = None, graphicFile = None): 14 super(EveStretch3, self).__init__(trigger, effect, graphicFile) 15 self.graphicInfo = getattr(trigger, 'graphicInfo', None) or {} 16 if trigger.locatorSetOverride is not None: 17 self.locatorSetName = trigger.locatorSetOverride 18 else: 19 self.locatorSetName = self.graphicInfo.get('locatorSetName', 'damage') 20 self.controllerTriggers = self.graphicInfo.get('controllerTrigger', None) 21 gIDOverride = self.graphicInfo.get('graphicIDOverride', None) 22 self.lingerOnDeathTime = self.graphicInfo.get('deathTimer', None) 23 self.moduleTypeID = getattr(trigger, 'moduleTypeID', None) 24 self.guid = getattr(trigger, 'guid', None) 25 if gIDOverride is not None: 26 graphicFilePath = GetGraphicFile(gIDOverride) 27 if graphicFilePath is not None: 28 self.graphicFile = graphicFilePath 29 30 def Stop(self, reason = STOP_REASON_DEFAULT): 31 if self.gfx is None: 32 raise RuntimeError('EveStretch3: no effect defined: ' + str(getattr(self, 'graphicFile', 'None'))) 33 self.gfx.StopFiring() 34 self.gfx.SetControllerVariable('LinkWithShip_Active', 0) 35 self.gfx.SetControllerVariable('stopSound', 1.0) 36 self.RemoveFromScene(self.gfxModel) 37 if isinstance(self.gfx.source, trinity.EveLocalPositionCurve): 38 self.gfx.source.parentPositionCurve = None 39 self.gfx.source.parentRotationCurve = None 40 self.gfx.source.alignPositionCurve = None 41 if isinstance(self.gfx.dest, trinity.EveLocalPositionCurve): 42 self.gfx.dest.parentPositionCurve = None 43 self.gfx.dest.parentRotationCurve = None 44 self.gfx.dest.alignPositionCurve = None 45 scene = self.fxSequencer.GetScene() 46 if reason == STOP_REASON_BALL_REMOVED and self.lingerOnDeathTime is not None: 47 uthread.new(EveStretch3._DelayedCleanUp, self.lingerOnDeathTime, self.gfx, scene) 48 else: 49 self._CleanUp(self.gfx, scene) 50 51 @staticmethod 52 def _DelayedCleanUp(timeInSec, model, scene): 53 blue.synchro.SleepSim(timeInSec * 1000) 54 EveStretch3._CleanUp(model, scene) 55 56 @staticmethod 57 def _CleanUp(model, scene): 58 if scene is not None and model is not None: 59 scene.objects.fremove(model) 60 61 def Prepare(self): 62 self.DoPrepare() 63 64 def _SetRemoteModuleType(self): 65 moduleEnumValue = 0 66 if self.moduleTypeID: 67 groupID = evetypes.GetGroupID(self.moduleTypeID) 68 groups = [[invconst.groupFueledRemoteArmorRepairer, invconst.groupArmorRepairProjector], [invconst.groupFueledRemoteShieldBooster, invconst.groupShieldTransporter], [invconst.groupRemoteHullRepairer]] 69 for group in groups: 70 if groupID in group: 71 moduleEnumValue = groups.index(group) + 1 72 break 73 74 elif self.guid: 75 effectTypes = ['effects.RemoteArmourRepair', 'effects.ShieldTransfer'] 76 moduleEnumValue = effectTypes.index(self.guid) if self.guid in effectTypes else 0 77 else: 78 moduleEnumValue = 0 79 self.gfx.SetControllerVariable('moduleType', moduleEnumValue) 80 81 def DoPrepare(self): 82 shipBall = self.GetEffectShipBall() 83 positionCurve = self.GetBallPositionCurve(shipBall) 84 targetBall = self.GetEffectTargetBall() 85 if shipBall is None: 86 raise RuntimeError('StretchEffect: no ball found') 87 if not getattr(shipBall, 'model', None): 88 raise RuntimeError('StretchEffect: no model found') 89 if targetBall is None: 90 raise RuntimeError('StretchEffect: no target ball found') 91 if targetBall.model is None or shipBall.model is None: 92 raise RuntimeError('StretchEffect: Both Source and Target need to have models') 93 self.gfx = self.RecycleOrLoad(self.graphicFile) 94 if self.gfx is None: 95 raise RuntimeError('StretchEffect: no effect found: ' + str(getattr(self, 'graphicFile', 'None'))) 96 if self.controllerTriggers is not None: 97 for key, value in self.controllerTriggers.items(): 98 self.gfx.SetControllerVariable(key, value) 99 100 if hasattr(shipBall.model, 'boundingSphereRadius'): 101 self.gfx.SetControllerVariable('boundingSphereRadius', shipBall.model.boundingSphereRadius) 102 if self.duration > 0: 103 self.gfx.SetControllerVariable('duration', self.duration / 1000.0) 104 self._SetRemoteModuleType() 105 self.gfx.destSpaceObject = targetBall.model 106 self.gfx.sourceSpaceObject = shipBall.model 107 sourceCurve = trinity.EveLocalPositionCurve(trinity.EveLocalPositionBehavior.nearestBounds) 108 sourceCurve.parent = shipBall.model 109 destCurve = trinity.EveLocalPositionCurve(trinity.EveLocalPositionBehavior.nearestFiringLocator) 110 destCurve.locatorSetName = self.locatorSetName 111 destCurve.parent = targetBall.model 112 self.gfx.source = sourceCurve 113 self.gfx.dest = destCurve 114 self.SetDestCurve(targetBall) 115 self.gfx.source.parentPositionCurve = shipBall 116 self.gfx.source.parentRotationCurve = shipBall 117 self.gfx.source.alignPositionCurve = targetBall 118 sourceScale = GetBoundingBox(shipBall, scale=1.0) 119 self.gfx.source.boundingSize = sourceScale 120 self.AddToScene(self.gfx) 121 122 def SetDestCurve(self, targetBall): 123 if targetBall is None: 124 self.Stop(STOP_REASON_BALL_REMOVED) 125 return 126 targetModelWorldPos = self.gfx.sourceSpaceObject.modelWorldPosition 127 goodIndex = self.gfx.destSpaceObject.GetGoodLocatorIndex(targetModelWorldPos, self.locatorSetName) 128 self.gfx.dest.locatorIndex = goodIndex 129 self.gfx.dest.parentPositionCurve = targetBall 130 self.gfx.dest.parentRotationCurve = targetBall 131 targetScale = GetBoundingBox(targetBall, scale=1.0) 132 self.gfx.dest.boundingSize = targetScale 133 134 def Start(self, duration): 135 if self.gfx is None: 136 raise RuntimeError('EveStretch3: no effect defined: ' + str(getattr(self, 'graphicFile', 'None'))) 137 self.gfx.StartFiring(0.0) 138 self.gfx.SetControllerVariable('stopSound', 0.0) 139 self.gfx.SetControllerVariable('triggerSound', 1.0) 140 141 def Repeat(self, duration): 142 if self.gfx is None: 143 return 144 shipBall = self.GetEffectShipBall() 145 targetBall = self.GetEffectTargetBall() 146 if targetBall is None: 147 self.Stop(STOP_REASON_BALL_REMOVED) 148 if shipBall is None: 149 self.Stop(STOP_REASON_BALL_REMOVED) 150 if self.gfx.destSpaceObject is None or self.gfx.sourceSpaceObject is None: 151 self.Stop(STOP_REASON_BALL_REMOVED) 152 self.gfx.SetControllerVariable('triggerSound', 1.0) 153 self.SetDestCurve(targetBall) 154 155 def UpdateGraphicInfo(self, newGraphicInfo): 156 if self.gfx is None: 157 return 158 self.locatorSetName = newGraphicInfo.get('locatorSetName', self.locatorSetName) 159 if self.locatorSetName is not None: 160 positionOffset = self.FindGoodLocator() 161 if positionOffset is not None: 162 self.gfx.dest.positionOffset = positionOffset 163 self.controllerTriggers = newGraphicInfo.get('controllerTrigger', None) 164 if self.controllerTriggers is not None: 165 for key, value in self.controllerTriggers.items(): 166 self.gfx.SetControllerVariable(key, value) 167 if self.gfx.destSpaceObject is not None: 168 self.gfx.destSpaceObject.SetControllerVariable(key, value) 169 if self.gfx.sourceSpaceObject is not None: 170 self.gfx.sourceSpaceObject.SetControllerVariable(key, value) 171 172 def FindGoodLocator(self): 173 locatorSets = getattr(self.gfx.destSpaceObject, 'locatorSets', None) 174 if locatorSets: 175 locator = locatorSets.FindByName(self.locatorSetName) 176 if locator is None: 177 self.locatorSetName = 'damage' 178 targetModelWorldPos = self.gfx.sourceSpaceObject.modelWorldPosition 179 goodIndex = self.gfx.destSpaceObject.GetGoodLocatorIndex(targetModelWorldPos, self.locatorSetName) 180 if goodIndex != -1: 181 return self.gfx.destSpaceObject.GetLocatorPositionFromSet(goodIndex, True, self.locatorSetName)