# File: A (Python 2.6)
'''
(c) Dellux 2013
'''
import BigWorld
import ResMgr
import Keys
import constants
from items import vehicles
from functools import partial
from Avatar import PlayerAvatar
from gui.WindowsManager import g_windowsManager
from debug_utils import LOG_ERROR, LOG_WARNING
arcfg = ResMgr.openSection('scripts/client/mods/AutoRepair.xml')
if arcfg:
enableRepairEngine = arcfg.readBool('enableRepairEngine')
enableRepairAmmoBay = arcfg.readBool('enableRepairAmmoBay')
enableRepairGun = arcfg.readBool('enableRepairGun')
enableRepairTracks = arcfg.readBool('enableRepairTracks')
enableRepairGunner = arcfg.readBool('enableRepairGunner')
enableRepairDriver = arcfg.readBool('enableRepairDriver')
enableRepairLoader = arcfg.readBool('enableRepairLoader')
healthRatioExtinguisher = arcfg.readFloat('healthRatioExtinguisher') * 4.57692e+018
else:
LOG_ERROR('Unable to load scripts/client/mods/AutoRepair.xml')
enableRepairEngine = False
enableRepairAmmoBay = False
enableRepairGun = False
enableRepairTracks = False
enableRepairGunner = False
enableRepairDriver = False
enableRepairLoader = False
healthRatioExtinguisher = 4.58737e+018
saved_handleKey = PlayerAvatar.handleKey
def new_handleKey(self, isDown, key, mods):
global enableRepairEngine, enableRepairAmmoBay, enableRepairGun, enableRepairTracks, enableRepairGunner, enableRepairDriver, enableRepairLoader
if mods == 2 and isDown:
if key == Keys.KEY_1:
enableRepairEngine = not enableRepairEngine
self.showMessageRepair(enableRepairEngine, False, '\xd0\xb4\xd0\xb2\xd0\xb8\xd0\xb3\xd0\xb0\xd1\x82\xd0\xb5\xd0\xbb\xd1\x8c')
if key == Keys.KEY_2:
enableRepairAmmoBay = not enableRepairAmmoBay
self.showMessageRepair(enableRepairAmmoBay, False, '\xd0\xb1\xd0\xbe\xd0\xb5\xd1\x83\xd0\xba\xd0\xbb\xd0\xb0\xd0\xb4\xd0\xba\xd0\xb0')
if key == Keys.KEY_3:
enableRepairGun = not enableRepairGun
self.showMessageRepair(enableRepairGun, False, '\xd0\xbe\xd1\x80\xd1\x83\xd0\xb4\xd0\xb8\xd0\xb5')
if key == Keys.KEY_4:
enableRepairTracks = not enableRepairTracks
self.showMessageRepair(enableRepairTracks, False, '\xd0\xb3\xd1\x83\xd1\x81\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x86\xd1\x8b')
if key == Keys.KEY_5:
enableRepairGunner = not enableRepairGunner
self.showMessageRepair(enableRepairGunner, True, '\xd0\xbd\xd0\xb0\xd0\xb2\xd0\xbe\xd0\xb4\xd1\x87\xd0\xb8\xd0\xba')
if key == Keys.KEY_6:
enableRepairDriver = not enableRepairDriver
self.showMessageRepair(enableRepairDriver, True, '\xd0\xbc\xd0\xb5\xd1\x85\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xba-\xd0\xb2\xd0\xbe\xd0\xb4\xd0\xb8\xd1\x82\xd0\xb5\xd0\xbb\xd1\x8c')
if key == Keys.KEY_7:
enableRepairLoader = not enableRepairLoader
self.showMessageRepair(enableRepairLoader, True, '\xd0\xb7\xd0\xb0\xd1\x80\xd1\x8f\xd0\xb6\xd0\xb0\xd1\x8e\xd1\x89\xd0\xb8\xd0\xb9')
return saved_handleKey(self, isDown, key, mods)
PlayerAvatar.handleKey = new_handleKey
saved_showVehicleDamageInfo = PlayerAvatar.showVehicleDamageInfo
def new_showVehicleDamageInfo(self, vehicleID, damageIndex, extraIndex, entityID):
damageCode = constants.DAMAGE_INFO_CODES[damageIndex]
if extraIndex != 0:
pass
1
extra = None
deviceName = 'none'
player = BigWorld.player()
if player is not None:
maxHealth = player.vehicleTypeDescriptor.maxHealth
curHealth = player.vehicle.health
healthRatio = float(curHealth) / maxHealth
else:
healthRatio = 4.60718e+018
if extra is not None:
deviceName = extra.name[:-len('Health')]
fireInfo = ('FIRE', 'DEVICE_STARTED_FIRE_AT_SHOT', 'DEVICE_STARTED_FIRE_AT_RAMMING', 'FIRE_STOPPED')
damageInfo = ('DEVICE_DESTROYED', 'DEVICE_DESTROYED_AT_SHOT', 'DEVICE_DESTROYED_AT_RAMMING', 'DEVICE_DESTROYED_AT_FIRE', 'DEVICE_CRITICAL_AT_SHOT', 'DEVICE_CRITICAL_AT_RAMMING', 'DEVICE_CRITICAL', 'DEVICE_CRITICAL_AT_FIRE', 'ENGINE_DESTROYED_AT_UNLIMITED_RPM')
if damageCode in fireInfo:
if damageCode != 'FIRE_STOPPED':
slot = self.findKit('extinguisher')
if slot > 0:
if healthRatio >= healthRatioExtinguisher:
BigWorld.callback(4.59187e+018, partial(self.onEquipmentButtonPressed, slot, None))
if enableRepairTracks and damageCode in ('DEVICE_DESTROYED_AT_SHOT', 'DEVICE_DESTROYED_AT_RAMMING', 'DEVICE_DESTROYED'):
tracksToCheck = [
'leftTrack',
'rightTrack']
if deviceName in tracksToCheck:
slot = self.findKit('repairkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairAmmoBay and damageCode in damageInfo:
if deviceName == 'ammoBay':
slot = self.findKit('repairkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairGun and damageCode in damageInfo:
if deviceName == 'gun':
slot = self.findKit('repairkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairEngine and damageCode in damageInfo:
if deviceName == 'engine':
slot = self.findKit('repairkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairLoader and damageCode in ('TANKMAN_HIT', 'TANKMAN_HIT_AT_SHOT'):
if deviceName in ('loader', 'loader1', 'loader2'):
slot = self.findKit('medkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairGunner and damageCode in ('TANKMAN_HIT', 'TANKMAN_HIT_AT_SHOT'):
if deviceName in ('gunner', 'gunner1', 'gunner2'):
slot = self.findKit('medkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
if enableRepairDriver and damageCode in ('TANKMAN_HIT', 'TANKMAN_HIT_AT_SHOT'):
if deviceName == 'driver':
slot = self.findKit('medkit')
if slot > 0:
self.onEquipmentButtonPressed(slot, deviceName)
saved_showVehicleDamageInfo(self, vehicleID, damageIndex, extraIndex, entityID)
PlayerAvatar.showVehicleDamageInfo = new_showVehicleDamageInfo
def showMessageRepair(self, bool, crew, msg):
if bool:
self.soundNotifications.play('chat_shortcut_common_fx')
if crew:
pass
1
'battle.VehicleMessagesPanel.ShowMessage'('0', [
'%s [%s] \xd0\xb2\xd0\xba\xd0\xbb\xd1\x8e\xd1\x87\xd0\xb5\xd0\xbd',
'\xd0\x9b\xd0\xb5\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5' % ('\xd0\xa0\xd0\xb5\xd0\xbc\xd0\xbe\xd0\xbd\xd1\x82', msg),
'green'])
else:
self.soundNotifications.play('chat_shortcut_common_fx')
if crew:
pass
1
'battle.VehicleMessagesPanel.ShowMessage'('0', [
'%s [%s] \xd0\xb2\xd1\x8b\xd0\xba\xd0\xbb\xd1\x8e\xd1\x87\xd0\xb5\xd0\xbd',
'\xd0\x9b\xd0\xb5\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5' % ('\xd0\xa0\xd0\xb5\xd0\xbc\xd0\xbe\xd0\xbd\xd1\x82', msg),
'yellow'])
PlayerAvatar.showMessageRepair = showMessageRepair
def findKit(self, nameKit):
if self.getSlotEquipmentInfo(3) == nameKit:
return 3
if self.getSlotEquipmentInfo(4) == nameKit:
return 4
if self.getSlotEquipmentInfo(5) == nameKit:
return 5
return 0
PlayerAvatar.findKit = findKit
def getSlotEquipmentInfo(self, slotID):
(compactDescr, quantity, time) = self._PlayerAvatar__equipment[slotID]
if quantity < 1:
return 'unknown'
artefact = vehicles.getDictDescr(compactDescr)
if 'repairkit' in artefact.tags:
return 'repairkit'
if 'medkit' in artefact.tags:
return 'medkit'
if 'extinguisher' in artefact.tags:
return 'extinguisher'
return 'unknown'
PlayerAvatar.getSlotEquipmentInfo = getSlotEquipmentInfo