__init__.py 9.38 KB
Newer Older
Roman Astafev's avatar
Roman Astafev committed
1
""" XVM (c) https://modxvm.com 2013-2021 """
sirmax2's avatar
sirmax2 committed
2
3

#####################################################################
sirmax2's avatar
sirmax2 committed
4
# imports
sirmax2's avatar
sirmax2 committed
5
6

import traceback
7
import simplejson
sirmax2's avatar
sirmax2 committed
8

sirmax2's avatar
sirmax2 committed
9
import BigWorld
sirmax2's avatar
sirmax2 committed
10
from gui.shared import event_dispatcher
sirmax2's avatar
sirmax2 committed
11
from gui.Scaleform.daapi.view.battle_results_window import BattleResultsWindow
sirmax2's avatar
sirmax2 committed
12
from gui.Scaleform.daapi.view.bootcamp.BCBattleResult import BCBattleResult
Maxim Schedriviy's avatar
Maxim Schedriviy committed
13
from gui.Scaleform.genConsts.BATTLE_RESULTS_PREMIUM_STATES import BATTLE_RESULTS_PREMIUM_STATES
14
15
from gui.battle_results import composer
from gui.battle_results.components import base
Maxim Schedriviy's avatar
Maxim Schedriviy committed
16
from gui.battle_results.components.personal import DynamicPremiumState
17
from gui.battle_results.settings import BATTLE_RESULTS_RECORD
sirmax2's avatar
sirmax2 committed
18
from gui.shared.crits_mask_parser import critsParserGenerator
sirmax2's avatar
sirmax2 committed
19
20
from helpers import dependency
from skeletons.gui.shared import IItemsCache
sirmax2's avatar
sirmax2 committed
21

sirmax2's avatar
sirmax2 committed
22
from xfw import *
23
from xfw_actionscript.python import swf_loaded_info
sirmax2's avatar
sirmax2 committed
24

sirmax2's avatar
sirmax2 committed
25
26
from xvm_main.python.logger import *
import xvm_main.python.config as config
Yaroslav Brustinov's avatar
Yaroslav Brustinov committed
27

sirmax2's avatar
sirmax2 committed
28

Maxim Schedriviy's avatar
Maxim Schedriviy committed
29
30
# wait for loading xvm_battleresults_ui.swf
@overrideMethod(event_dispatcher, 'showBattleResultsWindow')
31
32
def event_dispatcher_showBattleResultsWindow_proxy(base, arenaUniqueID):
    event_dispatcher_showBattleResultsWindow(base, arenaUniqueID)
Maxim Schedriviy's avatar
Maxim Schedriviy committed
33

34
def event_dispatcher_showBattleResultsWindow(base, arenaUniqueID, cnt=0):
35
    if cnt < 5 and not swf_loaded_info.swf_loaded_get('xvm_lobby_ui.swf'):
36
        BigWorld.callback(0, lambda: event_dispatcher_showBattleResultsWindow(base, arenaUniqueID, cnt + 1))
Maxim Schedriviy's avatar
Maxim Schedriviy committed
37
    else:
38
        base(arenaUniqueID)
sirmax2's avatar
sirmax2 committed
39
40
41
42

@overrideMethod(BattleResultsWindow, 'as_setDataS')
def BattleResultsWindow_as_setDataS(base, self, data):
    try:
43
        linkage = data['tabInfo'][0]['linkage']
sirmax2's avatar
sirmax2 committed
44

45
46
47
        if linkage == 'EpicStatsUI' and not config.get('battleResults/showStandardFrontLineInterface', True):
            linkage = 'CommonStats'

sirmax2's avatar
sirmax2 committed
48
49
50
51
52
        if linkage == 'CommonStats':
            linkage = 'com.xvm.lobby.ui.battleresults::UI_CommonStats'

        if linkage == 'com.xvm.lobby.ui.battleresults::UI_CommonStats':
            data['tabInfo'][0]['linkage'] = linkage
53
54
55
56
            # Use data['common']['regionNameStr'] value to transfer XVM data.
            # Cannot add in data object because DAAPIDataClass is not dynamic.
            #log(data['xvm_data'])
            data['xvm_data']['regionNameStr'] = data['common']['regionNameStr']
Maxim Schedriviy's avatar
Maxim Schedriviy committed
57
            data['xvm_data']['arenaUniqueID'] = str(self._BattleResultsWindow__arenaUniqueID)
sirmax2's avatar
sirmax2 committed
58
            data['common']['regionNameStr'] = simplejson.dumps(data['xvm_data'], separators=(',',':'))
Maxim Schedriviy's avatar
Maxim Schedriviy committed
59

60
61
62
63
64
        del data['xvm_data']
    except Exception as ex:
        err(traceback.format_exc())
    return base(self, data)

sirmax2's avatar
sirmax2 committed
65
66
67
68
69
70
71
72
@overrideMethod(BCBattleResult, 'as_setDataS')
def BCBattleResult_as_setDataS(base, self, data):
    try:
        del data['xvm_data']
    except Exception as ex:
        err(traceback.format_exc())
    return base(self, data)

Maxim Schedriviy's avatar
Maxim Schedriviy committed
73
74
75
76
77
78
@overrideMethod(DynamicPremiumState, 'getVO')
def _DynamicPremiumState_getVO(base, self):
    res = base(self)
    if self._value in [BATTLE_RESULTS_PREMIUM_STATES.PREMIUM_ADVERTISING, BATTLE_RESULTS_PREMIUM_STATES.PREMIUM_INFO]:
        self._value = BATTLE_RESULTS_PREMIUM_STATES.PREMIUM_EARNINGS
        return super(DynamicPremiumState, self).getVO()
79
    #res = self._value = BATTLE_RESULTS_PREMIUM_STATES.PREMIUM_BONUS
Maxim Schedriviy's avatar
Maxim Schedriviy committed
80
    return res
81
82
83
84
85
86
87

#####################################################################
# collect data for XVM

class XvmDataBlock(base.StatsBlock):
    __slots__ = ('xvm_data')

sirmax2's avatar
sirmax2 committed
88
89
    itemsCache = dependency.descriptor(IItemsCache)

90
91
92
93
94
95
    def __init__(self, meta = None, field = '', *path):
        super(XvmDataBlock, self).__init__(meta, field, *path)
        self.xvm_data = []

    def getVO(self):
        return {
sirmax2's avatar
sirmax2 committed
96
            '__xvm': True, # XVM data marker
Roman Astafev's avatar
Roman Astafev committed
97
            'regionNameStr': '',
Maxim Schedriviy's avatar
Maxim Schedriviy committed
98
            'arenaUniqueID': 0,
99
100
101
            'data': self.xvm_data}

    def setRecord(self, result, reusable):
sirmax2's avatar
sirmax2 committed
102
        #log(result)
103
        xdata_total = {
sirmax2's avatar
sirmax2 committed
104
105
            'origXP': 0,
            'premXP': 0,
106
107
108
109
110
111
112
            'origCrewXP': 0,
            'premCrewXP': 0,
            'damageDealt': 0,
            'damageAssisted': 0,
            'damageAssistedCount': 0,
            'damageAssistedRadio': 0,
            'damageAssistedTrack': 0,
113
            'damageAssistedStun': 0,
114
115
116
117
118
119
            'damageBlockedByArmor': 0,
            'shots': 0,
            'hits': 0,
            'piercings': 0,
            'kills': 0,
            'spotted': 0,
120
121
            'stunNum': 0,
            'stunDuration': 0,
122
123
            'critsCount': 0,
            'ricochetsCount': 0,
124
            'nonPenetrationsCount': 0}
125
126

        for typeCompDescr, vData in reusable.personal.getVehicleCDsIterator(result):
127
128
            #log(vData)
            #log from 1.5.0.0: https://koreanrandom.com/forum/topic/49651-
Maxim Schedriviy's avatar
Maxim Schedriviy committed
129

130
            #TODO 1.5: add support for premiumPlus and premiumVip
sirmax2's avatar
sirmax2 committed
131
132
            origXP = vData['xp']
            premXP = vData['xp']
133
134
135
            origCrewXP = vData['tmenXP']
            premCrewXP = vData['tmenXP']
            if vData['isPremium']:
136
137
                origXP = vData['xp'] / (vData['premiumXPFactor100'] / 100.0)
                origCrewXP = vData['tmenXP'] / (vData['premiumXPFactor100'] / 100.0)
138
            else:
139
140
                premXP = vData['xp'] * (vData['premiumXPFactor100'] / 100.0)
                premCrewXP = vData['tmenXP'] * (vData['premiumXPFactor100'] / 100.0)
sirmax2's avatar
sirmax2 committed
141
            ownVehicle = self.itemsCache.items.getItemByCD(typeCompDescr)
142
143
144
145
146
            if ownVehicle and ownVehicle.isPremium:
                origCrewXP = int(origCrewXP * 1.5)
                premCrewXP = int(premCrewXP * 1.5)

            data = {
sirmax2's avatar
sirmax2 committed
147
148
                'origXP': origXP,
                'premXP': premXP,
149
150
151
152
153
154
155
                'origCrewXP': origCrewXP,
                'premCrewXP': premCrewXP,
                'damageDealt': vData['damageDealt'],
                'damageAssisted': vData['damageAssistedRadio'] + vData['damageAssistedTrack'],
                'damageAssistedCount': calcDetailsCount(vData['details'], ['damageAssistedRadio', 'damageAssistedTrack']),
                'damageAssistedRadio': vData['damageAssistedRadio'],
                'damageAssistedTrack': vData['damageAssistedTrack'],
156
                'damageAssistedStun': vData['damageAssistedStun'],
157
158
159
160
161
162
                'damageBlockedByArmor': vData['damageBlockedByArmor'],
                'shots': vData['shots'],
                'hits': vData['directHits'],
                'piercings': vData['piercings'],
                'kills': vData['kills'],
                'spotted': vData['spotted'],
163
164
                'stunNum': vData['stunNum'],
                'stunDuration': vData['stunDuration'],
sirmax2's avatar
sirmax2 committed
165
                'critsCount': calcCritsCount(vData['details']),
166
                'ricochetsCount': calcDetailsSum(vData['details'], 'rickochetsReceived'),
167
                'nonPenetrationsCount': vData['noDamageDirectHitsReceived']
sirmax2's avatar
sirmax2 committed
168
            }
169
170
171
172
173
174
            self.xvm_data.append(data)
            appendTotalData(xdata_total, data)

        self.xvm_data.insert(0, xdata_total)

def appendTotalData(total, data):
sirmax2's avatar
sirmax2 committed
175
176
    total['origXP'] += data['origXP']
    total['premXP'] += data['premXP']
177
178
179
180
181
182
183
    total['origCrewXP'] += data['origCrewXP']
    total['premCrewXP'] += data['premCrewXP']
    total['damageDealt'] += data['damageDealt']
    total['damageAssisted'] += data['damageAssisted']
    total['damageAssistedCount'] += data['damageAssistedCount']
    total['damageAssistedRadio'] += data['damageAssistedRadio']
    total['damageAssistedTrack'] += data['damageAssistedTrack']
184
    total['damageAssistedStun'] += data['damageAssistedStun']
185
186
187
188
189
190
    total['damageBlockedByArmor'] += data['damageBlockedByArmor']
    total['shots'] += data['shots']
    total['hits'] += data['hits']
    total['piercings'] += data['piercings']
    total['kills'] += data['kills']
    total['spotted'] += data['spotted']
191
192
    total['stunNum'] += data['stunNum']
    total['stunDuration'] += data['stunDuration']
193
194
195
    total['critsCount'] += data['critsCount']
    total['ricochetsCount'] += data['ricochetsCount']
    total['nonPenetrationsCount'] += data['nonPenetrationsCount']
196

197
_XVM_DATA_STATS_BLOCK = XvmDataBlock(base.DictMeta(), 'xvm_data', BATTLE_RESULTS_RECORD.PERSONAL)
198
199
200
201
202
203
204
205
206

@overrideMethod(composer.StatsComposer, '__init__')
def _StatsComposer__init__(base, self, *args):
    try:
        base(self, *args)
        self._block._meta._meta.update({'xvm_data':{}})
        self._block._meta._unregistered.add('xvm_data')
        self._block.addNextComponent(_XVM_DATA_STATS_BLOCK.clone())
    except:
sirmax2's avatar
sirmax2 committed
207
        err(traceback.format_exc())
sirmax2's avatar
sirmax2 committed
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#####################################################################
# utility

def calcDetailsSum(details, field):
    try:
        n = 0
        for detail in details.values():
            if field in detail:
                n += int(detail[field])
        return n
    except Exception as ex:
        err(traceback.format_exc())
        return 0

def calcDetailsCount(details, fields):
    try:
        n = 0
        for detail in details.values():
            for field in fields:
sirmax2's avatar
sirmax2 committed
228
                if detail.get(field, 0) > 0:
229
230
231
232
233
234
                    n += 1
                    break;
        return n
    except Exception as ex:
        err(traceback.format_exc())
        return 0
sirmax2's avatar
sirmax2 committed
235
236
237
238
239
240
241
242
243
244
245
246
247

def calcCritsCount(details):
    try:
        n = 0
        for detail in details.values():
            value = detail.get('crits', 0)
            if value > 0:
                for subType, critType in critsParserGenerator(value):
                    n += 1
        return n
    except Exception as ex:
        err(traceback.format_exc())
        return 0