Advertisement
Guest User

WoT UniversalAims.py

a guest
Apr 12th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.37 KB | None | 0 0
  1. from functools import partial
  2. import math
  3. import weakref
  4. import BigWorld
  5. import GUI
  6. import Math
  7. import ResMgr
  8. from debug_utils import *
  9. from helpers import i18n
  10. from helpers.func_utils import *
  11. from gui import DEPTH_OF_Aim
  12. from gui.Scaleform.Flash import Flash
  13. from gui.Scaleform.ColorSchemeManager import _ColorSchemeManager
  14. from account_helpers.AccountSettings import AccountSettings
  15. from gui.BattleContext import g_battleContext
  16. import BattleReplay
  17.  
  18. def createAim(type):
  19.     if type == 'strategic':
  20.         return StrategicAim((0, 0.0))
  21.     if type == 'arcade':
  22.         return ArcadeAim((0, 0.15), False)
  23.     if type == 'sniper':
  24.         return ArcadeAim((0, 0.0), True)
  25.     if type == 'postmortem':
  26.         return PostMortemAim((0, 0.0))
  27.     LOG_ERROR('Undefined aim type. <%s>' % type)
  28.  
  29.  
  30. class Aim(Flash):
  31.     _UPDATE_INTERVAL = 0.03
  32.     __FLASH_CLASS = 'WGAimFlash'
  33.  
  34.     def __init__(self, mode, offset):
  35.         Flash.__init__(self, 'crosshair_panel_{0:>s}.swf'.format(mode), self.__FLASH_CLASS)
  36.         self.component.wg_inputKeyMode = 2
  37.         self.component.position.z = DEPTH_OF_Aim
  38.         self.component.focus = False
  39.         self.component.moveFocus = False
  40.         self.component.heightMode = 'PIXEL'
  41.         self.component.widthMode = 'PIXEL'
  42.         self.movie.backgroundAlpha = 0
  43.         self.flashSize = GUI.screenResolution()
  44.         self._offset = offset
  45.         self._isLoaded = False
  46.         self.mode = mode
  47.         self.__timeInterval = _TimeInterval(Aim._UPDATE_INTERVAL, '_update', weakref.proxy(self))
  48.         self.__isColorBlind = AccountSettings.getSettings('isColorBlind')
  49.  
  50.     def prerequisites(self):
  51.         return []
  52.  
  53.     def _isColorBlind(self):
  54.         return self.__isColorBlind
  55.  
  56.     def create(self):
  57.         from account_helpers.SettingsCore import g_settingsCore
  58.         g_settingsCore.onSettingsChanged += self.applySettings
  59.         replayCtrl = BattleReplay.g_replayCtrl
  60.         if replayCtrl.isPlaying and replayCtrl.replayContainsGunReloads:
  61.             self._flashCall('setupReloadingCounter', [False])
  62.             self.__cbIdSetReloading = BigWorld.callback(0.0, self.setReloadingFromReplay)
  63.         else:
  64.             self.__cbIdSetReloading = None
  65.         return
  66.  
  67.     def destroy(self):
  68.         from account_helpers.SettingsCore import g_settingsCore
  69.         g_settingsCore.onSettingsChanged -= self.applySettings
  70.         self.close()
  71.         if self.__cbIdSetReloading is not None:
  72.             BigWorld.cancelCallback(self.__cbIdSetReloading)
  73.             self.__cbIdSetReloading = None
  74.         self.__timeInterval.stop()
  75.         self.__timeInterval = None
  76.         return
  77.  
  78.     def applySettings(self, diff):
  79.         from account_helpers.SettingsCore import g_settingsCore
  80.         for type in ('arcade', 'sniper'):
  81.             if type in diff and self.mode == type:
  82.                 settings = g_settingsCore.getSetting(type)
  83.                 subSetting = settings['centralTag']
  84.                 subSettingType = settings['centralTagType']
  85.                 self._flashCall('setCenterType', [subSetting, subSettingType])
  86.                 subSetting = settings['net']
  87.                 subSettingType = settings['netType']
  88.                 self._flashCall('setNetType', [subSetting, subSettingType])
  89.                 subSetting = settings['reloader']
  90.                 self._flashCall('setReloaderType', [subSetting, 0])
  91.                 subSetting = settings['condition']
  92.                 self._flashCall('setConditionType', [subSetting, 0])
  93.                 subSetting = settings['cassette']
  94.                 self._flashCall('setCassetteType', [subSetting, 0])
  95.                 subSetting = settings['reloaderTimer']
  96.                 self._flashCall('setReloaderTimerType', [subSetting, 0])
  97.  
  98.         if 'isColorBlind' in diff:
  99.             self.__isColorBlind = diff['isColorBlind']
  100.  
  101.     def enable(self):
  102.         global _g_aimState
  103.         self.active(True)
  104.         self.applySettings(self.mode)
  105.         self.__timeInterval.start()
  106.         _g_aimState['target']['id'] = None
  107.         self._enable(_g_aimState, _g_aimState['isFirstInit'])
  108.         _g_aimState['isFirstInit'] = False
  109.         self.onRecreateDevice()
  110.         return
  111.  
  112.     def disable(self):
  113.         self.active(False)
  114.         _g_aimState['target']['id'] = None
  115.         self.__timeInterval.stop()
  116.         self._disable()
  117.         return
  118.  
  119.     def updateMarkerPos(self, pos, relaxTime):
  120.         self.component.updateMarkerPos(pos, relaxTime)
  121.  
  122.     def onRecreateDevice(self):
  123.         screen = GUI.screenResolution()
  124.         self.component.size = screen
  125.         width = screen[0]
  126.         height = screen[1]
  127.         offsetX = self._offset[0]
  128.         offsetY = self._offset[1]
  129.         posX = 0.5 * width * (1.0 + offsetX)
  130.         posX = round(posX) if width % 2 == 0 else int(posX)
  131.         posY = 0.5 * height * (1.0 - offsetY)
  132.         posY = round(posY) if height % 2 == 0 else int(posY)
  133.         self._flashCall('onRecreateDevice', [posX, posY])
  134.  
  135.     def setVisible(self, isVisible):
  136.         self.component.visible = isVisible
  137.  
  138.     def offset(self, value = None):
  139.         if value is not None:
  140.             self._offset = value
  141.             self.onRecreateDevice()
  142.         else:
  143.             return self._offset
  144.         return
  145.  
  146.     def setTarget(self, target):
  147.         state = _g_aimState['target']
  148.         vInfo = dict(target.publicInfo)
  149.         state['id'] = target.id
  150.         state['startTime'] = None
  151.         clanAbbrev = BigWorld.player().arena.vehicles.get(target.id, {}).get('clanAbbrev', '')
  152.         state['name'] = i18n.convert('%s[%s]' % (vInfo['name'], clanAbbrev) if len(clanAbbrev) > 0 else vInfo['name'])
  153.         state['vType'] = i18n.convert(target.typeDescriptor.type.userString)
  154.         state['isFriend'] = vInfo['team'] == BigWorld.player().team
  155.         self._setTarget(state['name'], state['vType'], state['isFriend'])
  156.         return
  157.  
  158.     def clearTarget(self):
  159.         state = _g_aimState['target']
  160.         state['id'] = None
  161.         state['startTime'] = BigWorld.time()
  162.         self._clearTarget(0)
  163.         return
  164.  
  165.     def getTargetColor(self, isFriend):
  166.         colorScheme = _ColorSchemeManager.getSubScheme('aim_target_ally' if isFriend else 'aim_target_enemy', isColorBlind=self.__isColorBlind)
  167.         return _ColorSchemeManager._makeRGB(colorScheme)
  168.  
  169.     def getReloadingTimeLeft(self):
  170.         state = _g_aimState['reload']
  171.         correction = state.get('correction')
  172.         startTime = state.get('startTime', 0)
  173.         duration = state.get('duration', 0)
  174.         if correction is not None:
  175.             startTime = correction.get('startTime', 0)
  176.             duration = correction.get('timeRemaining', 0)
  177.         if startTime is not None:
  178.             current = BigWorld.time()
  179.             return duration - (current - startTime)
  180.         else:
  181.             return 0
  182.  
  183.     def getAmmoQuantityLeft(self):
  184.         ammo = _g_aimState['ammo']
  185.         if self.isCasseteClip():
  186.             return ammo[1]
  187.         else:
  188.             return ammo[0]
  189.  
  190.     def isCasseteClip(self):
  191.         clip = _g_aimState['clip']
  192.         return clip[0] != 1 or clip[1] != 1
  193.  
  194.     def setReloading(self, duration, startTime = None, baseTime = None):
  195.         state = _g_aimState['reload']
  196.         _isReloading = state.get('isReloading', False)
  197.         _startTime = state.get('startTime', 0)
  198.         _duration = state.get('duration', 0)
  199.         isReloading = duration != 0
  200.         state['isReloading'] = isReloading
  201.         state['correction'] = None
  202.         state['baseTime'] = baseTime
  203.         if _isReloading and duration > 0 and _duration > 0 and _startTime > 0:
  204.             current = BigWorld.time()
  205.             state['correction'] = {'timeRemaining': duration,
  206.              'startTime': current,
  207.              'startPosition': (current - _startTime) / _duration}
  208.             self._flashCall('updateReloadingBaseTime', [baseTime, False])
  209.             self._correctReloadingTime(duration)
  210.         else:
  211.             state['duration'] = duration
  212.             state['startTime'] = BigWorld.time() if isReloading else None
  213.             self._setReloading(duration, 0, isReloading, None, baseTime)
  214.         return
  215.  
  216.     def setHealth(self, current):
  217.         state = _g_aimState['health']
  218.         state['cur'] = current
  219.         if state['max'] is None:
  220.             state['max'] = float(BigWorld.player().vehicleTypeDescriptor.maxHealth)
  221.         self._setHealth(state['cur'], state['max'])
  222.         return
  223.  
  224.     def setAmmoStock(self, quantity, quantityInClip, clipReloaded = False):
  225.         _g_aimState['ammo'] = (quantity, quantityInClip)
  226.         self._setAmmoStock(quantity, quantityInClip, clipReloaded=clipReloaded)
  227.  
  228.     def updateAmmoState(self, hasAmmo):
  229.         self._flashCall('updateAmmoState', [hasAmmo])
  230.  
  231.     def getAmmoState(self, quantity, quantityInClip):
  232.         clipCapacity, burst = _g_aimState['clip']
  233.         state = 'normal'
  234.         isLow = quantity < 3
  235.         if clipCapacity > 1:
  236.             state = self._getClipState(clipCapacity, burst, quantityInClip)
  237.             isLow |= quantity <= clipCapacity
  238.         return (isLow, state)
  239.  
  240.     def setClipParams(self, capacity, burst):
  241.         _g_aimState['clip'] = (capacity, burst)
  242.         if capacity > 1:
  243.             self._setClipParams(capacity, burst)
  244.  
  245.     def showHit(self, gYaw, isDamage):
  246.         _g_aimState['hitIndicators'].append({'gYaw': gYaw,
  247.          'startTime': BigWorld.time(),
  248.          'isDamage': isDamage})
  249.         self._showHit(_g_aimState['hitIndicators'][-1:][0])
  250.  
  251.     def isGunReload(self):
  252.         return _g_aimState['reload']['isReloading']
  253.  
  254.     def onCameraChange(self):
  255.         if not self.isGunReload():
  256.             baseTime = _g_aimState['reload'].get('baseTime', -1)
  257.             self._flashCall('updateReloadingBaseTime', [baseTime, True])
  258.         elif not _g_aimState['reload']['correction']:
  259.             self._flashCall('clearPreviousCorrection', [])
  260.  
  261.     def resetVehicleMatrix(self):
  262.         pass
  263.  
  264.     def _enable(self, state, isFirstInit):
  265.         pass
  266.  
  267.     def _disable(self):
  268.         pass
  269.  
  270.     def _showHit(self, hitDesc):
  271.         pass
  272.  
  273.     def _setTarget(self, name, vType, isFriend):
  274.         self._flashCall('setTarget', [name, vType, self.getTargetColor(isFriend)])
  275.  
  276.     def _clearTarget(self, startTime):
  277.         self._flashCall('clearTarget', [startTime])
  278.  
  279.     def setReloadingFromReplay(self):
  280.         self._setReloadingAsPercent(100.0 * BattleReplay.g_replayCtrl.getGunReloadAmountLeft())
  281.         self.__cbIdSetReloading = BigWorld.callback(0.0, self.setReloadingFromReplay)
  282.  
  283.     def _setReloading(self, duration, startTime = None, isReloading = True, correction = None, baseTime = None):
  284.         replayCtrl = BattleReplay.g_replayCtrl
  285.         if replayCtrl.isPlaying and replayCtrl.replayContainsGunReloads:
  286.             return
  287.         else:
  288.             if replayCtrl.isRecording:
  289.                 replayCtrl.setGunReloadTime(startTime, duration)
  290.             if correction is not None:
  291.                 params = self._getCorrectionReloadingParams(correction)
  292.                 if params is not None:
  293.                     self._flashCall('setReloading', params)
  294.             else:
  295.                 self._flashCall('setReloading', [duration,
  296.                  startTime,
  297.                  isReloading,
  298.                  None,
  299.                  baseTime])
  300.             return
  301.  
  302.     def _setReloadingAsPercent(self, percent):
  303.         self._flashCall('setReloadingAsPercent', [percent])
  304.  
  305.     def _correctReloadingTime(self, duration):
  306.         replayCtrl = BattleReplay.g_replayCtrl
  307.         if replayCtrl.isPlaying and replayCtrl.replayContainsGunReloads:
  308.             self.setReloadingFromReplay()
  309.             return
  310.         self._flashCall('correctReloadingTime', [duration])
  311.  
  312.     def _getCorrectionReloadingParams(self, correction):
  313.         cTimeRemaining = correction.get('timeRemaining', 0)
  314.         cStartTime = correction.get('startTime', 0)
  315.         cStartPosition = correction.get('startPosition', 0)
  316.         if not cTimeRemaining > 0:
  317.             LOG_WARNING('timeRemaining - invalid value ', cTimeRemaining)
  318.             return None
  319.         else:
  320.             delta = BigWorld.time() - cStartTime
  321.             currentPosition = cStartPosition + delta / cTimeRemaining * (1 - cStartPosition)
  322.             return [cTimeRemaining - delta,
  323.              cStartTime,
  324.              True,
  325.              currentPosition * 100.0]
  326.  
  327.     def _setHealth(self, cur, max):
  328.         if cur is not None and max is not None:
  329.             self._flashCall('setHealth', [cur / max])
  330.         return
  331.  
  332.     def _setAmmoStock(self, quantity, quantityInClip, clipReloaded = False):
  333.         isLow, state = self.getAmmoState(quantity, quantityInClip)
  334.         self._flashCall('setAmmoStock', [quantity,
  335.          quantityInClip,
  336.          isLow,
  337.          state,
  338.          clipReloaded])
  339.  
  340.     def _getClipState(self, capacity, burst, quantityInClip):
  341.         state = 'normal'
  342.         if burst > 1:
  343.             total = math.ceil(float(capacity) / float(burst))
  344.             current = math.ceil(float(quantityInClip) / float(burst))
  345.         else:
  346.             total = capacity
  347.             current = quantityInClip
  348.         if current <= 0.5 * total:
  349.             state = 'critical' if current == 1 else 'warning'
  350.         return state
  351.  
  352.     def _setClipParams(self, capacity, burst):
  353.         self._flashCall('setClipParams', [capacity, burst])
  354.  
  355.     def _update(self):
  356.         targetID = _g_aimState['target']['id']
  357.         if targetID is not None:
  358.             targ = BigWorld.entity(targetID)
  359.             if targ is None:
  360.                 self.clearTarget()
  361.                 LOG_ERROR('Invalid target ID')
  362.             else:
  363.                 state = _g_aimState['target']
  364.                 state['dist'] = int((targ.position - BigWorld.player().getOwnVehiclePosition()).length)
  365.                 state['health'] = math.ceil(100.0 * max(0, targ.health) / targ.typeDescriptor.maxHealth)
  366.         return
  367.  
  368.     def _flashCall(self, funcName, args = None):
  369.         self.call('Aim.' + funcName, args)
  370.  
  371.  
  372. class StrategicAim(Aim):
  373.  
  374.     def __init__(self, offset, isPostMortem = False):
  375.         Aim.__init__(self, 'strategic', offset)
  376.  
  377.     def create(self):
  378.         Aim.create(self)
  379.         self.__damageCtrl = _DamageIndicatorCtrl(self._offset)
  380.  
  381.     def onRecreateDevice(self):
  382.         Aim.onRecreateDevice(self)
  383.         self.__damageCtrl.onRecreateDevice()
  384.  
  385.     def destroy(self):
  386.         Aim.destroy(self)
  387.         self.__damageCtrl.disable()
  388.         self.__damageCtrl = None
  389.         return
  390.  
  391.     def _enable(self, state, isFirstInit):
  392.         self.__damageCtrl.enable()
  393.         if isFirstInit:
  394.             return
  395.         else:
  396.             Aim._flashCall(self, 'updateDistance', [self._getAimDistance()])
  397.             hs = state['health']
  398.             self._setHealth(hs['cur'], hs['max'])
  399.             rs = state['reload']
  400.             if rs['startTime'] is not None:
  401.                 self._setReloading(rs['duration'], startTime=BigWorld.time() - rs['startTime'], correction=rs['correction'])
  402.             else:
  403.                 self._setReloading(rs['duration'], 0, False)
  404.             capacity, burst = state['clip']
  405.             if capacity > 1:
  406.                 self._setClipParams(capacity, burst)
  407.             self._setAmmoStock(*state['ammo'])
  408.             return
  409.  
  410.     def _disable(self):
  411.         self.__damageCtrl.disable()
  412.  
  413.     def _showHit(self, hitDesc):
  414.         self.__damageCtrl.add(hitDesc)
  415.  
  416.     def _update(self):
  417.         Aim._update(self)
  418.         Aim._flashCall(self, 'updateDistance', [self._getAimDistance()])
  419.  
  420.     def _clearTarget(self, startTime):
  421.         pass
  422.  
  423.     def _getAimDistance(self):
  424.         x, y, z = BigWorld.player().gunRotator.markerInfo[0]
  425.         v = BigWorld.player().getOwnVehiclePosition() - Math.Vector3(x, y, z)
  426.         return int(v.length)
  427.  
  428.  
  429. class PostMortemAim(Aim):
  430.  
  431.     def __init__(self, offset):
  432.         Aim.__init__(self, 'postmortem', offset)
  433.         self.__msgCaption = i18n.makeString('#ingame_gui:player_messages/postmortem_caption')
  434.  
  435.     def create(self):
  436.         Aim.create(self)
  437.         self.__vID = None
  438.         return
  439.  
  440.     def destroy(self):
  441.         Aim.destroy(self)
  442.  
  443.     def applySettings(self, diff):
  444.         Aim.applySettings(self, diff)
  445.         if 'isColorBlind' in diff:
  446.             self.updateAdjust()
  447.  
  448.     def changeVehicle(self, vID):
  449.         self.__vID = vID
  450.         self.updateAdjust()
  451.         if vID == BigWorld.player().playerVehicleID:
  452.             self.updateAmmoState(True)
  453.  
  454.     def updateAdjust(self):
  455.         scheme = _ColorSchemeManager.getSubScheme('vm_ally', self._isColorBlind())
  456.         adjustTuple = _ColorSchemeManager._makeAdjustTuple(scheme)
  457.         self._flashCall('updateAdjust', list(adjustTuple))
  458.  
  459.     def _update(self):
  460.         Aim._update(self)
  461.         if self.__vID is not None:
  462.             vehicle = BigWorld.entity(self.__vID)
  463.             if vehicle is not None:
  464.                 playerName = g_battleContext.getFullPlayerName(vID=self.__vID, showVehShortName=False)
  465.                 type = vehicle.typeDescriptor.type.userString
  466.                 healthPercent = math.ceil(100.0 * max(0, vehicle.health) / vehicle.typeDescriptor.maxHealth)
  467.                 self.__setText(playerName, type, healthPercent)
  468.         Aim._flashCall(self, 'updateTarget', [_g_aimState['target']['dist']])
  469.         return
  470.  
  471.     def __setText(self, name, type, health):
  472.         text = i18n.convert(self.__msgCaption % {'name': name,
  473.          'type': type,
  474.          'health': health})
  475.         Aim._flashCall(self, 'updatePlayerInfo', [text])
  476.  
  477.  
  478. class ArcadeAim(Aim):
  479.  
  480.     def __init__(self, offset, isSniper):
  481.         Aim.__init__(self, 'sniper' if isSniper else 'arcade', offset)
  482.         self.__isSniper = isSniper
  483.  
  484.     def create(self):
  485.         Aim.create(self)
  486.         self.__damageCtrl = _DamageIndicatorCtrl(self._offset)
  487.  
  488.     def destroy(self):
  489.         Aim.destroy(self)
  490.         self.__damageCtrl.disable()
  491.         self.__damageCtrl = None
  492.         return
  493.  
  494.     def _enable(self, state, isFirstInit):
  495.         self.__damageCtrl.enable()
  496.         if isFirstInit:
  497.             return
  498.         else:
  499.             ts = state['target']
  500.             if ts['startTime'] is not None:
  501.                 self._setTarget(ts['name'], ts['vType'], ts['isFriend'])
  502.                 Aim._flashCall(self, 'updateTarget', [ts['dist']])
  503.                 self._clearTarget(BigWorld.time() - ts['startTime'])
  504.             hs = state['health']
  505.             self._setHealth(hs['cur'], hs['max'])
  506.             rs = state['reload']
  507.             if rs['startTime'] is not None:
  508.                 self._setReloading(rs['duration'], startTime=BigWorld.time() - rs['startTime'], correction=rs['correction'])
  509.             else:
  510.                 self._setReloading(rs['duration'], 0, False)
  511.             capacity, burst = state['clip']
  512.             if capacity > 1:
  513.                 self._setClipParams(capacity, burst)
  514.             self._setAmmoStock(*state['ammo'])
  515.             return
  516.  
  517.     def _disable(self):
  518.         self.__damageCtrl.disable()
  519.  
  520.     def setVisible(self, isVisible):
  521.         Aim.setVisible(self, isVisible)
  522.         self.__damageCtrl.setVisible(isVisible)
  523.  
  524.     def onRecreateDevice(self):
  525.         Aim.onRecreateDevice(self)
  526.         self.__damageCtrl.onRecreateDevice()
  527.  
  528.     def _showHit(self, hitDesc):
  529.         self.__damageCtrl.add(hitDesc)
  530.  
  531.     def _update(self):
  532.         Aim._update(self)
  533.         Aim._flashCall(self, 'updateTarget', [_g_aimState['target']['dist']])
  534.  
  535.  
  536. class _DamageIndicatorCtrl():
  537.     _HIT_INDICATOR_MAX_ON_SCREEN = 5
  538.  
  539.     def __init__(self, offset):
  540.         self.proxy = weakref.proxy(self)
  541.         self.__worldToClip = None
  542.         self.__isVisible = True
  543.         self.__offset = offset
  544.         self.__hits = list()
  545.         return
  546.  
  547.     def enable(self):
  548.         for hitDesc in _g_aimState['hitIndicators'][:]:
  549.             self.add(hitDesc)
  550.  
  551.     def disable(self):
  552.         for hitDesc in _g_aimState['hitIndicators']:
  553.             if hitDesc.get('comp', None) is not None:
  554.                 hitDesc['comp'].close()
  555.                 BigWorld.cancelCallback(hitDesc['callbackID'])
  556.                 hitDesc['comp'] = None
  557.                 hitDesc['callbackID'] = None
  558.  
  559.         return
  560.  
  561.     def setVisible(self, isVisible):
  562.         self.__isVisible = isVisible
  563.         for hitDesc in _g_aimState['hitIndicators']:
  564.             if hitDesc.get('comp', None) is not None:
  565.                 hitDesc['comp'].component.visible = isVisible
  566.  
  567.         return
  568.  
  569.     def add(self, hitDesc):
  570.         duration = _DamageIndicator.TOTAL_FRAMES / float(_DamageIndicator.FRAME_RATE)
  571.         globalYaw = hitDesc['gYaw']
  572.         startTime = hitDesc['startTime']
  573.         isDamage = hitDesc['isDamage']
  574.         timePass = BigWorld.time() - startTime
  575.         if timePass >= duration:
  576.             self._remove(startTime)
  577.             return
  578.         if len(_g_aimState['hitIndicators']) >= self._HIT_INDICATOR_MAX_ON_SCREEN:
  579.             self._remove(min((desc['startTime'] for desc in _g_aimState['hitIndicators'])))
  580.         hitInd = _DamageIndicator()
  581.         hitInd.setup(globalYaw, self.__offset)
  582.         hitInd.active(True)
  583.         hitInd.component.visible = self.__isVisible
  584.         hitInd.call('DamageIndicator.setDamageFlagAndAnimFrame', [isDamage, timePass * _DamageIndicator.FRAME_RATE])
  585.         callbackID = BigWorld.callback(duration, partial(callMethod, self.proxy, '_remove', startTime))
  586.         hitDesc['comp'] = hitInd
  587.         hitDesc['callbackID'] = callbackID
  588.  
  589.     def onRecreateDevice(self):
  590.         for desc in _g_aimState['hitIndicators']:
  591.             desc['comp'].setup(desc['gYaw'], self.__offset)
  592.  
  593.     def _remove(self, startTime):
  594.         removedDesc = None
  595.         for desc in _g_aimState['hitIndicators']:
  596.             if desc['startTime'] == startTime:
  597.                 removedDesc = desc
  598.                 break
  599.  
  600.         if removedDesc is not None:
  601.             if removedDesc.get('comp', None) is not None:
  602.                 removedDesc['comp'].close()
  603.             _g_aimState['hitIndicators'].remove(removedDesc)
  604.         return
  605.  
  606.  
  607. class new_DamageIndicator(Flash):
  608.     __SWF_FILE_NAME = 'DamageIndicator.swf'
  609.     __FLASH_CLASS = 'WGHitIndicatorFlash'
  610.     __FLASH_MC_NAME = 'damageMC'
  611.     __FLASH_SIZE = (680, 680)
  612.     TOTAL_FRAMES = 90
  613.     FRAME_RATE = 24
  614.  
  615.     def __init__(self):
  616.         Flash.__init__(self, self.__SWF_FILE_NAME, self.__FLASH_CLASS, [self.__FLASH_MC_NAME])
  617.         self.component.wg_inputKeyMode = 2
  618.         self.component.position.z = DEPTH_OF_Aim
  619.         self.movie.backgroundAlpha = 0.0
  620.         self.component.focus = False
  621.         self.component.moveFocus = False
  622.         self.component.heightMode = 'PIXEL'
  623.         self.component.widthMode = 'PIXEL'
  624.         self.flashSize = self.__FLASH_SIZE
  625.  
  626.     def setup(self, gYaw, offset):
  627.         self.component.position.x = offset[0]
  628.         self.component.position.y = offset[1]
  629.         self.component.wg_globalYaw = gYaw
  630.  
  631.     def __del__(self):
  632.         pass
  633.  
  634. _DamageIndicator = new_DamageIndicator
  635.  
  636. class _TimeInterval():
  637.  
  638.     def __init__(self, interval, funcName, scopeProxy = None):
  639.         self.__cbId = None
  640.         self.__interval = interval
  641.         self.__funcName = funcName
  642.         self.__scopeProxy = scopeProxy
  643.         return
  644.  
  645.     def start(self):
  646.         if self.__cbId is not None:
  647.             LOG_ERROR('To start a new time interval You should before stop already the running time interval.')
  648.             return
  649.         else:
  650.             self.__cbId = BigWorld.callback(self.__interval, self.__update)
  651.             return
  652.  
  653.     def stop(self):
  654.         if self.__cbId is not None:
  655.             BigWorld.cancelCallback(self.__cbId)
  656.             self.__cbId = None
  657.         return
  658.  
  659.     def __update(self):
  660.         self.__cbId = None
  661.         if self.__scopeProxy is not None:
  662.             funcObj = getattr(self.__scopeProxy, self.__funcName, None)
  663.             if funcObj is not None:
  664.                 funcObj()
  665.         self.__cbId = BigWorld.callback(self.__interval, self.__update)
  666.         return
  667.  
  668.  
  669. def clearState():
  670.     global _g_aimState
  671.     _g_aimState = {'isFirstInit': True,
  672.      'target': {'id': None,
  673.                 'dist': 0,
  674.                 'health': 0,
  675.                 'startTime': None,
  676.                 'name': None,
  677.                 'vType': None,
  678.                 'isFriend': None},
  679.      'reload': {},
  680.      'hitIndicators': [],
  681.      'ammo': (0, 0),
  682.      'clip': (1, 1),
  683.      'health': {'cur': None,
  684.                 'max': None}}
  685.     return
  686.  
  687.  
  688. _g_aimState = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement