NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

svc_modtest.py (13015B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\devtools\script\svc_modtest.py
      2 from __future__ import print_function
      3 import blue
      4 import dogma.data
      5 import evetypes
      6 from carbon.common.script.sys.service import Service
      7 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER
      8 from carbonui import uiconst
      9 from carbonui.primitives.container import Container
     10 from carbonui.button.group import ButtonGroup
     11 from carbonui.control.window import Window
     12 from eve.client.script.ui.control.entries.checkbox import CheckboxEntry
     13 from eve.client.script.ui.control.entries.util import GetFromClass
     14 from eve.client.script.ui.util import uix
     15 from eve.client.script.ui.control import eveLabel, eveScroll
     16 from eve.client.script.parklife import states as state
     17 from carbonui.uicore import uicore
     18 from eveexceptions import UserError
     19 SERVICENAME = 'modtest'
     20 Progress = lambda title, text, current, total: sm.GetService('loading').ProgressWnd(title, text, current, total)
     21 
     22 class ModTest(Service):
     23     __exportedcalls__ = {}
     24     __notifyevents__ = ['ProcessRestartUI']
     25     __dependencies__ = []
     26     __guid__ = 'svc.modtest'
     27     __servicename__ = SERVICENAME
     28     __displayname__ = SERVICENAME
     29 
     30     def Run(self, memStream = None):
     31         self.wnd = None
     32         self.ammo = None
     33 
     34     def InitGroups(self):
     35         if getattr(self, 'testgroups', None):
     36             return
     37         self.testgroups = {}
     38         t, a, p = self.GetModuleLists()
     39         t = t + a
     40         for x in t:
     41             gid = evetypes.GetGroupID(x[0])
     42             if gid not in (const.groupSiegeModule,
     43              const.groupSuperWeapon,
     44              const.groupJumpPortalGenerator,
     45              const.groupMiningLaser):
     46                 self.testgroups[gid] = True
     47             else:
     48                 self.testgroups[gid] = False
     49 
     50     def Stop(self, memStream = None):
     51         self.Hide()
     52         Service.Stop(self, memStream)
     53 
     54     def Show(self):
     55         if not self.wnd:
     56             self.wnd = wnd = Window.Open(windowID=SERVICENAME)
     57             wnd._OnClose = self.Hide
     58             wnd.SetCaption('Module Test')
     59             wnd.sr.main = wnd.GetChild('main')
     60             wnd.SetMinSize((352, 200))
     61             main = Container(name='main', parent=wnd.sr.main, pos=(const.defaultPadding,
     62              const.defaultPadding,
     63              const.defaultPadding,
     64              const.defaultPadding))
     65             eveLabel.Label(text='Select module groups to test', parent=main, align=uiconst.TOTOP, width=10, left=5, top=5, color=None, state=uiconst.UI_DISABLED)
     66             wnd.sr.scroll = eveScroll.Scroll(parent=main)
     67             buttons = [['Test',
     68               self.Test,
     69               None,
     70               81], ['Close',
     71               self.Hide,
     72               None,
     73               81]]
     74             wnd.sr.main.children.insert(0, ButtonGroup(btns=buttons))
     75             scrolllist = []
     76             self.InitGroups()
     77             for gid in self.testgroups:
     78                 groupName = evetypes.GetGroupNameByGroup(gid)
     79                 scrolllist.append(GetFromClass(CheckboxEntry, {'label': groupName,
     80                  'checked': self.testgroups[gid],
     81                  'cfgname': groupName.replace(' ', ''),
     82                  'retval': gid,
     83                  'OnChange': self.CheckBoxChange}))
     84 
     85             scrolllist.sort(lambda a, b: cmp(a.label, b.label))
     86             wnd.sr.scroll.Load(contentList=scrolllist)
     87 
     88     def CheckBoxChange(self, checkbox, node, *args):
     89         self.testgroups[node.retval] = checkbox.checked
     90 
     91     def Hide(self, *args):
     92         if self.wnd:
     93             self.wnd.Close()
     94             self.wnd = None
     95 
     96     def ProcessRestartUI(self):
     97         if self.wnd:
     98             self.Hide()
     99             self.Show()
    100 
    101     def GetModuleLists(self):
    102         test = {}
    103         groups = dict.fromkeys([ groupID for groupID in evetypes.GetGroupIDsByCategory(const.categoryModule) ])
    104         for parentID in evetypes.GetAllVariationParents():
    105             for typeID in evetypes.GetVariationChildren(parentID):
    106                 metaGroupID = evetypes.GetMetaGroupID(typeID)
    107                 if metaGroupID == 2:
    108                     if evetypes.Exists(typeID) and evetypes.GetMarketGroupID(typeID) and evetypes.GetCategoryID(typeID) == const.categoryModule:
    109                         test[evetypes.GetGroupID(typeID)] = typeID
    110 
    111         for typeID in evetypes.Iterate():
    112             groupID = evetypes.GetGroupID(typeID)
    113             if groupID not in test and groupID in groups:
    114                 if evetypes.GetVariationChildren(typeID) is None:
    115                     if evetypes.GetMarketGroupID(typeID):
    116                         test[groupID] = typeID
    117 
    118         targeted = []
    119         activated = []
    120         passive = []
    121         for typeID in test.values():
    122             effects = [ dogma.data.get_effect(row.effectID) for row in dogma.data.get_type_effects(typeID) ]
    123             effectCategories = [ eff.effectCategory for eff in effects if eff.effectName != 'online' ]
    124             if const.dgmEffTarget in effectCategories:
    125                 targeted.append((typeID, effects))
    126             elif const.dgmEffActivation in effectCategories:
    127                 activated.append((typeID, effects))
    128             else:
    129                 passive.append((typeID, effects))
    130 
    131         return (targeted, activated, passive)
    132 
    133     def GetAmmo(self):
    134         if getattr(self, 'ammo', None):
    135             return
    136         groups = {}
    137         for groupID in evetypes.GetGroupIDsByCategory(const.categoryCharge):
    138             groups[groupID] = True
    139 
    140         self.ammo = {}
    141         godma = sm.GetService('godma')
    142         for typeID in evetypes.GetTypeIDsByGroups(groups.keys()):
    143             groupID = evetypes.GetGroupID(typeID)
    144             if groupID in self.ammo:
    145                 self.ammo[groupID].append(godma.GetType(typeID))
    146             else:
    147                 self.ammo[groupID] = [godma.GetType(typeID)]
    148 
    149     def Test(self, *args):
    150         if session.stationid:
    151             return
    152         self.Hide()
    153 
    154         def _Click(module):
    155             module.Click()
    156             while module.sr.glow.state == uiconst.UI_HIDDEN:
    157                 blue.pyos.synchro.SleepWallclock(1)
    158 
    159             try:
    160                 module.Click()
    161             except:
    162                 pass
    163 
    164         def _Idle(module):
    165             return module.sr.glow.state == uiconst.UI_HIDDEN and module.sr.busy.state == uiconst.UI_HIDDEN and module.blinking == False and module.reloadingAmmo is False
    166 
    167         def _WaitForIdle(module, timeout = 60000, reason = None):
    168             if reason:
    169                 print('WaitForIdle: %s' % reason)
    170             blue.pyos.synchro.SleepWallclock(100)
    171             timeout -= 100
    172             while not _Idle(module) and timeout > 0:
    173                 blue.pyos.synchro.SleepWallclock(100)
    174                 timeout -= 100
    175 
    176         self.GetAmmo()
    177         t, a, p = self.GetModuleLists()
    178         ship = sm.GetService('godma').GetItem(session.shipid)
    179         if session.role & ROLE_PROGRAMMER:
    180             if ship.cpuOutput != 13371337:
    181                 w = sm.RemoteSvc('slash')
    182                 w.SlashCmd('/dogma me cpuOutput = 13371337')
    183                 w.SlashCmd('/dogma me powerOutput = 10000000')
    184                 w.SlashCmd('/dogma me hiSlots = 8')
    185                 w.SlashCmd('/dogma me medSlots = 8')
    186                 w.SlashCmd('/dogma me lowSlots = 8')
    187                 w.SlashCmd('/dogma me rigSlots = 8')
    188                 w.SlashCmd('/dogma me upgradeCapacity = 10000')
    189                 w.SlashCmd('/dogma me turretSlotsLeft = 8')
    190                 w.SlashCmd('/dogma me launcherSlotsLeft = 8')
    191                 w.SlashCmd('/dogma me upgradeSlotsLeft = 8')
    192                 w.SlashCmd('/dogma me capacity = 1000000')
    193                 w.SlashCmd('/dogma me capacitorCapacity = 1000000')
    194         errors = []
    195         t = filter(lambda x: self.testgroups[x[0].groupID], t + a)
    196         total = len(t)
    197         current = 0
    198         while t:
    199             sm.RemoteSvc('slash').SlashCmd('/unload me all')
    200             slotsLeft = {'hiPower': [ x + const.flagHiSlot0 for x in range(int(ship.hiSlots)) ],
    201              'medPower': [ x + const.flagMedSlot0 for x in range(int(ship.medSlots)) ],
    202              'loPower': [ x + const.flagLoSlot0 for x in range(int(ship.lowSlots)) ],
    203              'rigSlot': [ x + const.flagRigSlot0 for x in range(int(ship.rigSlots)) ]}
    204             for item in t[:]:
    205                 typeID, effects = item
    206                 Progress('Module Test', 'Fitting %d/%d: %s' % (current, total, evetypes.GetName(typeID)), current, total)
    207                 current += 1
    208                 try:
    209                     slotType = [ eff.effectName for eff in effects if eff.effectName.endswith('Power') or eff.effectName == 'rigSlot' ][0]
    210                     if slotsLeft[slotType]:
    211                         sm.RemoteSvc('slash').SlashCmd('/fit me %s' % typeID)
    212                         t.remove(item)
    213                         flag = slotsLeft[slotType].pop(0)
    214                         module = []
    215                         while not module:
    216                             blue.pyos.synchro.SleepSim(500)
    217                             module = [ x for x in sm.GetService('godma').GetItem(session.shipid).modules if x.flagID == flag ]
    218 
    219                         if not session.stationid:
    220                             sm.RemoteSvc('slash').SlashCmd('/heal me capac=1')
    221                         if slotsLeft.values() == [[],
    222                          [],
    223                          [],
    224                          []]:
    225                             break
    226                 except UserError as e:
    227                     errors.append((typeID, str(e)))
    228 
    229             Progress('Module Test', 'Testing, hold on...', current, total)
    230             for itemID in sm.GetService('target').GetTargets():
    231                 slimItem = uix.GetBallparkRecord(itemID)
    232                 if slimItem.typeID == 12403:
    233                     break
    234             else:
    235                 itemID = sm.RemoteSvc('slash').SlashCmd('/spawn 12403 victim')
    236                 sm.GetService('target').ClearTargets()
    237                 sm.GetService('target').LockTarget(itemID)
    238                 slimItem = uix.GetBallparkRecord(itemID)
    239 
    240             if slimItem:
    241                 sm.GetService('stateSvc').SetState(slimItem.itemID, state.selected, 1)
    242                 sm.GetService('stateSvc').SetState(slimItem.itemID, state.activeTarget, 1)
    243             if not uicore.layer.shipui:
    244                 return
    245             for module in uicore.layer.shipui.slotsContainer.modulesByID.itervalues():
    246                 module.SetRepeat(1000)
    247                 attr = sm.GetService('godma').GetType(module.moduleinfo.typeID)
    248                 groups = []
    249                 for x in range(1, 4):
    250                     if attr.AttributeExists('chargeGroup%d' % x):
    251                         groups.append(getattr(attr, 'chargeGroup%d' % x))
    252 
    253                 if groups:
    254                     module.SetAutoReload(0)
    255                     for gid in groups:
    256                         for ammo in self.ammo[gid]:
    257                             if ammo.chargeSize == attr.chargeSize and evetypes.GetMarketGroupID(ammo.typeID):
    258                                 print('%s <- %s' % (evetypes.GetName(attr.typeID), evetypes.GetName(ammo.typeID)))
    259                                 sm.RemoteSvc('slash').SlashCmd('/create %d' % ammo.typeID)
    260                                 try:
    261                                     sm.GetService('clientDogmaIM').GetDogmaLocation().LoadAmmoTypeToModule(module.id, ammo.typeID)
    262                                     _WaitForIdle(module, 2000, reason='pre-activate')
    263                                     if attr.chargeSize == 4:
    264                                         blue.pyos.synchro.SleepSim(5000)
    265                                     else:
    266                                         blue.pyos.synchro.SleepSim(1000)
    267                                     _Click(module)
    268                                     _WaitForIdle(module, reason='post-activate')
    269                                 except UserError as e:
    270                                     errors.append((module.moduleinfo.typeID, str(e)))
    271 
    272                                 sm.RemoteSvc('slash').SlashCmd('/unload me %d' % ammo.typeID)
    273                                 break
    274 
    275                         break
    276 
    277                 else:
    278                     try:
    279                         _Click(module)
    280                     except UserError as e:
    281                         errors.append((module.moduleinfo.typeID, str(e)))
    282 
    283             busy = True
    284             timeout = 30000
    285             while busy and timeout > 0:
    286                 blue.pyos.synchro.SleepSim(250)
    287                 timeout -= 250
    288                 for module in uicore.layer.shipui.slotsContainer.modulesByID.itervalues():
    289                     if not _Idle(module):
    290                         break
    291                 else:
    292                     busy = False
    293 
    294         Progress('Module Test', 'Done!', 3, 4)
    295         blue.pyos.synchro.Sleep(2000)
    296         Progress('Module Test', 'Done!', 4, 4)
    297         for typeID, errormsg in errors:
    298             self.LogError('%d: %s' % (typeID, errormsg))