SegFault

在2016年5月6日 (星期五)加入
删除308字节 、​ 2016年10月5日 (星期三)
无编辑摘要
无编辑摘要
无编辑摘要
第1行: 第1行:
<pre><nowiki>
<pre>
from urllib.request import urlopen
from urllib.request import urlopen
import json
import json
第6行: 第6行:


specialShipNames = [ '重庆', '奥希金斯', '信赖', '萝德尼' ]
specialShipNames = [ '重庆', '奥希金斯', '信赖', '萝德尼' ]
specialCountries = { '戈本':'土耳其', '德·鲁伊特':'荷兰', '苏赫巴托尔':'蒙古', '奥希金斯':'智利', '吸血鬼':'英国', '海达人':'加拿大', '奥丁':'冰岛' }


countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国', '???' ]
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国', '???' ]
第53行: 第52行:
     for i in range(n, ship['equipmentNum']):
     for i in range(n, ship['equipmentNum']):
         eq[i] = noEquipt
         eq[i] = noEquipt
    country = countryNames[int(ship['country'])]
    if ship['title'] in specialCountries:
        country = specialCountries[ship['title']]


     ret = "ships['%s'] = {\n    " % getShipName(ship)
     ret = "ships['%s'] = {\n    " % getShipName(ship)
第64行: 第59行:


     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']


第137行: 第133行:
def getDialogue(ship):
def getDialogue(ship):
     name = getShipName(ship)
     name = getShipName(ship)
     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行: 第173行:
     return ret + ' }'
     return ret + ' }'


def printShips(data):
def parse(data):
     ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 ]
     f = open('数据.txt', '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))
        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行: 第205行:
     return json.loads(j)
     return json.loads(j)


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