def check_command(input_): """ @ input_ : (string) 使用者輸入的字串 @ return : 將使用者輸入的字串切割,並檢查第一個 word[0] 是否為合法的指令(Command), 如果正常的話就執行,不回傳 如果非合理指令,就不動作並回傳 False e.g. input_ = "c1 akagi" 則我們檢查 word[0],也就是 "c1" 是否為合法的指令。 """ input_ = input_.split() command = input_[0] if len(input_) > 1: args = input_[1:] place = kcCommand.get_place_of_command(command) if place is None: u.unknown_command(command) return False if len(input_) > 1: kcScript.exec_script(player, place, command, args) else: kcCommand.exec_single_command(player, place, command)
def do_action(player, place, command, sleep_time): exec_single_command(player, place, command, sleep_time)
def exec_script(player, place, command, args): if place == 'hensei': change_ship_cmds = ['c1', 'c2', 'c3', 'c4', 'c5', 'c6'] change_fleet_cmds = ['f1', 'f2', 'f3', 'f4'] if (command in change_ship_cmds) and len(args) == 1: # "c1 akagi" kcScripts.change_ship.run(player, command, args[0]) elif (command in change_fleet_cmds) and len(args) == 1: # "f1 kobe" # 自動找出代號為 "kobe" 的艦隊編列,並將第一艦隊(f1) 更換成代號艦隊所編列的艦娘 # kcScripts.change_fleet.run(player, command, args[0]) # 找出該艦隊的所有艦娘位置 result = kcShipData.get_fleets_data_by_fleet_nick_name( command, args[0]) if result is False: return False # 切換成該艦隊 (f1 ~ f4) kcCommand.exec_single_command(player, place, command) u._sleep(0.1) # 清空目前艦隊 kcCommand.exec_single_command(player, place, 'clear') u._sleep(u._LAG) # 檢查目前旗艦是否需要更換 begin = 0 flagship_local_id = player.decks[int(command[1:]) - 1].ships[0] flagship_name = kcShipData.get_name_by_local_id( player, flagship_local_id) if flagship_name == result[0]: u.uprint("旗艦は{}さん、変更する必要はありません".format( u.append_color(flagship_name, 'yellow'))) begin = 1 # 切換五個或六個艦娘 for i in xrange(begin, 6): if result[i] is not "": nick_name = kcShipData.get_adana_by_name(result[i]) if kcScripts.change_ship.run(player, 'c' + str(i + 1), nick_name) is not False: u._sleep(u._LAG) # 回到 port kcCommand.exec_single_command(player, place, 'port') elif place == 'refill': fleet_cmds = ['f1', 'f2', 'f3', 'f4'] if (command in fleet_cmds) and len(args) == 1: # "f1 dialy" if args[0] == 'daily': kcScripts.refill_fleet_daily.run(player, command) # "f1 all" elif args[0] == 'all': kcScripts.refill_fleet_all.run(command) elif place == 'factory': build_cmds = ['dock1', 'dock2'] if command in build_cmds: # "dock1 uc" if len(args) == 1 and args[0] == 'uc': kcScripts.factory_uc.run(command) # "dock1 shimakaze" elif len(args) == 1: if args[0] == 'shimakaze' or args[0] == 's': kcScripts.factory_build.run(command, (250, 30, 200, 30)) elif args[0] == 'kuubou' or args[0] == 'k': kcScripts.factory_build.run(command, (300, 30, 400, 300)) # "dock2 250 30 200 30" elif len(args) == 4: kcScripts.factory_build.run(command, args) elif command == 'kaihatu': # "kaihatu plane" if len(args) == 1: # http://wikiwiki.jp/kancolle/?%B3%AB%C8%AF%A5%EC%A5%B7%A5%D4 if args[0] == 'plane' or args[0] == 'p': kcScripts.factory_build.run(command, (20, 60, 10, 110)) elif args[0] == 'sonar' or args[0] == 's': kcScripts.factory_build.run(command, (10, 10, 10, 20)) elif args[0] == 'bakurai' or args[0] == 'b': kcScripts.factory_build.run(command, (10, 30, 10, 10)) elif args[0] == 'sb': kcScripts.factory_build.run(command, (10, 30, 10, 31)) elif args[0] == 'm': kcScripts.factory_build.run(command, (10, 90, 90, 30)) # "kaihatu 20 50 10 110" elif len(args) == 4: kcScripts.factory_build.run(command, args) elif command == 'build' and args[0] == 'uc': kcScripts.factory_uc.run(command) elif place == 'auto': if command == 'repair': kcScripts.auto_repair.run(player) else: u.unknown_command(command)
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