def fun():
     nonlocal screen
     out = self.get_fight_auto(screen, 3)
     if out == -1:
         raise RetryNow()
     if out == auto:
         return True
     else:
         self.click(FIGHT_BTN["auto_on"], post_delay=1.5)  # 避免涟漪影响
         screen = self.getscreen()
         raise ContinueNow()
 def fun():
     nonlocal screen
     out = self.get_fight_speed(screen, 3)
     if out == -1:
         raise RetryNow()
     if out == level:
         return True
     else:
         while out != level:
             self.click(FIGHT_BTN["speed_0"], post_delay=0.2)
             out = (out + 1) % (max_level + 1)
         time.sleep(1.3)  # 防止涟漪
         screen = self.getscreen()
         raise ContinueNow()
Ejemplo n.º 3
0
            def DOIT():
                nonlocal t
                if t == 0:
                    return "continue"
                M: FightInfoZhuXian = S.click_xy_and_open_fightinfo(x, y)
                if M is None:
                    if can_not_enter_action == "exit":
                        self.log.write_log("info", f"无法进入图{m}{a}-{b}!结束刷图。")
                        self.save_last_screen(f"CanNotEnter2_{self.account}.bmp")
                        self.lock_home()
                        return "return"
                    elif can_not_enter_action == "skip":
                        self.log.write_log("info", f"无法进入图{m}{a}-{b}!跳过该图。")
                        return "continue"
                S.clear_initFC()
                sc = self.getscreen()
                stars = M.get_upperright_stars(sc)
                if stars == 3:
                    # 可以扫荡
                    # 次数判断:对Hard图
                    max_cishu = t  # 目标:刷t次
                    if m == "H":
                        cishu = M.get_cishu(sc)
                        if cishu == 0:
                            # 不能扫荡,没有次数
                            ds["hard"][f"{a}-{b}"] = 3
                            record_ds(ds)
                            for _ in range(6):
                                self.click(1,1)
                            self.log.write_log("info", f"{m}{a}-{b}已经不能再刷更多了!")
                            return "continue"
                        max_cishu = min(cishu, max_cishu)
                    self._zdzb_info = ""  # 记录失败原因
                    # 扫荡券判断:最多还能扫荡几次
                    quan = M.get_saodangquan(sc)
                    if quan<max_cishu:
                        self._zdzb_info = "noquan"
                        if quan==0:
                            self.log.write_log("warning", "已经没有扫荡券了!终止刷图。")
                            self.lock_home()
                            return "return"
                        self.log.write_log("warning", f"扫荡券可能不足,只能支持刷{quan}次了。")
                        max_cishu=quan

                    # 体力判断:最多还能进行几次
                    left_tili = M.get_tili_left(sc)
                    one_tili = LoadPCRData().get_map_tili(mode, a, b)
                    max_cishu_tili = floor(left_tili / one_tili)
                    bought_tili = False
                    while max_cishu_tili < max_cishu:
                        # 体力不足:可以选择买体力倒是。
                        if ds["buy_tili"] < daily_tili:
                            # 可以!买体力!
                            for _ in range(6):
                                self.click(1, 1)
                            bought_tili = True
                            S.goto_buytili().OK().OK()
                            ds["buy_tili"] += 1
                            record_ds(ds)
                            self.log.write_log("info", f"体力不足,购买体力{ds['buy_tili']}/{daily_tili}")
                            left_tili += 120
                            max_cishu_tili = floor(left_tili / one_tili)
                        else:
                            # 已经……买不动了
                            if daily_tili > 0:
                                self.log.write_log("info", f"已经消耗完全部的买体力次数了。")
                            self._zdzb_info = "notili"
                            if max_cishu_tili == 0:
                                self.log.write_log("info", "已经一点体力都不剩了!终止刷图。")
                                self.stop_shuatu()
                                self.lock_home()
                                return "return"
                            else:
                                self.log.write_log("info", f"剩下的体力只够刷{max_cishu_tili}次了!")
                            break
                    if bought_tili:
                        # 买过体力之后要重新进图
                        S.click_xy_and_open_fightinfo(x, y)
                    max_cishu = min(max_cishu, max_cishu_tili)
                    # 扫荡
                    true_cishu = max_cishu
                    M.set_saodang_cishu(true_cishu, one_tili=one_tili, left_tili=left_tili,sc=self.last_screen)
                    SD = M.goto_saodang()  # 扫荡确认
                    SD = SD.OK()  # 扫荡结果
                    # 记录
                    ds[mode][f"{a}-{b}"] += true_cishu
                    record_ds(ds)
                    MsgList = SD.OK()  # 扫荡后的一系列MsgBox
                    while True:
                        out = MsgList.check()
                        if out is None:  # 无msgbox
                            break
                        if isinstance(out, MsgList.XianDingShangDianBox):
                            # 限定商店
                            if xianding:
                                shop = out.Go()
                                shop.buy_all()
                                shop.back()
                                break
                            else:
                                out.Cancel()
                        if isinstance(out,MsgList.TuanDuiZhanBox):
                            out.OK()
                        if isinstance(out,MsgList.LevelUpBox):
                            out.OK()
                            self.start_shuatu()  # 体力又有了!
                        if isinstance(out,MsgList.ChaoChuShangXianBox):
                            out.OK()
                    # 扫荡结束
                    # 保险起见
                    for _ in range(6):
                        self.click(1,1)
                    if true_cishu<t:
                        self.log.write_log("info", f"{m}{a}-{b}刷图剩余次数:{t - true_cishu}")
                        t -= true_cishu
                        raise ContinueNow("DOIT")
                    else:
                        self.log.write_log("info", f"{m}{a}-{b}刷图成功!")
                else:
                    # 特判
                    if stars==0:
                        if zero_star_action == "exit":
                            self.log.write_log("info",f"{m}{a}-{b}尚未通关,终止刷图!")
                            self.lock_home()
                            return "return"
                        elif zero_star_action == "skip":
                            self.log.write_log("info", f"{m}{a}-{b}尚未通关,跳过刷图!")
                            for _ in range(6):
                                self.click(1,1)
                            return "continue"
                    if stars<3:
                        if not_three_star_action == "exit":
                            self.log.write_log("info", f"{m}{a}-{b}尚未三星,终止刷图!")
                            self.lock_home()
                            return "return"
                        elif not_three_star_action == "skip":
                            self.log.write_log("info", f"{m}{a}-{b}尚未三星,跳过刷图!")
                            for _ in range(6):
                                self.click(1,1)
                            return "continue"
                    # 次数判断:对Hard图
                    if m == "H":
                        cishu = M.get_cishu(sc)
                        if cishu == 0:
                            # 不能扫荡,没有次数
                            ds["hard"][f"{a}-{b}"] = 3
                            record_ds(ds)
                            for _ in range(6):
                                self.click(1, 1)
                            self.log.write_log("info", f"{m}{a}-{b}已经不能再刷更多了!")
                            return "continue"
                    # 体力判断:至少得有一次体力,否则就买
                    left_tili = M.get_tili_left(sc)
                    one_tili = LoadPCRData().get_map_tili(mode, a, b)
                    bought_tili = False
                    if left_tili<one_tili:
                        # 体力不足:可以选择买体力倒是。
                        if ds["buy_tili"] < daily_tili:
                            # 可以!买体力!
                            for _ in range(6):
                                self.click(1, 1)
                            bought_tili = True
                            S.goto_buytili().OK().OK()
                            ds["buy_tili"] += 1
                            record_ds(ds)
                            self.log.write_log("info", f"体力不足,购买体力{ds['buy_tili']}/{daily_tili}")
                        else:
                            # 已经……买不动了
                            self.log.write_log("info", "已经一点体力都不剩了!终止刷图。")
                            self.stop_shuatu()
                            self.lock_home()
                            return "return"
                    if bought_tili:
                        # 买过体力之后要重新进图
                        S.click_xy_and_open_fightinfo(x, y)
                    # 体力次数都够了,进入挑战
                    TZ = M.goto_tiaozhan()
                    TZ.select_team(team_order)
                    F = TZ.goto_fight()
                    During = F.get_during()
                    F.set_auto(1, self.last_screen)
                    F.set_speed(1, self.last_screen)
                    state = {"flag": None}
                    last_time = time.time()
                    while True:
                        if time.time() - last_time > 300:
                            # TOO LONG
                            raise LockTimeoutError("战斗超时!")
                        out = During.check()
                        if out is None:
                            continue
                        if isinstance(out, During.LoveUpScene):
                            out.skip()
                        if isinstance(out, During.FightingLoseZhuXian):
                            state["flag"] = "lose"
                            out.goto_zhuxian(type(S))
                            break
                        if isinstance(out, During.FightingWinZhuXian):
                            state["flag"] = "win"
                            state["star"] = out.get_star()
                            state["next"] = out.get_after()
                            out.next()
                            break
                        if isinstance(out, During.FightingDialog):
                            out.skip()
                    if state["flag"] == "win":
                        # 记录
                        ds[mode][f"{a}-{b}"] += 1
                        record_ds(ds)
                    if state["flag"] == "win" and state["star"] < 3 and win_without_threestar_is_lose:
                        self.log.write_log("info", f"没有三星通关({state['star']}/3),算作失败!")
                        state["flag"] = "lose"
                    if state["flag"] == "lose":
                        if lose_action == "exit":
                            self.log.write_log("info", f"战败于{m}{a}-{b},结束刷图!")
                            self.lock_home()
                            return "return"
                        elif lose_action == "skip":
                            self.log.write_log("info", f"战败于{m}{a}-{b},跳过该图!")
                            return "continue"
                        else:
                            self.log.write_log("info", f"战败于{m}{a}-{b},重试该图!")
                            raise RetryNow("DOIT")
                    else:
                        # 战胜了!
                        self.log.write_log("info", f"战胜了{m}{a}-{b} ({state['star']}/3)!")
                        last_time = time.time()
                        next = state["next"]
                        while True:
                            if time.time() - last_time > 120:
                                raise LockTimeoutError("在结算页面超时!")
                            out = next.check()
                            if out is None:
                                break
                            if isinstance(out, next.XianDingShangDianBox):
                                # 限定商店
                                if xianding:
                                    shop = out.Go()
                                    shop.buy_all()
                                    shop.back()
                                    break
                                else:
                                    out.Cancel()
                            if isinstance(out, next.TuanDuiZhanBox):
                                out.OK()
                            if isinstance(out, next.LevelUpBox):
                                out.OK()
                                self.start_shuatu()  # 体力又有了!
                            if isinstance(out, next.ChaoChuShangXianBox):
                                out.OK()
                            if isinstance(out, next.AfterFightKKR):
                                out.skip()
                                # 再次进图
                                self.get_zhuye().goto_maoxian().goto_zhuxian()
                                break
                            if isinstance(out, next.FightingWinZhuXian2):
                                # 外出后可能还有Box,需要小心谨慎
                                out.next()
                        # 开init
                        S.set_initFC()

                        # 手刷结束
                        t -= 1
                    raise ContinueNow("DOIT")  # 把t次刷完