Beispiel #1
0
    def __init__(self, local_id, sortno, lv, nowhp, maxhp, cond, karyoku, raisou, taiku, soukou, kaihi, taisen, sakuteki, lucky):
        self.local_id  = local_id
        self.sortno    = sortno
        self.lv        = lv
        self.nowhp     = nowhp
        self.maxhp     = maxhp
        self.cond      = cond
        self.karyoku   = karyoku
        self.raisou    = raisou
        self.taiku     = taiku
        self.soukou    = soukou
        self.kaihi     = kaihi
        self.taisen    = taisen
        self.sakuteki  = sakuteki
        self.lucky     = lucky
        # 上方為 port API 可抓出的資訊

        self.dmghp     = self.maxhp - self.nowhp
        self.name      = kcShipData.get_name_by_sortno(self.sortno)
        self.nick_name = kcShipData.get_adana_by_name(self.name)
        self.stype     = kcShipData.get_stype_by_sortno(self.sortno)

        if self.name is None:
            u.uerror("Missing name, local_id:{0:>4d}, lv:{1:>3d}".format(self.local_id, self.lv))
        if self.stype is None:
            u.uerror("Missing stype, local_id:{0:>4d}, lv:{1:>3d}".format(self.local_id, self.lv))
Beispiel #2
0
    def get_damaged_ships_and_repair_time(self):
        damaged_ships = list()
        for ship in self.ships:
            if ship is None: break
            # print ship.name, ship.nowhp, ship.maxhp
            if not ship.nowhp == ship.maxhp:
                if ship.stype is None:
                    u.uerror(
                        "Missing stype, local_id:{0:>4d}, lv = {1:>3d}".format(
                            ship.local_id, player.ship.lv))
                    continue
                repair_time = self._get_repair_time(ship)
                # 幫大破小破上色
                tmp = self._get_hp_and_next_ha(ship.nowhp, ship.maxhp)
                hp = tmp[0]
                next_ha = tmp[1]

                damaged_ships.append(
                    (repair_time, hp, ship.lv, ship.name, next_ha))

        damaged_ships.sort(reverse=True)
        for value in damaged_ships:
            msg = self._format_damaged_ships_and_repair_time(value)
            u.uprint(msg)
        u.uprint('怪我している艦娘は {} 人います'.format(
            u.append_color(len(damaged_ships), 'cyan')))
Beispiel #3
0
    def print_info_decks(self, deck_id=5):
        if self.decks[0] is None:
            u.uerror("[Player][print_info_decks] Not initialized")
            return
        # 印出所有的艦隊狀態
        if deck_id == 5:
            start_pos = 0
            end_pos = 4
        # 印出某個指定的艦隊狀態
        elif deck_id > 0 and deck_id < 5 and (self.decks[deck_id - 1]
                                              is not None):
            start_pos = deck_id - 1
            end_pos = deck_id
        else:
            u.uerror("[Player][print_info_decks] Invalid deck_id")
            return
            # self.decks[deck_id-1].print_info()

        for i in range(start_pos, end_pos):
            if self.decks[i] is None: continue
            # self.decks[i].print_info()
            result = self.decks[i].get_info()
            fleet_name = result['name'].encode('utf-8')
            print(u.append_color(fleet_name, 'cyan'))
            msg = ''
            for local_id in result['ships']:
                if local_id == -1: continue
                for ship in self.ships:
                    if ship is None: break
                    if ship.local_id == local_id:
                        cond = ship.cond
                        if cond < 20:
                            cond = u.append_color(cond, 'red')
                        elif cond < 30:
                            cond = u.append_color(cond, 'orange')
                        elif cond >= 50:
                            cond = u.append_color(cond, 'yellow')

                        # 如果是印出全部艦隊的話,印簡易的資訊就好
                        if deck_id == 5:
                            msg += u.append_color(
                                ship.name, 'yellow') + '(' + str(cond) + '), '
                        # 如果是印出特定艦隊的話,印詳細的資訊
                        else:
                            tmp = self._get_hp_and_next_ha(
                                ship.nowhp, ship.maxhp)
                            repair_time = self._get_repair_time(ship)
                            value = (repair_time, tmp[0], ship.lv, ship.name,
                                     tmp[1])

                            msg += '(' + str(cond) + ') '
                            msg += self._format_damaged_ships_and_repair_time(
                                value)
                            msg += '\n'
            print(msg[:-1])
            print("任務" + str(result['mission']))
def _is_same_as_last_fetch(json_data):
    global last_hash
    md5 = hashlib.md5()
    md5.update(str(json_data))
    this_hash = md5.digest()
    if last_hash == this_hash:
        u.uerror("Didn't update Json due two same hash value")
        return True
    last_hash = this_hash
    return False
def update_gear_data_by_local_id(local_id, ship_name, ship_lv):
    unknown_sortno = 0
    sortno = local_id_to_sortno.get(local_id, None)
    if sortno is None:
        unknown_sortno += 1
        if unknown_sortno > 50:
            u.uerror('unknown_sortno > 50, please update item_slot.')
        return
    gear = gear_data[sortno]
    ship_name_and_lv = ship_name + "(" + str(ship_lv) + ")"
    if ship_name_and_lv not in gear.who_has:
        gear.who_has.append(ship_name_and_lv)
Beispiel #6
0
 def print_info_ships(self, ship_in_list=1):
     if self.ships[0] is None:
         u.uerror("[Player][print_info_ships] Not initialized")
         return
     # 印出某個指定的船狀態,以在 list 的順序印出來,
     if ship_in_list > 0 and ship_in_list <= 100:
         if self.ships[ship_in_list - 1] is not None:
             self.ships[ship_in_list - 1].print_info()
         else:
             return
     else:
         u.uerror("[Player][print_info_ships] Invalid ship_in_list")
def fetch_api_response(player, filter_, retry=1):
    # 清空 clipboard
    u.pbcopy("NA")

    # 設定 filter
    _set_chrome_dev_filter(filter_)
    # 複製 response
    _copy_api_response_from_chrome_dev()

    dataFromClipboard = u.pbpaste()

    try:
        json_data = json.loads(dataFromClipboard[7:])
    except:
        # traceback.print_exc()
        u.uerror("Failed to fecth Kancolle API")
        # u.uerror("Data: {0}".format(dataFromClipboard))
        # 當抓取失敗時,最多重複 n = retry 次
        if retry == 0:
            return 'Reached_retry_limit'
        retry = retry - 1
        u.uprint('Retrying...')
        u._sleep(u.get_lag())
        fetch_api_response(player, filter_, retry)
        return 'fail_to_fetch'

    # 與上個 JSON 是否擁有相同的 hash,有的話就更新
    if _is_same_as_last_fetch(json_data) is True:
        return 'same_as_last'

    try:
        if filter_ == 'questlist':
            global gl_total_quest_page
            gl_total_quest_page = _parse_questlist(json_data)
            print "gl_total_quest_page = ", gl_total_quest_page
        elif filter_ == 'port':
            _parse_port(player, json_data)
    except:
        # traceback.print_exc()
        u.uerror("Failed to parse Kancolle API (新しい艦娘がアップデートしましたか?)")
        # u.uerror("Data: {0}".format(dataFromClipboard))
        # 當抓取失敗時,最多重複 n = retry 次
        if retry == 0:
            return 'Reached_retry_limit'
        retry = retry - 1
        u.uprint('Retrying...')
        u._sleep(u.get_lag())
        fetch_api_response(player, filter_, retry)
        return 'fail_to_parse'
Beispiel #8
0
def main(command, materials):
    global target
    mat_name = ['oil', 'bullet', 'steel', 'aluminum']
    target = cmd['factory']

    # dock1 shimakaze
    if command.startswith('dock'):
        default = 30
    # dock1 shimakaze
    elif command == 'kaihatu':
        default = 10

    do_action(target[command], 0.5)
    u.uprint("燃料{x}{a}{y}、弾薬{x}{b}{y}、鋼材{x}{c}{y}、ボーキ{x}{d}{y}".format(
        a=materials[0],
        b=materials[1],
        c=materials[2],
        d=materials[3],
        x=u.color['yellow'],
        y=u.color['default']))

    # test(target, wait_)

    for i in xrange(4):
        mat = materials[i]
        name = mat_name[i]
        if u.is_number(mat) is False:
            u.uerror("Materials quanity error (is not number)")
            return False

        mat = int(mat)
        if mat > (default + 620) or mat < default:
            u.uerror(
                "Materials quanity error (default < number < default+620)")
            return False

        mat = mat - default
        if not mat == 0:
            hundred = mat // 100
            ten = (mat % 100) // 10
            one = (mat % 10)
            # print hundred, ten, one
            for k in xrange(hundred):
                do_action(target[name + '+100'])
            for k in xrange(ten):
                do_action(target[name + '+10'])
            for k in xrange(one):
                do_action(target[name + '+1'])
Beispiel #9
0
 def print_info_ndocks(self, player, dock_id=5):
     if self.ndocks[0] is None:
         u.uerror("[Player][print_info_ndocks] Not initialized")
         return
     # 印出所有的修船廠狀態
     if dock_id == 5:
         for i in range(0, 2):
             if self.ndocks[i] is None: continue
             info = self.ndocks[i].get_info(player)
             print("第" + str(info['ndock_id']) + "修船廠(" + info['state'] +
                   "):" + info['name_count_down'])
     # 印出某個指定的修船廠狀態
     # elif dock_id > 0 and dock_id < 5 and (self.ndocks[dock_id-1] is not None):
     # self.ndocks[dock_id-1].print_info_short(player)
     else:
         u.uerror("[Player][print_info_ndocks] Invalid dock_id")
Beispiel #10
0
 def get_ship_current_id_by_nick_name(self, nick_name):
     current_id = self.get_max_level_ship_with_same_nick_name(nick_name)
     if current_id is None:
         u.uerror("この艦娘が艦隊にいないです {}".format(nick_name))
     else:
         official_name = None
         for ship in self.ships:
             if ship.nick_name == nick_name:
                 official_name = ship.name
                 break
         msg = "{c1:s}{name:s}({nick:s}){c2:s}さんですね、わかりました".format(
             c1=u.color['yellow'],
             c2=u.color['default'],
             name=official_name,
             nick=nick_name)
         u.uprint(msg)
     return current_id
Beispiel #11
0
def get_fleets_data_by_fleet_nick_name(fleet_position, fleet_code_name):
    """
        輸入要更換的艦隊位置(第 1~4 艦隊),以及目標艦隊代號,回傳該艦隊的艦娘配置

    @ fleet_position:  要更換的艦隊位置(第 1~4 艦隊)
    @ fleet_code_name: 艦隊代號
    @ return:
         有找到艦隊: 回傳該艦隊的艦娘配置,配置艦娘的話回傳暱稱,配置是空位的話回傳 None
                    tuple("akagi", "kaga", "den", "hibiki", None, None)
         沒找到艦隊: 回傳 False
    """

    found = fleet_hensei_dict.get(fleet_code_name, None)
    if found is None:
        u.uerror("この名前の艦隊がないんです")
        return False
    msg = "第 " + fleet_position[1] + " 艦隊を" + u.append_color(
        found[0], 'yellow') + "に変更します"
    u.uprint(msg)
    result = found[1:]
    return result
Beispiel #12
0
def run(player_, position, nick_name):
    global player
    player = player_

    # 取得艦娘在目前的排組中,在 local_id 的順位在"第幾個",此值並非 local_id,值應為 1 ~ 100
    ship_current_id = player.get_ship_current_id_by_nick_name(nick_name)
    if ship_current_id is None:
        return False
    # 檢查此艦娘是否空著,如果正在遠征的話就不切換
    if is_on_expedition(ship_current_id) is True:
        u.uerror(nick_name + "は今遠征中、変更できないです")
        return False

    # 計算一下此艦娘在第幾頁的第幾個
    tmp = abs(player.ships_count - ship_current_id) + 1
    page = ((tmp - 1) // 10) + 1
    number = tmp % 10
    # print "count: ", player.ships_count, "current_id: ", ship_current_id, "tmp: ", tmp
    # print "Page: ", page, "N.O: ", number

    u.get_focus_game()
    main(position, page, number)
    u.get_focus_terminal()
Beispiel #13
0
 def print_info_materials(self):
     if self.materials is None:
         u.uerror("[Player][print_info_materials] Not initialized")
         return
     self.materials.print_info()
Beispiel #14
0
def is_handled_by_predefined_func(inp):
    """
    針對使用者輸入的指令做預處理
    如果預處理就解決了,return True
    如果無法處理,return False
    """
    if inp == "exit" or inp == "bye":
        u.uprint("お疲れ様でした、明日も頑張ってください")
        exit()
    elif inp.startswith('api') and len(inp.split()) == 2:
        # 抓取 json API
        arg = inp.split()[1]
        if arg == 'quest' or arg == 'q':
            u.get_focus_game()
            kcFetchAPI.fetch_api_response(player, 'questlist')
            u.get_focus_terminal()
            return True
        elif arg == 'port' or arg == 'p':
            u.get_focus_game()
            kcFetchAPI.fetch_api_response(player, 'port')
            u.get_focus_terminal()
            return True
        else:
            return False
    elif inp.startswith('refresh') and len(inp.split()) == 1:
        # 重新讀取 kcShipData
        kcShipData.main()
        # 清空 network 監看紀錄,以免量太大導致 chrome dev tool 延遲或錯誤
        u.get_focus_game()
        u.click_and_wait([50, 700], 0.05)
        u.get_focus_terminal()
        return True
    # save f1 kobe
    elif inp.startswith('save') and len(inp.split()) == 3:
        args = inp.split()
        # 將指定艦隊(第1~4艦隊)的艦隊編成儲存起來
        avail_fleet_pos = ['f1', 'f2', 'f3', 'f4']
        if args[1] not in avail_fleet_pos:
            u.uerror('Usage: save (f1|f2|f3|f4) (fleet_name)')
            return True
        u.set_place(player, 'hensei')
        kcCommand.exec_single_command(player, u.get_place(), 'port',
                                      u.get_lag())
        kcShipData.save_current_fleets(
            player, args[2], player.decks[int(args[1][-1]) - 1].ships)
        kcShipData.load_user_fleets_data()
        return True
    elif inp.startswith('map11'):
        kcScript.exec_sikuli(player, '1-1')
        return True
    elif inp.startswith('map21'):
        kcScript.exec_sikuli(player, '2-1')
        return True
    elif inp.startswith('map22'):
        kcScript.exec_sikuli(player, '2-2')
        return True
    elif inp.startswith('map321'):
        kcScript.exec_sikuli(player, '3-2-1')
        return True
    elif inp.startswith('auto') and len(inp.split()) == 2:
        arg = inp.split()[1]
        if arg == 'repair' or arg == 'r':
            # 自動維修
            kcScript.exec_script(player, 'auto', 'repair', None)
            return True
    elif inp.startswith('cat') and len(inp.split()) == 2:
        # 顯示從 json API 得來的資料
        arg = inp.split()[1]
        if arg == '?':
            print('cat [arguments]:')
            print("[deck] [d] - 印出四個艦隊編成")
            print("[ndock] [n] - 印出維修工廠狀態")
            print("[ship] [s] - 印出所有船艦狀態")
            print("[material] [r] - 印出目前擁有的資源")
            print("[names] [name] - 印出四個艦隊編成")
            print("[fleets] [f] - 印出使用者自行編列的艦隊編成")
            print("[damage] [dmg] - 印出受傷的船艦與預期維修時間")
            print("[gearall] [ga] - 印出所有裝備與所持的艦娘")
            print("[gear] [g] - 印出貴重裝備與所持的艦娘")
            return True
        elif arg == 'deck' or arg == 'd':
            # 印出四個艦隊狀態
            player.print_info_decks()
            return True
        elif arg == 'd1' or arg == 'd1':
            # 印出第一個艦隊狀態
            player.print_info_decks(deck_id=1)
            return True
        elif arg == 'ndock' or arg == 'n':
            # 印出維修工廠狀態
            player.print_info_ndocks(player)
            return True
        elif arg == 'ship' or arg == 's':
            # 印出所有船艦狀態
            for i in range(1, 101):
                if i % 10 == 1:
                    print "[", i, "]"
                player.print_info_ships(i)
            player.print_info_ships_count()
            return True
        elif arg == 'material' or arg == 'r':  # Resource
            # 印出目前擁有的資源
            player.print_info_materials()
            return True
        elif arg == 'names' or arg == 'name':
            # 印出艦娘的暱稱
            kcShipData.cat_names()
            return True
        elif arg == 'fleets' or arg == 'f':
            # 印出使用者自行編列的艦隊編成
            kcShipData.cat_fleets()
            return True
        elif arg == 'damage' or arg == 'dmg':
            # 印出所有受傷的艦娘資訊與預期維修時間
            player.get_damaged_ships_and_repair_time()
            return True
        elif arg == 'gearall' or arg == 'ga':
            kcGear.print_all_gears()
            return True
        elif arg == 'gear' or arg == 'g':
            kcGear.print_important_gears()
            return True
        else:
            return False
    elif inp.startswith('lag'):
        # 印出目前 LAG
        if len(inp.split()) == 1:
            u.uprint("サーバーとの予測レイテンシは " +
                     u.append_color(str(u.get_lag()), 'yellow') + " 秒です")
        # 指定目前 LAG
        else:
            u.set_lag(player, inp.split()[1])
        return True
    elif inp.startswith('place'):
        # 印出目前場景
        if len(inp.split()) == 1:
            u.uprint("私たちは今 " + u.append_color(u.get_place(), 'yellow') +
                     " にいます")
        # 指定目前場景
        else:
            u.set_place(player, inp.split()[1])
        return True
    elif inp == '?':
        u.uprint("Place = " + u.append_color(u.get_place(), 'yellow') +
                 ", Lag = " + u.append_color(u.get_lag(), 'yellow'))
        u.uprint("available commands = " +
                 str(sorted(kcCommand.get_current_available_cmds())))
        return True
    elif inp == "":
        global _user_input
        _user_input = "ok"
        u.play_audio('kcAudio/nanodesu.mp3')
        return False