def run(self, stage_code: str, repeat_times: int = 1000, try_current_activity=True): stage_code = stage_code.upper() if try_current_activity: try: ActivityAddOn(self.helper).run(stage_code, repeat_times) return except: pass stage_code_map, zone_linear_map = get_stage_map() if stage_code not in stage_code_map: raise RuntimeError(f'无效的关卡: {stage_code}') stage = stage_code_map[stage_code] activity_id = stage['zoneId'].split('_')[0] activity_infos = get_activity_infos() activity = activity_infos[activity_id] logger.debug(f'stage: {stage}, activity: {activity}') self.enter_activity(activity) self.after_enter_activity(stage) stage_linear = zone_linear_map[stage['zoneId']] logger.info( f"stage zone id: {stage['zoneId']}, stage_linear: {stage_linear}") self.helper.find_and_tap_stage_by_ocr(None, stage_code, stage_linear) self.helper.module_battle_slim(None, repeat_times)
def enter_activity(self, activity): vh = self.vh act_name = get_activity_name(activity) if act_name not in get_available_activity(): raise RuntimeError(f'无效的活动: {act_name}') self.open_terminal() if activity['displayType'] == 'BRANCHLINE': self.tap_branch_line() else: self.tap_side_story() crop_flag = activity['displayType'] == 'SIDESTORY' act_pos_map = self.get_all_act_pos(crop_flag) if act_name not in act_pos_map: if activity['displayType'] == 'BRANCHLINE': raise RuntimeError(f'找不到相应活动: {act_name}') last_acts = act_pos_map.keys() while True: origin_x = random.randint(int(5.833 * vh), int(24.861 * vh)) origin_y = random.randint(int(57.222 * vh), int(77.917 * vh)) move = -random.randint(int(vh // 5), int(vh // 4)) self.helper.adb.touch_swipe2((origin_x, origin_y), (random.randint(-20, 20), move), random.randint(900, 1200)) act_pos_map = self.get_all_act_pos(crop_flag) if act_name in act_pos_map: break if last_acts == act_pos_map.keys(): raise RuntimeError(f'找不到相应活动: {act_name}') last_acts = act_pos_map.keys() logger.info(f'switch to {act_name}') self.click(act_pos_map[act_name], 1) self.tap_enter_activity()
def get_all_act_pos(self, crop=False): act_map = {} screen = self.screenshot() cv_screen = pil2cv(screen) for icon in [icon1, icon2]: act_map.update(self.get_act_pos_by_icon(cv_screen, icon, crop)) logger.info(act_map) return act_map
def run(self, **kwargs): print('加载库存信息...') aog_cache = load_aog_cache() my_items = self.load_inventory() all_items = arkplanner.get_all_items() l = [] for item in all_items: if item['itemType'] in ['MATERIAL'] and item['name'] not in exclude_names and item['rarity'] == 2 \ and len(item['itemId']) > 4: l.append({ 'name': item['name'], 'itemId': item['itemId'], 'count': my_items.get(item['itemId'], 0), 'rarity': item['rarity'] }) l = sorted(l, key=lambda x: x['count']) print('require item: %s, owned: %s' % (l[0]['name'], l[0]['count'])) aog_items = aog_cache['aog'] t3_items = aog_items['tier']['t3'] stage = '' for t3_item in t3_items: if t3_item['name'] == l[0]['name']: # print(t3_item) stage_info = order_stage(t3_item) stage = stage_info['code'] print('aog stage:', stage) break try: self.helper.module_battle(stage, 1000) except Exception as e: if use_start_sp_stage: from addons.start_sp_stage import StartSpStageAddon logger.info('尝试进入活动关卡') StartSpStageAddon(self.helper).run(stage, 1000) else: raise e
def open_terminal(self): self.helper.back_to_main() logger.info('open terminal') self.helper.tap_quadrilateral( imgreco.main.get_ballte_corners(self.screenshot())) time.sleep(1)
def tap_enter_activity(self): logger.info('enter activity') vh, vw = self.vh, self.vw self.helper.tap_rect((100 * vw - 24.583 * vh, 69.167 * vh, 100 * vw - 8.750 * vh, 75.556 * vh)) time.sleep(1)
def tap_branch_line(self): logger.info('open branch line view') vh, vw = self.vh, self.vw self.helper.tap_rect( (29.375 * vw, 88.611 * vh, 41.719 * vw, 98.750 * vh)) time.sleep(1)
def tap_side_story(self): vh, vw = self.vh, self.vw logger.info('open side story view') self.helper.tap_rect( (44.297 * vw, 88.611 * vh, 56.406 * vw, 98.750 * vh)) time.sleep(1)
if __name__ == '__main__': if not os.path.exists('config/plan.json'): logger.error('未能检测到刷图计划文件.') exit(-1) with open('config/plan.json', 'r') as f: plan = json.load(f) helper, _ = _create_helper() if plan['stages']: update_flag = False has_remain_sanity = True for task in plan['stages']: remain = task.get('remain', task['count']) if remain == 0: continue logger.info('准备执行关卡 [%s], 计划次数: %s, 剩余次数: %s' % (task['stage'], task['count'], remain)) update_flag = True c_id, remain = helper.module_battle(task['stage'], remain) task['remain'] = remain if remain > 0: logger.info('理智不足, 退出计划执行') has_remain_sanity = False break if update_flag: with open('config/plan.json', 'w') as f: json.dump(plan, f, indent=4, sort_keys=True) print('刷图计划已更新至: config/plan.json') if has_remain_sanity and config.get('plan/idle_stage', None) is not None: # todo recheck idle_stage = config.get('plan/idle_stage')