Advertisement
Guest User

GameOver Notify v6.0

a guest
Sep 1st, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.59 KB | None | 0 0
  1. import re
  2. import os
  3. import GUI
  4. import Math
  5. import BigWorld
  6. from json import loads
  7. from ResMgr import openSection
  8. from gui import g_guiResetters
  9. from gui import DEPTH_OF_GunMarker
  10. from constants import ARENA_PERIOD
  11. from messenger import MessengerEntry
  12. from PlayerEvents import g_playerEvents
  13. from gui.Scaleform.Battle import Battle
  14. from gui.shared.utils.sound import Sound
  15.  
  16. AppName = 'GameOver_Notify'
  17. AppFile = AppName + '.json'
  18.  
  19. g_text = None
  20. g_other_team = 0
  21. g_onetime = 0
  22. g_my_team = 0
  23.  
  24. def DefaultConfig():
  25.     return {'ArenaPanel': {
  26.           'posX': 0,
  27.           'posY': 100,
  28.           'hcentered': True,
  29.           'vcentered': True,
  30.           'font': 'default_small'},
  31.                  'TimeOut': {
  32.           'Chat': {'enabled': True,
  33.           'message': u'Время вышло',
  34.           'color': '#4CFF47'},
  35.           'Arena': {'enabled': True,
  36.           'message': u'Время вышло',
  37.           'color': '#4cff47',
  38.           'time': 3.0},
  39.           'Sound': {'enabled': True,
  40.           'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
  41.                  'TeamBasePoints': {
  42.           'Chat': {
  43.           '50': {'enabled': True,
  44.           'message': u'База захвачена на 50%',
  45.           'color': '#FFFF47',
  46.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
  47.           '70': {'enabled': True,
  48.           'message': u'База захвачена на 70%',
  49.           'color': '#FF9F34',
  50.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
  51.           '90': {'enabled': True,
  52.           'message': 'База захвачена на 90%',
  53.           'color': '#FF0000',
  54.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'}},
  55.           'Arena': {
  56.           '50': {'enabled': True,
  57.           'message': u'База захвачена на 50%',
  58.           'time': 3.0,
  59.           'color': '#FFFF47',
  60.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
  61.           '70': {'enabled': True,
  62.           'message': u'База захвачена на 70%',
  63.           'time': 3.0,
  64.           'color': '#FF9F34',
  65.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
  66.           '90': {'enabled': True,
  67.           'message': 'База захвачена на 90%',
  68.           'time': 3.0,
  69.           'color': '#FF0000',
  70.           'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'}}},
  71.                  'TeamBaseCaptured': {
  72.           'Chat': {'enabled': True,
  73.           'message': u'База захвачена',
  74.           'color': '#CC0006'},
  75.           'Arena': {'enabled': True,
  76.           'message': u'База захвачена',
  77.           'color': '#CC0006',
  78.           'time': 3.0},
  79.           'Sound': {'enabled': True,
  80.           'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
  81.                  'VehicleKilled': {
  82.           'enabled': True,
  83.           'allies': u'Союзники',
  84.           'opponents': u'Противники',
  85.           'Colors': {
  86.           'color1': '#83FF79',
  87.           'color2': '#FF0000',
  88.           'color3': '#FFFF93'},
  89.           'MyTeamDestroyed': {
  90.           'Chat': {'enabled': True,
  91.           'message': u'Ваша команда уничтожена',
  92.           'color': '#FF0000'},
  93.           'Arena': {'enabled': True,
  94.           'message': u'Ваша команда уничтожена',
  95.           'color': '#FF0000',
  96.           'time': 3.0},
  97.           'Sound': {'enabled': True,
  98.           'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
  99.           'TheEnemyTeamDestroyed': {
  100.           'Chat': {'enabled': True,
  101.           'message': u'Команда противника уничтожена',
  102.           'color': '#4CFF47'},
  103.           'Arena': {'enabled': True,
  104.           'message': u'Команда противника уничтожена',
  105.           'color': '#4CFF47',
  106.           'time': 3.0},
  107.           'Sound': {'enabled': True,
  108.           'paths': 'ingame_voice/notifications_VO/target_unlocked'}}
  109.           }
  110.           }
  111.  
  112. def FixPath(path):
  113.     a = path.split('/')
  114.     restore = False
  115.     if not a[0]:
  116.         a[0] = '_'
  117.         restore = True
  118.     path = os.path.join(*a)
  119.     if restore:
  120.         return path[1:]
  121.     return path
  122.  
  123.  
  124. def PythonInfo(text):
  125.     try:
  126.         return text.encode('windows-1251')
  127.     except:
  128.         return text
  129.  
  130.  
  131. def PrintError(*args):
  132.     Error = PythonInfo('[' + AppName + ']: ' + str(*args))
  133.     print Error
  134.  
  135.  
  136. def Comments(string, strip_space = True):
  137.     tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r')
  138.     end_slashes_re = re.compile(r'(\\)*$')
  139.     in_string = False
  140.     in_multi = False
  141.     in_single = False
  142.     new_str = []
  143.     index = 0
  144.     for match in re.finditer(tokenizer, string):
  145.         if not (in_multi or in_single):
  146.             tmp = string[index:match.start()]
  147.             if not in_string and strip_space:
  148.                 tmp = re.sub('[ \t\n\r]+', '', tmp)
  149.             new_str.append(tmp)
  150.         index = match.end()
  151.         val = match.group()
  152.         if val == '"' and not (in_multi or in_single):
  153.             escaped = end_slashes_re.search(string, 0, match.start())
  154.             if not in_string or (escaped is None or len(escaped.group()) % 2 == 0):
  155.                 in_string = not in_string
  156.             index -= 1
  157.         elif not (in_string or in_multi or in_single):
  158.             if val == '/*':
  159.                 in_multi = True
  160.             elif val == '//':
  161.                 in_single = True
  162.         elif val == '*/' and in_multi and not (in_string or in_single):
  163.             in_multi = False
  164.         elif val in '\r\n' and not (in_multi or in_string) and in_single:
  165.             in_single = False
  166.         elif not ((in_multi or in_single) or (val in ' \r\n\t' and strip_space)):
  167.             new_str.append(val)
  168.     new_str.append(string[index:])
  169.     return ''.join(new_str)
  170.  
  171.  
  172. def ConfigSection(directory):
  173.     return openSection(FixPath('../paths.xml'))['Paths'].values()[0].asString + FixPath('/' + directory)
  174.  
  175.  
  176. def GameOver_Notify_Cfg():
  177.     global Cfg
  178.     Cfg = None
  179.     conf_file = None
  180.     try:
  181.         conf_file = ConfigSection('scripts/client/mods/' + AppFile)
  182.         file = open(conf_file)
  183.         Cfg = loads(Comments(file.read()))
  184.         file.close()
  185.         print ''
  186.         print '-------------------------------------------------------------------------'
  187.         print PythonInfo(u'[' + AppName + u']: [' + AppName + u' by Ekspoint & waza123, Pepto_]')
  188.         print PythonInfo(u'[' + AppName + u']: Конфиг файл [' + AppFile + u'] Успешно загрузился.')
  189.         print '-------------------------------------------------------------------------'
  190.         print ''
  191.     except Exception as err:
  192.         print ''
  193.         print '-----------------------------------------------------------------------------------------------------------'
  194.         print PythonInfo(u'[' + AppName + u']: [' + AppName + u' by Ekspoint & waza123, Pepto_]')
  195.         PrintError(err)
  196.         print PythonInfo(u'[' + AppName + u']: Конфиг файл [' + AppFile + u'] не правильно настроен или не найден.')
  197.         print PythonInfo(u'[' + AppName + u']: Загружаю из мода встроенный конфиг' + ' ' + '[' + AppFile + ']')
  198.         print '-----------------------------------------------------------------------------------------------------------'
  199.         print ''
  200.         Cfg = DefaultConfig()
  201.  
  202.     return
  203.  
  204.  
  205. GameOver_Notify_Cfg()
  206.  
  207.  
  208. def PeriodChange(period, *args):
  209.     global g_onetime
  210.     arena = BigWorld.player().arena
  211.     if arena is not None:
  212.         if arena.period == ARENA_PERIOD.AFTERBATTLE and g_onetime != 1:
  213.             g_onetime = 1
  214.             if Cfg['TimeOut']['Chat']['enabled']:
  215.                 nst_logs(Cfg['TimeOut']['Chat']['message'], Cfg['TimeOut']['Chat']['color'])
  216.             if Cfg['TimeOut']['Arena']['enabled']:
  217.                 nst_text(Cfg['TimeOut']['Arena']['message'], Cfg['TimeOut']['Arena']['time'], Cfg['TimeOut']['Arena']['color'], Cfg['ArenaPanel']['font'])
  218.             if Cfg['TimeOut']['Sound']['enabled']:
  219.                 Sound('/' + Cfg['TimeOut']['Sound']['paths']).play()
  220.     return
  221.  
  222.  
  223. def nst_logs(message, color = '#FF0000'):
  224.     MessengerEntry.g_instance.gui.addClientMessage('<font color="' + color + '">' + message + '</font>')
  225.  
  226.  
  227. def nst_text(message, time, color = '#FFFFFF', font = 'hpmp_panel'):
  228.     global g_text
  229.     if g_text is not None:
  230.         GUI.delRoot(g_text)
  231.         g_text = None
  232.     g_text = GUI.Text('')
  233.     g_text.verticalAnchor = 'TOP' #выравнивание элемента по оси Y (top, center, bottom).
  234.     g_text.horizontalAnchor = 'CENTER' #выравнивание элемента по оси Х (left, center, right).
  235.     g_text.widthMode = 'PIXEL'
  236.     g_text.heightMode = 'PIXEL'
  237.     g_text.verticalPositionMode = 'PIXEL'
  238.     g_text.horizontalPositionMode = 'PIXEL'
  239.     g_text.colourFormatting = True
  240.     color = '\\c' + re.sub('[^A-Za-z0-9]+', '', color) + 'FF;'
  241.     font = font + '.font'
  242.     g_text.font = font
  243.     g_text.text = color + message
  244.     GUI.addRoot(g_text)
  245.     onChangeScreenResolution()
  246.     BigWorld.callback(time, nst_del_text)
  247.     return
  248.  
  249.  
  250. def onChangeScreenResolution():
  251.     sr = GUI.screenResolution()
  252.     if g_text is None:
  253.         return
  254.     x = sr[0] / 2 + Cfg['ArenaPanel']['posX'] if Cfg['ArenaPanel']['hcentered'] else Cfg['ArenaPanel']['posX']
  255.     y = sr[1] / 2 + Cfg['ArenaPanel']['posY'] if Cfg['ArenaPanel']['vcentered'] else Cfg['ArenaPanel']['posY']
  256.     g_text.position = (x, y, DEPTH_OF_GunMarker)
  257.     return
  258.  
  259. g_guiResetters.add(onChangeScreenResolution)
  260.  
  261. def Setup():
  262.     global g_onetime
  263.     global g_other_team
  264.     global g_my_team
  265.     g_other_team = 0
  266.     g_onetime = 0
  267.     g_my_team = 0
  268.  
  269.  
  270. def new_Battle_afterCreate(self):
  271.     Setup()
  272.     old_Battle_afterCreate(self)
  273.  
  274.  
  275. old_Battle_afterCreate = Battle.afterCreate
  276. Battle.afterCreate = new_Battle_afterCreate
  277.  
  278. def nst_del_text():
  279.     global g_text
  280.     if g_text is not None:
  281.         GUI.delRoot(g_text)
  282.         g_text = None
  283.     return
  284.  
  285.  
  286. def TeamBasePointsUpdate(team, baseID, points, capturingStopped):
  287.     if g_onetime != 1:
  288.         if points == 50:
  289.             if Cfg['TeamBasePoints']['Chat']['50']['enabled']:
  290.                 nst_logs(Cfg['TeamBasePoints']['Chat']['50']['message'], Cfg['TeamBasePoints']['Chat']['50']['color'])
  291.                 Sound('/' + Cfg['TeamBasePoints']['Chat']['50']['sound']).play()
  292.             if Cfg['TeamBasePoints']['Arena']['50']['enabled']:
  293.                 nst_text(Cfg['TeamBasePoints']['Arena']['50']['message'], Cfg['TeamBasePoints']['Arena']['50']['time'], Cfg['TeamBasePoints']['Arena']['50']['color'], Cfg['ArenaPanel']['font'])
  294.                 Sound('/' + Cfg['TeamBasePoints']['Arena']['50']['sound']).play()
  295.         if points == 70:
  296.             if Cfg['TeamBasePoints']['Chat']['70']['enabled']:
  297.                 nst_logs(Cfg['TeamBasePoints']['Chat']['70']['message'], Cfg['TeamBasePoints']['Chat']['70']['color'])
  298.                 Sound('/' + Cfg['TeamBasePoints']['Chat']['70']['sound']).play()
  299.             if Cfg['TeamBasePoints']['Arena']['70']['enabled']:
  300.                 nst_text(Cfg['TeamBasePoints']['Arena']['70']['message'], Cfg['TeamBasePoints']['Arena']['70']['time'], Cfg['TeamBasePoints']['Arena']['70']['color'], Cfg['ArenaPanel']['font'])
  301.                 Sound('/' + Cfg['TeamBasePoints']['Arena']['70']['sound']).play()
  302.         if points == 90:
  303.             if Cfg['TeamBasePoints']['Chat']['90']['enabled']:
  304.                 nst_logs(Cfg['TeamBasePoints']['Chat']['90']['message'], Cfg['TeamBasePoints']['Chat']['90']['color'])
  305.                 Sound('/' + Cfg['TeamBasePoints']['Chat']['90']['sound']).play()
  306.             if Cfg['TeamBasePoints']['Arena']['90']['enabled']:
  307.                 nst_text(Cfg['TeamBasePoints']['Arena']['90']['message'], Cfg['TeamBasePoints']['Arena']['90']['time'], Cfg['TeamBasePoints']['Arena']['90']['color'], Cfg['ArenaPanel']['font'])
  308.                 Sound('/' + Cfg['TeamBasePoints']['Arena']['90']['sound']).play()
  309.  
  310.  
  311. def TeamBaseCaptured(team, baseID):
  312.     global g_onetime
  313.     if g_onetime != 1:
  314.         g_onetime = 1
  315.         if Cfg['TeamBaseCaptured']['Chat']['enabled']:
  316.             nst_logs(Cfg['TeamBaseCaptured']['Chat']['message'], Cfg['TeamBaseCaptured']['Chat']['color'])
  317.         if Cfg['TeamBaseCaptured']['Arena']['enabled']:
  318.             nst_text(Cfg['TeamBaseCaptured']['Arena']['message'], Cfg['TeamBaseCaptured']['Arena']['time'], Cfg['TeamBaseCaptured']['Arena']['color'], Cfg['ArenaPanel']['font'])
  319.         if Cfg['TeamBaseCaptured']['Sound']['enabled']:
  320.             Sound('/' + Cfg['TeamBaseCaptured']['Sound']['paths']).play()
  321.  
  322.  
  323. def VehicleKilled(victimID, killerID, equipmentID, reason):
  324.     global g_onetime
  325.     global g_other_team
  326.     global g_my_team
  327.     arena = BigWorld.player().arena
  328.     if arena is not None:
  329.         total_other_team_players = len(BigWorld.player().arena.vehicles) / 2
  330.         if total_other_team_players != 0:
  331.             if BigWorld.player().team == BigWorld.player().arena.vehicles[victimID]['team']:
  332.                 g_my_team = g_my_team + 1
  333.                 c = Cfg['VehicleKilled']['Colors']['color2']
  334.                 if g_my_team > g_other_team:
  335.                     c = Cfg['VehicleKilled']['Colors']['color2']
  336.                 if g_my_team < g_other_team:
  337.                     c = Cfg['VehicleKilled']['Colors']['color1']
  338.                 if g_my_team == g_other_team:
  339.                     c = Cfg['VehicleKilled']['Colors']['color3']
  340.                 if Cfg['VehicleKilled']['enabled']:
  341.                     nst_logs(Cfg['VehicleKilled']['allies'] + '  ' + str(total_other_team_players - g_my_team) + '  ' + str(total_other_team_players - g_other_team) + '  ' + Cfg['VehicleKilled']['opponents'], c)
  342.                 if total_other_team_players == g_my_team and g_onetime != 1:
  343.                     g_onetime = 1
  344.                     if Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['enabled']:
  345.                         nst_logs(Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['message'], Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['color'])
  346.                     if Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['enabled']:
  347.                         nst_text(Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['message'], Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['time'], Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['color'], Cfg['ArenaPanel']['font'])
  348.                     if Cfg['VehicleKilled']['MyTeamDestroyed']['Sound']['enabled']:
  349.                         Sound('/' + Cfg['VehicleKilled']['MyTeamDestroyed']['Sound']['paths']).play()
  350.             if BigWorld.player().team != BigWorld.player().arena.vehicles[victimID]['team']:
  351.                 g_other_team = g_other_team + 1
  352.                 c = Cfg['VehicleKilled']['Colors']['color2']
  353.                 if g_my_team > g_other_team:
  354.                     c = Cfg['VehicleKilled']['Colors']['color2']
  355.                 if g_my_team < g_other_team:
  356.                     c = Cfg['VehicleKilled']['Colors']['color1']
  357.                 if g_my_team == g_other_team:
  358.                     c = Cfg['VehicleKilled']['Colors']['color3']
  359.                 if Cfg['VehicleKilled']['enabled']:
  360.                     nst_logs(Cfg['VehicleKilled']['allies'] + '  ' + str(total_other_team_players - g_my_team) + '   ' + str(total_other_team_players - g_other_team) + '  ' + Cfg['VehicleKilled']['opponents'], c)
  361.                 if total_other_team_players == g_other_team and g_onetime != 1:
  362.                     g_onetime = 1
  363.                     if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['enabled']:
  364.                         nst_logs(Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['message'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['color'])
  365.                     if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['enabled']:
  366.                         nst_text(Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['message'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['time'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['color'], Cfg['ArenaPanel']['font'])
  367.                     if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Sound']['enabled']:
  368.                         Sound('/' + Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Sound']['paths']).play()
  369.     return
  370.  
  371.  
  372. def avatarReady():
  373.     arena = BigWorld.player().arena
  374.     if arena is not None:
  375.         arena.onTeamBasePointsUpdate += TeamBasePointsUpdate
  376.         arena.onTeamBaseCaptured += TeamBaseCaptured
  377.         arena.onVehicleKilled += VehicleKilled
  378.         arena.onPeriodChange += PeriodChange
  379.     return
  380.  
  381.  
  382. g_playerEvents.onAvatarReady += avatarReady
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement