舰R百科是靠无数自愿编辑者持续地建设更新完善的。编辑非常简单,请勇于更新页面!
编辑入门 | 资助百科 | 留言讨论页 | 微博@舰R百科 | 百科编辑讨论Q群:366818861

用户:SegFault:修订间差异

来自舰R百科
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
<pre><nowiki>
<pre>
from urllib.request import urlopen
from urllib.request import urlopen
import json
import json
第5行: 第5行:
url = 'http://login.jianniang.com/index/getInitConfigs'
url = 'http://login.jianniang.com/index/getInitConfigs'


specialShipNames = [ '重庆', '奥希金斯', '信赖', '萝德尼' ]
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国' ]
specialCountries = { '戈本':'土耳其', '德·鲁伊特':'荷兰', '苏赫巴托尔':'蒙古', '奥希金斯':'智利', '吸血鬼':'英国', '海达人':'加拿大', '奥丁':'冰岛' }
shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', '航空战列舰', '战列巡洋舰', '重巡洋舰', \
 
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国', '???' ]
shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', 'BBV', '战列巡洋舰', '航空战列舰', \
         'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ]
         'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ]
rangeNames = [ '', '短', '中', '长', '超长' ]
rangeNames = [ '', '短', '中', '长', '超长' ]
第15行: 第12行:


remodelPostfix = '·改'
remodelPostfix = '·改'
specialPostfix = '(特殊)'
canNotEquip = '不可装备'
canNotEquip = '不可装备'
noEquipt = '无'
noEquipt = '无'
第28行: 第24行:
desc = '简介'
desc = '简介'


def getShipName(ship):
def getShipName(ship, allShips):
     name = ship['title'].strip()
     name = ship['title'].strip()
     idx = int(ship['shipIndex'])
     idx = int(ship['shipIndex'])
     if idx < 1000 or name in specialShipNames:
     if idx < 1000:
         return name
         return name
     elif idx < 2000:
 
         return name + remodelPostfix
     orig = [ s for s in allShips if int(s['shipIndex']) == idx % 1000 ][0]
     else:
    if name == orig['title'].strip():
        return name + specialPostfix
         name += remodelPostfix
     return name


def getShipAttr(ship, allShips, equipts):
def getShipAttr(ship, allShips, equipts):
第54行: 第51行:
         eq[i] = noEquipt
         eq[i] = noEquipt


    country = countryNames[int(ship['country'])]
     ret = "ships['%s'] = {\n    " % getShipName(ship, allShips)
    if ship['title'] in specialCountries:
        country = specialCountries[ship['title']]
 
     ret = "ships['%s'] = {\n    " % getShipName(ship)


     ret += "index=%s, " % int(ship['shipIndex'])
     ret += "index=%s, " % int(ship['shipIndex'])
第64行: 第57行:


     ret += "type='%s', " % shipTypeNames[ship['type']]
     ret += "type='%s', " % shipTypeNames[ship['type']]
     ret += "country='%s', " % country
     if int(ship['country']) < 9:
        ret += "country='%s', " % countryNames[int(ship['country'])]
     ret += "class='%s', " % ship['classNo']
     ret += "class='%s', " % ship['classNo']


第124行: 第118行:


         ret = ret[:-1] + '\n    '
         ret = ret[:-1] + '\n    '
         ret += "mod='%s', " % getShipName(t[0])
         ret += "mod='%s', " % getShipName(t[0], allShips)
         ret += "modLv=%s, " % ship['evoLevel']
         ret += "modLv=%s, " % ship['evoLevel']
         ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']]
         ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']]
第135行: 第129行:
     return ret[:-2] + '\n}\n'
     return ret[:-2] + '\n}\n'


def getDialogue(ship):
def getDialogue(ship, allShips):
     name = getShipName(ship)
     name = getShipName(ship, allShips)
     ret = "text['" + name + "'] = { }\n"
     ret = "ships['" + name + "']['" + aquire + "'] = '" + ship['getDialogue'].strip() + "'\n"
    ret += "text['" + name + "']['" + aquire + "'] = '" + ship['getDialogue'].strip() + "'\n"
     if ship['mainDialogue'] and ship['mainDialogue'][0]:
     if ship['mainDialogue'] and ship['mainDialogue'][0]:
         ret += "text['" + name + "']['" + day + "1'] = '" + ship['mainDialogue'][0].strip() + "'\n"
         ret += "ships['" + name + "']['" + day + "1'] = '" + ship['mainDialogue'][0].strip() + "'\n"
         ret += "text['" + name + "']['" + day + "2'] = '" + ship['mainDialogue'][1].strip() + "'\n"
         ret += "ships['" + name + "']['" + day + "2'] = '" + ship['mainDialogue'][1].strip() + "'\n"
         ret += "text['" + name + "']['" + day + "3'] = '" + ship['mainDialogue'][2].strip() + "'\n"
         ret += "ships['" + name + "']['" + day + "3'] = '" + ship['mainDialogue'][2].strip() + "'\n"
     if ship['mainDialogue'] and ship['mainDialogue'][6]:
     if ship['mainDialogue'] and ship['mainDialogue'][6] != ship['mainDialogue'][0]:
         ret += "text['" + name + "']['" + night + "1'] = '" + ship['mainDialogue'][6].strip() + "'\n"
         ret += "ships['" + name + "']['" + night + "1'] = '" + ship['mainDialogue'][6].strip() + "'\n"
         ret += "text['" + name + "']['" + night + "2'] = '" + ship['mainDialogue'][7].strip() + "'\n"
         ret += "ships['" + name + "']['" + night + "2'] = '" + ship['mainDialogue'][7].strip() + "'\n"
         ret += "text['" + name + "']['" + night + "3'] = '" + ship['mainDialogue'][8].strip() + "'\n"
         ret += "ships['" + name + "']['" + night + "3'] = '" + ship['mainDialogue'][8].strip() + "'\n"
     if ship['formationDialogue']:
     if ship['formationDialogue']:
         ret += "text['" + name + "']['" + formation + "'] = '" + ship['formationDialogue'].strip() + "'\n"
         ret += "ships['" + name + "']['" + formation + "'] = '" + ship['formationDialogue'].strip() + "'\n"
     if ship['atkDialogue']:
     if ship['atkDialogue']:
         ret += "text['" + name + "']['" + attack + "'] = '" + ship['atkDialogue'].strip() + "'\n"
         ret += "ships['" + name + "']['" + attack + "'] = '" + ship['atkDialogue'].strip() + "'\n"
     if ship['nightAtkDialogue']:
     if ship['nightAtkDialogue']:
         ret += "text['" + name + "']['" + nightAttack + "'] = '" + ship['nightAtkDialogue'].strip() + "'\n"
         ret += "ships['" + name + "']['" + nightAttack + "'] = '" + ship['nightAtkDialogue'].strip() + "'\n"
     if ship['breakDialogue']:
     if ship['breakDialogue']:
         ret += "text['" + name + "']['" + damaged + "'] = '" + ship['breakDialogue'].strip() + "'\n"
         ret += "ships['" + name + "']['" + damaged + "'] = '" + ship['breakDialogue'].strip() + "'\n"
     ret += "text['" + name + "']['" + vow + "'] = '" + ship['vow'].strip() + "'\n"
     ret += "ships['" + name + "']['" + vow + "'] = '" + ship['vow'].strip() + "'\n"
     ret += "text['" + name + "']['" + desc + "'] = '" + ship['desc'].strip() + "'\n"
     ret += "ships['" + name + "']['" + desc + "'] = '" + ship['desc'].strip() + "'\n"


     return ret + '\n'
     return ret + '\n'
第178行: 第171行:
     return ret + ' }'
     return ret + ' }'


def printShips(data):
def parse(data):
     ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 ]
     f = open('data.lua', 'w')
    f.write('local equipts = { }\nlocal ships = { }\n\n')


     f = open('台词.txt', 'w')
     # equipment attributes
     f.write('text = { }\n\n')
     f.write('-' * 100 + '\n\n')
     for s in ships:
     for equipt in data['shipEquipmnt']:
         f.write(getDialogue(s))
        #if equipt['picId'] == 998: continue
    f.write('return text')
        if equipt['title'] == '喵' or equipt['title'] == '': continue
    f.close()
         f.write(getEquiptAttr(equipt))
        f.write('\n')


    # ship attributes
    f.write('\n' + '-' * 100 + '\n\n')
     ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 and int(s['shipIndex']) < 2000 ]
     ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 and int(s['shipIndex']) < 2000 ]
    f = open('属性.txt', 'w')
    f.write('ships = { }\n\n')
     for s in ships:
     for s in ships:
         f.write(getShipAttr(s, ships, data['shipEquipmnt']))
         f.write(getShipAttr(s, ships, data['shipEquipmnt']))
         f.write('\n')
         f.write('\n')
    f.write('return ships')
    f.close()


     f = open('装备.txt', 'w')
     # dialogue
     f.write('equipts = { }\n\n')
     f.write('-' * 100 + '\n\n')
     for equipt in data['shipEquipmnt']:
     for s in ships:
        if equipt['picId'] == 998: continue
         f.write(getDialogue(s, ships))
        if equipt['title'] == '喵' or equipt['title'] == '': continue
 
         f.write(getEquiptAttr(equipt))
    f.write('-' * 100 + '\n\n')
        f.write('\n')
     f.write('return { equipts=equipts, ships=ships }')
     f.write('\nreturn equipts')
     f.close()
     f.close()


第212行: 第203行:
     return json.loads(j)
     return json.loads(j)


def run():
if __name__ == '__main__':
     data = download()
     data = download()
     printShips(data)
     parse(data)
</nowiki></pre>
</pre>

2016年10月17日 (一) 18:54的最新版本

from urllib.request import urlopen
import json

url = 'http://login.jianniang.com/index/getInitConfigs'

countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国' ]
shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', '航空战列舰', '战列巡洋舰', '重巡洋舰', \
        'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ]
rangeNames = [ '', '短', '中', '长', '超长' ]
coreNames = { 10441:'驱逐', 10341:'巡洋', 10241:'战列', 10141:'航母', 10541:'潜艇' }

remodelPostfix = '·改'
canNotEquip = '不可装备'
noEquipt = '无'
aquire = '获得'
day = '白天'
night = '夜间'
formation = '阵型'
attack = '攻击'
nightAttack = '夜战'
damaged = '中破'
vow = '誓约'
desc = '简介'

def getShipName(ship, allShips):
    name = ship['title'].strip()
    idx = int(ship['shipIndex'])
    if idx < 1000:
        return name

    orig = [ s for s in allShips if int(s['shipIndex']) == idx % 1000 ][0]
    if name == orig['title'].strip():
        name += remodelPostfix
    return name

def getShipAttr(ship, allShips, equipts):
    st = ship['strengthenTop']
    exp = ship['strengthenLevelUpExp']

    cap = [ 0 ] * 4
    if ship['capacityInit']:
        for i in range(len(ship['capacityInit'])):
            cap[i] = ship['capacityInit'][i]

    eq = [ canNotEquip ] * 4
    n = len(ship['equipment'])
    for i in range(n):
        eq[i] = [ e['title'] for e in equipts if e['cid'] == ship['equipment'][i] ][0]
    for i in range(n, ship['equipmentNum']):
        eq[i] = noEquipt

    ret = "ships['%s'] = {\n    " % getShipName(ship, allShips)

    ret += "index=%s, " % int(ship['shipIndex'])
    ret += "rarity=%s, " % ship['star']

    ret += "type='%s', " % shipTypeNames[ship['type']]
    if int(ship['country']) < 9:
        ret += "country='%s', " % countryNames[int(ship['country'])]
    ret += "class='%s', " % ship['classNo']

    ret = ret[:-1] + '\n    '

    ret += "hp=%s, " % ship['hp']
    ret += "atk=%s, " % ship['atk']
    ret += "tpd=%s, " % ship['torpedo']
    ret += "def=%s, " % ship['def']
    ret += "aa=%s, " % ship['airDef']
    ret += "eva=%s, " % ship['miss']
    ret += "as=%s, " % ship['antisub']
    ret += "rec=%s, " % ship['radar']
    ret += "speed=%s, " % ship['speed']
    ret += "luck=%s, " % ship['luck']
    ret += "range='%s', " % rangeNames[ship['range']]

    ret = ret[:-1] + '\n    '

    ret += "atkMax=%s, " % (int(ship['atk']) + st['atk'] // exp)
    ret += "tpdMax=%s, " % (int(ship['torpedo']) + st['torpedo'] // exp)
    ret += "defMax=%s, " % (ship['def'] + st['def'] // exp)
    ret += "aaMax=%s, " % (int(ship['airDef']) + st['air_def'] // exp)
    ret += "evaMax=%s, " % ship['missMax']
    ret += "asMax=%s, " % ship['antisubMax']
    ret += "recMax=%s, " % ship['radarMax']

    ret = ret[:-1] + '\n    '

    ret += "cap1=%s, " % cap[0]
    ret += "cap2=%s, " % cap[1]
    ret += "cap3=%s, " % cap[2]
    ret += "cap4=%s, " % cap[3]
    ret += "eq1='%s', " % eq[0]
    ret += "eq2='%s', " % eq[1]
    ret += "eq3='%s', " % eq[2]
    ret += "eq4='%s', " % eq[3]

    ret = ret[:-1] + '\n    '

    ret += "sFuel=%s, " % ship['maxOil']
    ret += "sAmmo=%s, " % ship['maxAmmo']
    ret += "rFuel=%s, " % ship['repairOilModulus']
    ret += "rSteel=%s, " % ship['repairSteelModulus']
    ret += "sAtk=%s, " % ship['strengthenSupplyExp']['atk']
    ret += "sTpd=%s, " % ship['strengthenSupplyExp']['torpedo']
    ret += "sDef=%s, " % ship['strengthenSupplyExp']['def']
    ret += "sAa=%s, " % ship['strengthenSupplyExp']['air_def']
    ret += "dFuel=%s, " % ship['dismantle']['2']
    ret += "dAmmo=%s, " % ship['dismantle']['3']
    ret += "dSteel=%s, " % ship['dismantle']['4']
    ret += "dBaux=%s, " % ship['dismantle']['9']

    t = [ s for s in allShips if int(s['shipIndex']) - int(ship['shipIndex']) == 1000 ]
    if len(t) != 0:
        mod = { '2':0, '3':0, '4':0, '9':0 }
        for k,v in ship['evoNeedResource'].items():
            mod[k] = v

        ret = ret[:-1] + '\n    '
        ret += "mod='%s', " % getShipName(t[0], allShips)
        ret += "modLv=%s, " % ship['evoLevel']
        ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']]
        ret += "coreNum=%s, " % ship['evoNeedResource'][str(ship['evoNeedItemCid'])]
        ret += "mFuel=%s, " % mod['2']
        ret += "mAmmo=%s, " % mod['3']
        ret += "mSteel=%s, " % mod['4']
        ret += "mBaux=%s, " % mod['9']

    return ret[:-2] + '\n}\n'

def getDialogue(ship, allShips):
    name = getShipName(ship, allShips)
    ret = "ships['" + name + "']['" + aquire + "'] = '" + ship['getDialogue'].strip() + "'\n"
    if ship['mainDialogue'] and ship['mainDialogue'][0]:
        ret += "ships['" + name + "']['" + day + "1'] = '" + ship['mainDialogue'][0].strip() + "'\n"
        ret += "ships['" + name + "']['" + day + "2'] = '" + ship['mainDialogue'][1].strip() + "'\n"
        ret += "ships['" + name + "']['" + day + "3'] = '" + ship['mainDialogue'][2].strip() + "'\n"
    if ship['mainDialogue'] and ship['mainDialogue'][6] != ship['mainDialogue'][0]:
        ret += "ships['" + name + "']['" + night + "1'] = '" + ship['mainDialogue'][6].strip() + "'\n"
        ret += "ships['" + name + "']['" + night + "2'] = '" + ship['mainDialogue'][7].strip() + "'\n"
        ret += "ships['" + name + "']['" + night + "3'] = '" + ship['mainDialogue'][8].strip() + "'\n"
    if ship['formationDialogue']:
        ret += "ships['" + name + "']['" + formation + "'] = '" + ship['formationDialogue'].strip() + "'\n"
    if ship['atkDialogue']:
        ret += "ships['" + name + "']['" + attack + "'] = '" + ship['atkDialogue'].strip() + "'\n"
    if ship['nightAtkDialogue']:
        ret += "ships['" + name + "']['" + nightAttack + "'] = '" + ship['nightAtkDialogue'].strip() + "'\n"
    if ship['breakDialogue']:
        ret += "ships['" + name + "']['" + damaged + "'] = '" + ship['breakDialogue'].strip() + "'\n"
    ret += "ships['" + name + "']['" + vow + "'] = '" + ship['vow'].strip() + "'\n"
    ret += "ships['" + name + "']['" + desc + "'] = '" + ship['desc'].strip() + "'\n"

    return ret + '\n'

def getEquiptAttr(e):
    ret = "equipts['%s'] = { " % e['title']
    ret += 'index=%s, rarity=%s' % (int(e['equipIndex']), e['star'])
    if int(e['atk']) != 0:          ret += ', atk=%s'   % e['atk']
    if int(e['def']) != 0:          ret += ', def=%s'   % e['def']
    if int(e['torpedo']) != 0:      ret += ', tpd=%s'   % e['torpedo']
    if int(e['antisub']) != 0:      ret += ', as=%s'    % e['antisub']
    if int(e['radar']) != 0:        ret += ', rec=%s'   % e['radar']
    if int(e['hit']) != 0:          ret += ', acc=%s'   % e['hit']
    if int(e['range']) != 0:        ret += ', range=%s' % e['range']
    if int(e['miss']) != 0:         ret += ', eva=%s'   % e['miss']
    if int(e['luck']) != 0:         ret += ', luck=%s'  % e['luck']
    if int(e['aircraftAtk']) != 0:  ret += ', bomb=%s'  % e['aircraftAtk']
    if int(e['airDef']) != 0:       ret += ', aa=%s'    % e['airDef']
    if float(e['airDefCorrect']) != 0: ret += ', aac=%d'   % (float(e['airDefCorrect']) * 100)
    if int(e['aluminiumUse']) != 0: ret += ', baux=%s'  % e['aluminiumUse']
    return ret + ' }'

def parse(data):
    f = open('data.lua', 'w')
    f.write('local equipts = { }\nlocal ships = { }\n\n')

    # equipment attributes
    f.write('-' * 100 + '\n\n')
    for equipt in data['shipEquipmnt']:
        #if equipt['picId'] == 998: continue
        if equipt['title'] == '喵' or equipt['title'] == '': continue
        f.write(getEquiptAttr(equipt))
        f.write('\n')

    # ship attributes
    f.write('\n' + '-' * 100 + '\n\n')
    ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 and int(s['shipIndex']) < 2000 ]
    for s in ships:
        f.write(getShipAttr(s, ships, data['shipEquipmnt']))
        f.write('\n')

    # dialogue
    f.write('-' * 100 + '\n\n')
    for s in ships:
        f.write(getDialogue(s, ships))

    f.write('-' * 100 + '\n\n')
    f.write('return { equipts=equipts, ships=ships }')
    f.close()

def download():
    j = urlopen(url).read().decode('utf-8')
    return json.loads(j)

if __name__ == '__main__':
    data = download()
    parse(data)