Beispiel #1
0
def fight_finish():
    adb = AutoAdb()

    # 等待战斗结束
    timer = Timer()
    while True:
        print('\r等待战斗结束 %ds ...' % timer.get_duration(), end='')
        skip_dialog()
        time.sleep(3)  # 每次循环加一个等待时间,降低cpu占用
        if adb.check('temp_images/fight/fight-finish.png'):
            print(' √ 总耗时: %ds' % timer.get_duration())
            break

    # 战斗结束
    fight_result = None
    ending_loc = Location(adb, None, 1160, 690)
    while True:
        if fight_result is None:
            # 处理新船
            new_ship = adb.check('temp_images/fight/new-ship.png')
            if new_ship:
                print('发现新船!!')
                fight_result = True
                ending_loc.click()
                adb.click('temp_images/confirm-btn.png')
                continue
            # 处理失败
            fail_confirm = adb.click('temp_images/fight/fail-confirm.png')
            if fail_confirm:
                fight_result = False
                # 战队难以成型时点击确定
                adb.wait('temp_images/confirm-btn.png', max_wait_time=3).click()
                break
        # 持续点击右下角
        ending_loc.click()
        # 回到 stage列表页面 或 敌人列表页面 也说明战斗已经结束
        if adb.check('temp_images/page/in-stage.png',  # stage列表
                     'temp_images/page/in-enemy.png',  # enemy列表
                     'temp_images/page/in-daily.png'):  # 日常任务结束后的界面
            fight_result = True
            break
        if adb.check('temp_images/page/in-operation.png'):
            print('误入演习界面,退出。。。')
            PageUtils.back()
            continue

    print('战斗胜利~(~ ̄▽ ̄)~' if fight_result else '战斗失败 >_<')
    # 战斗结束后可能出现紧急任务提示
    # 由于是透明遮罩, 所以无法根据其他元素是否显示而做出反应, 只能等一定的时间
    adb.wait('temp_images/confirm-btn.png', max_wait_time=2).click()
    return fight_result
Beispiel #2
0
def fight_stage(stage_temp_list):
    if stage_temp_list is None or len(stage_temp_list) == 0:
        print('目标关卡未指定')
        exit(1)

    auto_adb = AutoAdb()
    # 判断是否已经在关卡中
    in_enemy = PageUtils.in_enemy_page()
    if in_enemy:
        fight_all_enemy()
        return

    # 确定进入
    timer = Timer()
    while True:
        print('\r扫描目标关卡中 ... %ds ' % timer.get_duration(), end='')
        loc = auto_adb.get_location(*stage_temp_list)
        if loc is not None:
            break

    print('%s √' % loc.temp_rel_path)
    loc.click()  # 点击关卡图标
    confirmed = confirm_stage_team()  # 确认队伍
    if not confirmed:  # 如果队伍确认失败,则重新做一次
        fight_stage(stage_temp_list)
Beispiel #3
0
    def wait(self,
             temp_rel_path,
             threshold=threshold,
             cycle_interval=0,
             max_wait_time=None,
             episode=None):
        timer = Timer()
        while True:
            duration = timer.get_duration()
            print('\r > wait %s ... %ds ' % (temp_rel_path, duration), end='')

            if max_wait_time is not None and 0 < max_wait_time < duration:
                print(' ×', flush=True)
                return Location(self, None, None, None)

            if episode is not None:
                try:
                    episode()
                except Exception as e:
                    print('过程方法执行异常')
                    print(e)

            loc = self.get_location(temp_rel_path, threshold=threshold)
            if loc is not None:
                print(' √', flush=True)
                return loc

            if cycle_interval > 0:
                time.sleep(cycle_interval)
Beispiel #4
0
    def wait(self,
             temp_rel_path,
             threshold=threshold,
             max_wait_time=None,
             episode=None):
        timer = Timer()
        none_loc = Location(self, None, None, None)
        while True:
            duration = timer.get_duration()
            print('\r > wait %s ... %ds ' % (temp_rel_path, duration), end='')

            if max_wait_time is not None and 0 < max_wait_time < duration:
                print(' ×', flush=True)
                return none_loc

            if episode is not None:
                try:
                    res = episode()
                    if res is not None and not res:
                        return none_loc
                except Exception as e:
                    print('过程方法执行异常')
                    print(e)

            loc = self.get_location(temp_rel_path, threshold=threshold)
            if loc is not None:
                print(' √', flush=True)
                return loc
Beispiel #5
0
def wind_up_stage_fight():
    timer = Timer()
    while PageUtils.in_fight_page():
        print('\r战斗中。。。 %ds ' % timer.get_duration(), end='')
        time.sleep(5)

    if PageUtils.in_enemy_page():
        print('进行关卡收尾。。。')
        fight_all_enemy()
        return True
    return False
Beispiel #6
0
def confirm_stage_team():
    adb = AutoAdb()
    timer = Timer()
    while True:
        print('\r确认关卡队伍中。。。 %ds ' % timer.get_duration(), end='')
        # 如果已经进入敌人列表界面,则跳出循环
        if PageUtils.in_enemy_page():
            print(' √')
            fight_all_enemy()  # 战斗
            return True

        button_list = [
            'temp_images/stage/immediate-start.png',  # 立刻前往
            'temp_images/stage/weigh-anchor.png',  # 出击按钮
            'temp_images/fight/fight-confirm.png'  # 特殊关卡会提示更多
        ]
        button_loc = adb.get_location(*button_list)
        if button_loc is not None:
            button_loc.click()
        port_full = PortUtils.check_port_full()
        if port_full:
            return False
Beispiel #7
0
def fight_stage(stage_temp_list):
    if stage_temp_list is None or len(stage_temp_list) == 0:
        print('目标关卡未指定')
        exit(1)

    auto_adb = AutoAdb()
    # 判断是否已经在关卡中
    wind_up_stage_fight()

    # 确定进入
    timer = Timer()
    while True:
        print('\r扫描目标关卡中 ... %ds ' % timer.get_duration(), end='')
        loc = auto_adb.get_location(*stage_temp_list)
        if loc is not None:
            break

    print('%s √' % loc.temp_rel_path)
    loc.click()  # 点击关卡图标
    confirm_result = confirm_stage_team()  # 确认队伍, 战斗
    if confirm_result is None:  # 如果关卡进入失败, 则重新尝试
        print('关卡进入失败, 重新尝试...')
        fight_stage(stage_temp_list)
    return confirm_result