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 cat_fleets(): """ 印出目前使用者自訂的艦隊編成(user_fleets.data) """ for key, value in fleet_hensei_dict.items(): msg = "{} {} \n".format(u.append_color(key, 'yellow'), u.append_color(value[0], 'cyan')) for i in xrange(1, 7): name_format = u'{:\u3000<8s}'.format(value[i].decode('utf-8')) msg += str(i) + "." + (name_format).encode('utf-8') if i % 2 == 0: msg += "\n" print msg
def _parse_questlist(jsonData): meta = jsonData['api_data'] # print json.dumps(data) print "檢查任務第", meta['api_disp_page'], "頁,共", meta['api_page_count'], "頁。" quests = meta['api_list'] # 每一頁一定會有五個欄位,沒有任務的欄位會是 -1,這邊用 (1,6) 只是為了程式方便 for i in range(1, 6): quest = quests[i - 1] if quest == -1: print i, "N/A " # 此欄位沒有任務 else: """ **api_state** 任務狀況, 1 代表任務有顯示出來,但沒有選取 2 代表目前有被選取,會顯示”遂行中” 3 代表任務已完成,可以領獎 """ state = quest['api_state'] state_msg = " " if state == 1: pass elif state == 2: state_msg = u.append_color('執行中', 'yellow') elif state == 3: state_msg = u.append_color('已完成', 'yellow') state_msg += ' ' # **api_progress_flag** 目前進度,1 代表 50%,2 代表 80% progress = quest['api_progress_flag'] if progress == 1: state_msg += u.append_color('50%', 'cyan') elif progress == 2: state_msg += u.append_color('80%', 'cyan') else: state_msg += " " state_msg += " " msg = "" # 任務編號 # msg += "No." + str(quest['api_no']) + " " # msg += state_msg + " " + quest['api_title'] # print type(msg), type(state_msg), type(quest['api_title']) msg += state_msg + " " + (quest['api_title'].encode('utf-8')) print i, msg # 回傳 總共有幾頁 return meta['api_page_count']
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')))
def _format_damaged_ships_and_repair_time(self, value): # 幫修理時間上色 repair_time = '{:0>2d}:{:0>2d}:{:0>2d}'.format(value[0][0], value[0][1], value[0][2]) if not value[0][0] == 0: if value[0][0] == 1: repair_time = u.append_color(repair_time, 'yellow') else: repair_time = u.append_color(repair_time, 'red') msg = '{repair_time:>8s}, lv{lv:>2d} {name} ({hp}) {next}'.format( repair_time=repair_time, lv=value[2], name=u.append_color(value[3], 'cyan'), hp=value[1], next=value[4]) return msg
def print_user_ships_data_fields(fields): name = fields[0].strip() nick_name = fields[1].strip() planes = fields[2].strip() # 轉成 unicode object,為了插入 \u3000 排版.. name_format = u'{:\u3000<4s}'.format(name.decode('utf-8')) msg = u.append_color(name_format.encode('utf-8'), 'yellow') msg += '{nick_name:<12s}{planes:<14s}'.format(nick_name=nick_name, planes=planes) print msg
def _get_hp_and_next_ha(self, nowhp, maxhp): hp = str(nowhp) + "/" + str(maxhp) div = float(nowhp) / float(maxhp) if div == 1: next_ha = '' elif div <= 0.25: hp += ' 大破' hp = u.append_color(hp, 'red') # 計算距離下一個破還差多少 hp next_ha = u.append_color('!!!', 'red') elif div <= 0.5: hp += ' 中破' hp = u.append_color(hp, 'orange') next_ha = u.append_color('+' + str(nowhp - int(maxhp / 4.0)), 'red') elif div <= 0.75: hp += ' 小破' next_ha = u.append_color('+' + str(nowhp - int(maxhp / 2.0)), 'orange') else: next_ha = '+' + str(nowhp - int(maxhp / 2.0)) return (hp, next_ha)
def print_all_gears(important_gears=None): result = list() for sortno, gearData in gear_data.items(): if gearData.count == 0: continue elif important_gears is None: result.append((gearData.name, gearData)) else: for important_gear in important_gears: if (gearData.name == important_gear[4:]): result.append((important_gear, gearData)) break # if any(gearData.name in important_gear for important_gear in important_gears): # result.append(gearData) continue # ([3] 烈風 , GearData(name, sortno, count, who_has() )) result.sort() sort_title = ['主副砲', '対空武器', 'ソナー、爆雷', '戦闘機', '電探、その他'] sort_title_now = -1 for tuple_ in result: # print sort_title_now, tuple_[0][1] if (not tuple_[0][1] == str(sort_title_now)) and (not important_gears == None): sort_title_now += 1 print('\n{}'.format( u.append_color('### ' + sort_title[sort_title_now] + '###', 'cyan'))) gearData = tuple_[1] print('{}, {}'.format(u.append_color(tuple_[0], 'yellow'), u.append_color(gearData.count, 'green'))) if not len(gearData.who_has) == 0: msg = '' for ship_name in gearData.who_has: msg += u.append_color(ship_name, 'default') + ',' print(msg)
def main(): global _user_input global player player = Player() kcShipData.main() kcGear.main() u.uprint("あわわわ、びっくりしたのです。") # set_place("port") while True: _user_input = raw_input(u.append_color('電:提督、ご命令を', 'green') + " > ") if is_handled_by_predefined_func(_user_input) is True: continue check_command(_user_input)
def main(player, world_, map_, plan_): u.set_place(player, 'port', update_api=False) do_action(player, u.get_place(), 'fight') do_action(player, u.get_place(), 'pve', u.get_lag()) do_action(player, u.get_place(), world_) do_action(player, u.get_place(), map_) do_action(player, u.get_place(), 'y') do_action(player, u.get_place(), 'tatakau') t = SikuliThread("t1", plan_) t.start() while(True): # print t.thread_status if t.thread_status == 0: break; # spam 陣形一,"陣形 - 単縦陣" u.click_and_wait(cmd['tatakau']['1'][2], 0) u._sleep(3, print_=False) # 戰鬥結束,回到母港 u.set_place(player, 'port') do_action(player, u.get_place(), 'refill', u.get_lag()) u.uprint('出撃終了です、補給します', 'yellow') # 一個一個補給,每日補給任務 # kcScripts.refill_fleet_daily.run(player, 'f1') # 一次全部補給 kcScripts.refill_fleet_all.run('f1') # 只補給旗艦(捨て艦戦術) # do_action(player, u.get_place(), 'refill') # do_action(player, u.get_place(), '1') # do_action(player, u.get_place(), 'matome') do_action(player, u.get_place(), 'hensei') u.uprint('作戦 {} 遂行完了です'.format(u.append_color(plan_, 'cyan'))) player.print_info_decks(deck_id=1) player.print_info_ships_count() player.print_info_ndocks(player)
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
def get_info(self, player): ndock_state = {0:'閒置', 1:'維修中'} name = kcShipData.get_name_by_local_id(player, self.ship_local_id) self.update_current_time() seconds_left = 0 if self.complete_time is not 0: seconds_left = self.complete_time - self.current_time # 從 7615 秒 轉成 02:06:55 格式 hour = int(seconds_left // 3600) # 先 cast 成 int,以免整除時出現 1.0 等 minute = int(seconds_left % 3600 // 60) second = int(seconds_left % 60) count_down = '({:0>2s}:{:0>2s}:{:0>2s})'.format(str(hour), str(minute), str(second)) info = dict() info['ndock_id'] = self.ndock_id info['state'] = ndock_state.get(self.state, 'Error') info['ship_local_id'] = self.ship_local_id info['name_count_down'] = u.append_color(name + count_down, 'yellow') info['seconds_left'] = seconds_left return info
def print_info_ships_count(self): msg = self.ships_count if self.ships_count > 95: msg = u.append_color(self.ships_count, 'red') print "艦娘保有数:", msg
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