Advertisement
Guest User

WWIIHWA v1.1

a guest
Apr 16th, 2014
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.81 KB | None | 0 0
  1. """
  2. WOT VERSION: 0.9.0
  3. WOT SERVER : EU/NA/RU
  4. ----------------------
  5. WWIIHWA Script v1.1
  6. ----------------------
  7. (c) Kriegstreiber 2014
  8. ----------------------
  9. """
  10. import BigWorld
  11. import ResMgr
  12. from debug_utils import *
  13. from gui import SystemMessages
  14. CFG = {}
  15. msg_info = ''
  16. msg_error =''
  17.  
  18. def push_system_messages():
  19.     try:
  20.         if len(msg_info) != 0:
  21.             if SystemMessages.g_instance is None:
  22.                 BigWorld.callback(4.0, push_system_messages)
  23.             else:
  24.                 SystemMessages.pushMessage(msg_info, type=SystemMessages.SM_TYPE.Information)
  25.         if len(msg_error) != 0:
  26.             if SystemMessages.g_instance is None:
  27.                 BigWorld.callback(4.0, push_system_messages)
  28.             else:
  29.                 SystemMessages.pushMessage(msg_error, type=SystemMessages.SM_TYPE.Error)
  30.     except:
  31.         LOG_CURRENT_EXCEPTION()
  32.  
  33.     return
  34.  
  35. try:
  36.     WWIIHWA = ResMgr.openSection('gui/WWIIHWA.xml')
  37.     if WWIIHWA is not None:
  38.         CFG['autoequip'] = WWIIHWA.readBool('autoequip')
  39.         CFG['battletimer'] = WWIIHWA.readBool('battletimer')
  40.         print '[NOTE] WWIIHWA Ambiente v3.5 succesfully loaded.'
  41.         msg_info = 'Welcome to the WWIIHWA Mod.'
  42.     else:
  43.         CFG['autoequip'] = True
  44.         CFG['battletimer'] = True
  45.         print '[WARNING] WWIIHWA Ambiente v3.5 XMLs not found or invalid !'
  46.         msg_error = 'Something wrong by initializing WWIIHWA. Please check Python log file.'
  47. except:
  48.     print '[ERROR] XML (".../gui/WWIIHWA.xml") not found or invalid !'
  49.  
  50. if CFG['battletimer'] is True:
  51.     try:
  52.         import BattleReplay
  53.         from gui.shared.utils.sound import Sound
  54.         from gui.Scaleform import Battle
  55.         from string import Template
  56.         from Avatar import PlayerAvatar as pa
  57.         pa.snd3min = None
  58.         pa.snd1min = None
  59.         pa.snd30sec = None
  60.         pa.snd5sec = None
  61.         delay = 2
  62.         arenaLength = 0
  63.         try:
  64.             CONFIG = ResMgr.openSection('gui/battletimer.xml')
  65.             if CONFIG is not None:
  66.                 CFG['3mins'] = CONFIG.readString('t3mins')
  67.                 CFG['1min'] = CONFIG.readString('t1min')
  68.                 CFG['30secs'] = CONFIG.readString('t30secs')
  69.                 CFG['5secs'] = CONFIG.readString('t5secs')
  70.             else:
  71.                 CFG['3mins'] = '/GUI/notifications_FX/battle_timer/EN/3mins'
  72.                 CFG['1min'] = '/GUI/notifications_FX/battle_timer/EN/1min'
  73.                 CFG['30secs'] = '/GUI/notifications_FX/battle_timer/EN/30secs'
  74.                 CFG['5secs'] = '/GUI/notifications_FX/battle_timer/EN/5secs'
  75.         except:
  76.             print '[ERROR]WWIIHWA XML (".../gui/battletimer.xml") not found or invalid !'
  77.  
  78.         def stopSounds():
  79.                 pa.snd3min.stop()
  80.                 pa.snd1min.stop()
  81.                 pa.snd30sec.stop()
  82.                 pa.snd5sec.stop()
  83.  
  84.         def checktime(arenaLength, period):
  85.             if period != 3:
  86.                 stopSounds()
  87. #                initial()
  88.                 return
  89.             if arenaLength == 180 and not pa.snd3min.isPlaying:
  90.                 pa.snd3min.play()
  91.             elif arenaLength == 60 and not pa.snd1min.isPlaying:
  92.                 pa.snd1min.play()
  93.             elif arenaLength == 30 and not pa.snd30sec.isPlaying:
  94.                 pa.snd30sec.play()
  95.             elif arenaLength == 5 and not pa.snd5sec.isPlaying:
  96.                 pa.snd5sec.play()
  97.  
  98.  
  99.         old_setArenaTime = Battle.Battle._Battle__setArenaTime
  100.  
  101.         def newsetArenaTime(self):
  102.             if hasattr(BigWorld.player(), 'shop') or BigWorld.player().arena is None:
  103.                 old_setArenaTime(self)
  104.                 return
  105.             else:
  106.                 period = BigWorld.player().arena.period
  107.                 replayCtrl = BattleReplay.g_replayCtrl
  108.                 if replayCtrl.isPlaying:
  109.                     arenaLength = int(replayCtrl.getArenaLength())
  110.                 else:
  111.                     arenaLength = int(BigWorld.player().arena.periodEndTime - BigWorld.serverTime())
  112.                 checktime(arenaLength, period)
  113.                 old_setArenaTime(self)
  114.                 return
  115.  
  116.  
  117.         Battle.Battle._Battle__setArenaTime = newsetArenaTime
  118.  
  119.         def __startBattleL():
  120.             pa.snd3min = Sound(CFG['3mins'])
  121.             pa.snd1min = Sound(CFG['1min'])
  122.             pa.snd30sec = Sound(CFG['30secs'])
  123.             pa.snd5sec = Sound(CFG['5secs'])
  124.  
  125.     except:
  126.         LOG_CURRENT_EXCEPTION()
  127.  
  128. if CFG['autoequip'] is True:
  129.     try:
  130.         from CurrentVehicle import g_currentVehicle
  131.         from gui.Scaleform.daapi.view.lobby.hangar.AmmunitionPanel import AmmunitionPanel
  132.         from gui.shared import g_itemsCache, REQ_CRITERIA
  133.         from gui.shared.utils.requesters import Requester
  134.         from debug_utils import *
  135.         from adisp import process
  136.         g_or_setVehicleModule = None
  137.         g_xmlSetting = None
  138.         g_prevVehicle = None
  139.  
  140.         def getDeviceInventoryCounts(inventoryDevices, device):
  141.             invCount = 0
  142.             try:
  143.                 invCount = inventoryDevices[inventoryDevices.index(device)].count
  144.             except Exception:
  145.                 pass
  146.  
  147.             return invCount
  148.  
  149.  
  150.         def equipAllRemovableDevicesOnVehicle(vehicle):
  151.             global g_xmlSetting
  152.  
  153.             def callback(resultID):
  154.                 pass
  155.  
  156.             if g_xmlSetting[vehicle.name]:
  157.                 for slotIdx in range(0, 3):
  158.                     device = vehicle.descriptor.optionalDevices[slotIdx]
  159.                     if not device:
  160.                         deviceCompactDescr = g_xmlSetting[vehicle.name].readInt('slot' + str(slotIdx + 1), 0)
  161.                         if deviceCompactDescr is not 0:
  162.                             BigWorld.player().inventory.equipOptionalDevice(vehicle.invID, deviceCompactDescr, slotIdx, False, callback)
  163.  
  164.  
  165.         @process
  166.         def removeAllRemovableDevicesFromAllVehicle(curVehicle):
  167.  
  168.             def callback(resultID):
  169.                 pass
  170.  
  171.             deviceAllInventory = yield Requester('optionalDevice').getFromInventory()
  172.             alreadyRemoved = []
  173.             vehicles = g_itemsCache.items.getVehicles(REQ_CRITERIA.INVENTORY).values()
  174.             for vehicle in vehicles:
  175.                 if curVehicle is not vehicle:
  176.                     if not vehicle.isInBattle:
  177.                         for slotIdx in range(0, 3):
  178.                             device = vehicle.descriptor.optionalDevices[slotIdx]
  179.                             if device and device.removable:
  180.                                 devCount = getDeviceInventoryCounts(deviceAllInventory, device)
  181.                                 if devCount is 0 and device.compactDescr not in alreadyRemoved:
  182.                                     BigWorld.player().inventory.equipOptionalDevice(vehicle.invID, 0, slotIdx, False, callback)
  183.                                     alreadyRemoved.append(device.compactDescr)
  184.  
  185.  
  186.         def onCurrentVehicleChanged(prevVehicle, curVehicle):
  187.             removeAllRemovableDevicesFromAllVehicle(curVehicle)
  188.             equipAllRemovableDevicesOnVehicle(curVehicle)
  189.  
  190.  
  191.         def vehicleCheckCallback():
  192.             global g_prevVehicle
  193.             if g_currentVehicle.isInHangar:
  194.                 curVehicle = g_currentVehicle.item
  195.                 if g_prevVehicle is not curVehicle:
  196.                     if g_prevVehicle and curVehicle:
  197.                         if g_prevVehicle.name is not curVehicle.name:
  198.                             onCurrentVehicleChanged(g_prevVehicle, curVehicle)
  199.                     g_prevVehicle = curVehicle
  200.             BigWorld.callback(0.1, vehicleCheckCallback)
  201.  
  202.  
  203.         def saveDeviceOnVehicle(vehicle, deviceId, slotId, isRemove):
  204.             g_xmlSetting.write(vehicle.name, '')
  205.             if isRemove:
  206.                 g_xmlSetting[vehicle.name].writeInt('slot' + str(slotId + 1), 0)
  207.             else:
  208.                 g_xmlSetting[vehicle.name].writeInt('slot' + str(slotId + 1), int(deviceId))
  209.             g_xmlSetting.save()
  210.  
  211.  
  212.         def hook_setVehicleModule(self, newId, slotIdx, oldId, isRemove):
  213.             global g_or_setVehicleModule
  214.             g_or_setVehicleModule(self, newId, slotIdx, oldId, isRemove)
  215.             vehicle = g_currentVehicle.item
  216.             saveDeviceOnVehicle(vehicle, newId, slotIdx, isRemove)
  217.  
  218.  
  219.         def init():
  220.             global g_or_setVehicleModule
  221.             global g_xmlSetting
  222.             g_xmlSetting = ResMgr.openSection('gui/AutoEquip.xml', True)
  223.             if not g_xmlSetting:
  224.                 g_xmlSetting.save()
  225.             g_or_setVehicleModule = AmmunitionPanel.setVehicleModule
  226.             AmmunitionPanel.setVehicleModule = hook_setVehicleModule
  227.             vehicleCheckCallback()
  228.  
  229.  
  230.         init()
  231.     except:
  232.         LOG_CURRENT_EXCEPTION()
  233.  
  234. BigWorld.callback(6.0, push_system_messages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement