def exec_single_command(player, place, command, sleep=0): cmd_msg = cmd[place][command][0] cmd_type = cmd[place][command][1] cmd_pos = cmd[place][command][2] # type 0 滑鼠點擊乙次: if cmd_type == 0: u.get_focus_game() if not cmd_msg.strip() == "": u.uprint(cmd_msg) u.click_and_wait(cmd_pos, sleep) u.get_focus_terminal() # type 1 滑鼠點擊乙次(會切換場景): elif cmd_type == 1: u.get_focus_game() u.uprint(cmd_msg) u.click_and_wait(cmd_pos, sleep) u.set_place(player, command) u.get_focus_terminal() """ # type 2 一系列的滑鼠點擊: elif cmd_type == 2: pass # type 3 滑鼠點擊乙次,有 callback: elif cmd_type == 3: pass # type 4 滑鼠點擊乙次(會切換場景),有 callback: elif cmd_type == 4: pass """ else: u.unknown_command(command)
def main(player): # 先回 port,更新 API # u.set_place(player, 'place') # 檢查是否有空的 ndock 與受傷的艦娘 do_action(player, u.get_place(), 'ndock', u.get_lag()) do_action(player, u.get_place(), 'port', u.get_lag()) player.get_damaged_ships_and_repair_time() u.get_focus_terminal() u.scroll_down() u.get_focus_game() try: check_ndock_and_kanmusu(player) except KeyboardInterrupt: print "" u.uprint('自動修理が中断されました', 'red') return u.uprint('全部修理完了です')
def check_ndock_and_kanmusu(player): """ 這邊採用 busy waiting,實際上不用 busy waiting 也能做到一樣的效果 但我喜歡看他倒數 為了應應臨時抓不到 api、網路延遲、遠征回來等情形 ,這裡先持續用 busy waiting 暫時不要 refactoring """ global injured_kanmusu_count global empty_dock u.uprint('空いてるドック = ' + str(empty_dock)) all_healed = False while all_healed is False: # 檢查受傷的艦娘 injured_kanmusu_count = 0 for i in xrange(100): if player.ships[i] is None: break elif player.ships[i].dmghp > 0: injured_kanmusu_count += 1 # 檢查空的維修廠 for i in xrange(2): if player.ndocks[i].state == 0: empty_dock[i] = True else: empty_dock[i] = False # 到 ndock 將受傷的艦娘放入 if (True in empty_dock) and (injured_kanmusu_count > 1): put_into_ndock(player) elif (injured_kanmusu_count == 0) or (injured_kanmusu_count == 1): all_healed = True # 監看並等待維修時間差不多結束 else: seconds_left = player.print_info_ndocks_auto_repair(player) if seconds_left[0] < 59 or seconds_left[1] < 59: print "" # random sleep u.get_focus_game() do_action(player, u.get_place(), 'ndock', u.get_lag()) do_action(player, u.get_place(), 'port', u.get_lag()) u.get_focus_game() u.sleep(1)
def put_into_ndock(player): global injured_kanmusu_count global empty_dock fast_sleep = 1.7 u.uprint('空いてるドック = ' + str(empty_dock)) player.get_damaged_ships_and_repair_time() u.get_focus_terminal() u.scroll_down() u.get_focus_game() do_action(player, u.get_place(), 'ndock', u.get_lag()) if empty_dock[0] is True: # 從最上面修 (大破、中破) do_action(player, u.get_place(), 'dock1', fast_sleep) do_action(player, u.get_place(), '1', fast_sleep) elif empty_dock[1] is True: # 從最下面修 (擦傷、小破) do_action(player, u.get_place(), 'dock2', fast_sleep) count = injured_kanmusu_count if count > 9: count = 0 do_action(player, u.get_place(), str(count), fast_sleep) # 回到 port,更新 API do_action(player, u.get_place(), 'repair', fast_sleep) do_action(player, u.get_place(), 'hai', u.get_lag()) do_action(player, u.get_place(), 'port', u.get_lag()) u.get_focus_game() player.print_info_ndocks(player) u.get_focus_terminal() u.scroll_down() u.get_focus_game()
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()
def run(player_, fleet): u.get_focus_game() main(player_, fleet) u.get_focus_terminal()
def run(player): u.get_focus_game() main(player) u.get_focus_terminal()
def run(command): u.get_focus_game() main(command) u.get_focus_terminal()
def run(fleet): u.get_focus_game() main(fleet) u.get_focus_terminal()
def run(command, materials): u.get_focus_game() main(command, materials) u.get_focus_terminal()
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
def run(player, world_, map_, plan_): u.get_focus_game() main(player, world_, map_, plan_) u.get_focus_terminal()