recorder.py (3586B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\parklife\recorder.py 2 from __future__ import print_function 3 import blue 4 from carbon.common.script.sys.service import Service 5 6 class EventRecorder(Service): 7 __guid__ = 'svc.recorder' 8 __exportedcalls__ = {'StartStateCapture': [], 9 'EndStateCapture': []} 10 __notifyevents__ = ['DoBallsAdded', 'DoDestinyUpdate', 'DoDestinyUpdates'] 11 __dependencies__ = [] 12 13 def __init__(self): 14 super(EventRecorder, self).__init__() 15 self.captureBallAttributes = ['name', 16 'radius', 17 'maxVelocity', 18 'x', 19 'y', 20 'z', 21 'vx', 22 'vy', 23 'vz', 24 'gotoX', 25 'gotoY', 26 'gotoZ', 27 'Agility', 28 'mode', 29 'followId', 30 'followRange', 31 'mass', 32 'maxVelocity', 33 'isFree', 34 'isGlobal', 35 'isMassive', 36 'isInteractive', 37 'speedFraction'] 38 self.captureSessionAttributes = ['userid', 39 'shipid', 40 'solarsystemid', 41 'solarsystemid2'] 42 self.initialState = None 43 self.capturingState = False 44 self.capturedStateUpdates = [] 45 46 def CaptureInitialState(self): 47 michelle = sm.StartService('michelle') 48 bp = michelle.GetBallpark() 49 globalState = {} 50 itemState = {} 51 for ballID in bp.balls: 52 slimItem = bp.GetInvItem(ballID) 53 ball = bp.GetBall(ballID) 54 itemState[ballID] = ballState = {} 55 if slimItem is not None: 56 for key, val in slimItem.__dict__.iteritems(): 57 ballState[key] = val 58 59 for a in self.captureBallAttributes: 60 ballState[a] = getattr(ball, a, None) 61 62 globalState['egoBall'] = bp.ego 63 globalState['shipid'] = session.shipid 64 globalState['solarsystemid'] = session.solarsystemid 65 globalState['solarsystemid2'] = session.solarsystemid2 66 globalState['initialTime'] = blue.os.GetSimTime() 67 globalState['regionid'] = session.regionid 68 self.initialState = (globalState, itemState) 69 70 def StartStateCapture(self): 71 self.capturingState = True 72 self.capturedStateUpdates = [] 73 self.CaptureInitialState() 74 75 def EndStateCapture(self, filepath): 76 self.capturingState = False 77 import cPickle 78 print('Writing State out') 79 f = open(filepath, 'wb') 80 cPickle.dump((self.initialState[0], self.initialState[1], self.capturedStateUpdates), f) 81 f.close() 82 83 def DoDestinyUpdate(self, state, waitForBubble, dogmaMessages = [], doDump = True): 84 if self.capturingState: 85 filteredStates = [] 86 for stamp, (funcName, args) in state: 87 if funcName != 'AddBalls': 88 filteredStates.append((stamp, (funcName, args))) 89 90 self.capturedStateUpdates.append((blue.os.GetSimTime(), filteredStates)) 91 92 def DoDestinyUpdates(self, updates): 93 pass 94 95 def DoBallsAdded(self, lst): 96 stateUpdate = [] 97 for ball, slimItem in lst: 98 ballState = {} 99 if slimItem is not None: 100 for key, val in slimItem.__dict__.iteritems(): 101 ballState[key] = val 102 103 for a in self.captureBallAttributes: 104 ballState[a] = getattr(ball, a, None) 105 106 stateUpdate.append((ball.id, ballState)) 107 108 self.capturedStateUpdates.append((blue.os.GetSimTime(), [(0, ('DoBallsAdded', stateUpdate))]))