# -*- coding: utf-8 -*-
from scriptBase.imgFind import pcacc_img, savePic
from scriptBase.mouseClick import pcacc_mouse
from scriptBase.ocr import capture_and_ocr

import scriptBase.base
from scriptBase.comon import *
from scriptBase.ocr import *
from apscheduler.schedulers.blocking import BlockingScheduler
import pyautogui
import random
import sys
import math
import os
import time
from yys_define import *
from yys_pic import *
import subprocess
from yys_pic import _imported
import socket




'''
基础配置说明：
1280*720（DPI 240）
游戏画面：流畅
高帧率关闭
町中模式：旧版

'''

def task_getComputerName():
    return socket.gethostname()

def task_acceptTask():
    while True:
        if waitFindImg_withBool(public_img.xiezhu, 0.1, 4) == True:
            waitClickImg_withBool(public_img.accept, 0.4, 0.5)


def init():
    global _imported
    if not _imported:
        acceptTask = threading.Thread(target=task_acceptTask)
        acceptTask.daemon = True
        if acceptTask.is_alive() == False:
            acceptTask.start()
            _imported = True

class basic_operate:
    @staticmethod
    def find_place():
        if waitFindImg_withBool(place_img.search, 0.4, 0):
            return PLACE.SEARCH
        if waitFindImg_withBool(place_img.Town, 0.4, 0):
            return PLACE.TOWN
        if waitFindImg_withBool(place_img.outside, 0.4, 0):
            return PLACE.OUTSIDE
        return PLACE.NONE
    @staticmethod
    def do_back():
        ret = False
        ret |= waitClickImg_noWait_withBool(place_img.back1, 0.6, 0)
        ret |= waitClickImg_noWait_withBool(place_img.back2, 0.6, 0)
        ret |= waitClickImg_noWait_withBool(place_img.close, 0.6, 0)
        ret |= waitClickImg_noWait_withBool(place_img.enter, 0.6, 0)
    
    @staticmethod
    def do_fight(fightBeginWait = 10):
        if fightBeginWait > 0:
            if waitClickImg_withBool(public_img.fight_begin, fightBeginWait, 1) == False:
                return False
            waitClickImg_withBool(public_img.fight_begin, 2, 5)
        if waitClickImg_noWait_withBool([public_img.fight_fail,public_img.fight_fail2,public_img.fight_fail3,public_img.fight_success,public_img.fight_success2, public_img.miwen_success, public_img.guiwang_success],180,1) == False:
            return False
        
        waitClickImg_noWait_withBool([public_img.fight_fail,public_img.fight_fail2,public_img.fight_fail3,public_img.fight_success,public_img.fight_success2, public_img.miwen_success, public_img.guiwang_success],1,1) 
        return True

def task_return_game():
    tryTimes = 3
    while tryTimes > 0:
        if False == waitFindImg_withBool([place_img.title, place_img.title2], 1, 1):
            waitClickImg_noWait([place_img.ico, place_img.ico2], 1, 0)
            myTimeSleep_big()
            tryTimes -= 1
            if tryTimes == 0:
                return False
        else:
            break

def task_goto_place(place : PLACE):
    task_return_game()
    cur_place = basic_operate.find_place() #当前位置
    dstMsg = "From " + cur_place.name + " to " + place.name
    if cur_place == place:
        if place == PLACE.TOWN and waitFindImg_withBool(zudui_img.zudui, 1, 1) == False:
            waitClickImg_noWait_withBool([place_img.juanzhou,place_img.juanzhou2], 1, 1)
        return True

    #try back to Town
    try_times = 5
    while try_times > 0 and PLACE.NONE == cur_place:
        basic_operate.do_back()
        cur_place = basic_operate.find_place()
        try_times -= 1

    if cur_place == PLACE.SEARCH:
        basic_operate.do_back()
    elif cur_place == PLACE.OUTSIDE:
        waitClickImg(place_img.outside, 1, 1)

    #cur in town, go to dst
    if waitFindImg_withBool(zudui_img.zudui, 1, 1) == False:
        waitClickImg_noWait_withBool([place_img.juanzhou,place_img.juanzhou2], 1, 1)
    if place == PLACE.SEARCH:
        waitClickImg(place_img.Town, 1, 1)
    elif place == PLACE.OUTSIDE:
        waitClickImg(place_img.goOutside, 1, 1)
    myTimeSleep_big()
    return place == basic_operate.find_place()

def task_save_compress_pic():
    # 截取屏幕截图
    screenshot = pyautogui.screenshot()
    compressed_data = compress_image(screenshot)

    # 保存压缩后的图像到文件
    with open('compressed_screenshot.jpg', 'wb') as f:
        f.write(compressed_data)

def task_close_game():
    task_return_game()
    if waitClickImg_withBool(gameStart_img.close, 5, 1):
        myTimeSleep(10)

    subprocess.call(f"taskkill /f /im MuMuPlayer.exe")
    subprocess.call(f"taskkill /f /im MuMuVMMHeadless.exe")
    subprocess.call(f"taskkill /f /im MuMuVMMSVC.exe")
    myTimeSleep_big()

def task_start_game():
    isSuccess = False
    path1 = R'C:\\Program Files\\Netease\\MuMuPlayer-12.0\\shell\\MuMuPlayer.exe'
    path2 = R'C:\Program Files\Netease\MuMu Player 12\shell\MuMuPlayer.exe'
    if os.path.exists(path1):
        subprocess.Popen(path1)
    elif os.path.exists(path2):
        subprocess.Popen(path2)
    if waitClickImg_withBool(gameStart_img.ico, 100, 20) == False:
        return False
    waitFindImg_withBool(gameStart_img.gameIn, 100, 10)
    while waitFindImg_withBool(gameStart_img.gameIn, 5, 10) == False:
        x1, y1 = get_yys_random_point((120, 120, 120, 120))
        pcacc_mouse.click(x1, y1)

    myTimeSleep(10)
    while waitFindImg_withBool(place_img.Town, 5, 5) == False:
        x1, y1 = get_yys_random_point(gameStart_img.enterGame)
        pcacc_mouse.click(x1, y1)
        isSuccess = True
    myTimeSleep_big()

    return isSuccess

class yys_task:
    def __init__(self, name):
        self.name = name

    def run(self):
        print(f"Running task: {self.name}")

def task_daoguan():
    waitClickImg_withBool(public_img.fight_begin, 3, 0)

class task_yeyuanhuo(yys_task):
    def __init__(self):
        super().__init__(f"打业原火XXX100次")
    def run(self):
        tryTimes = 100
        while tryTimes > 0:
            tryTimes -= 1
            waitClickImg_withBool([public_img.tiaozhan,public_img.tiaozhan2,public_img.tiaozhan3,public_img.tiaozhan4, public_img.tiaozhan5, public_img.tiaozhan6, public_img.tiaozhan7, public_img.tiaozhan8, public_img.tiaozhan8,public_img.guiwang
                                , public_img.guiwangFight], 10, 0)
            basic_operate.do_fight()

class task_zhaohuan(yys_task):
    def __init__(self):
        super().__init__(f"召唤100次")
    def run(self):
        tryTimes = 100
        while tryTimes > 0:
            tryTimes = tryTimes - 1
            waitClickImg_withBool(special_img.zhaohuan, 1, 3)

class task_chaoguiwang(yys_task):
    def __init__(self):
        super().__init__(f"打超鬼王4次")
    def run(self):
        tryTimes = 4
        while tryTimes > 0:
            '''
            if True == waitClickImg_noWait_withBool(chaoguiwang_img.xiaohao, 2, 0):
                myTimeSleep_big()
                waitClickImg_withBool(public_img.guiwang, 10, 0)
                myTimeSleep_big()
                waitClickImg_noWait(chaoguiwang_img.jijie, 3, 0)
                myTimeSleep_big()
                waitClickImg_noWait(chaoguiwang_img.kongbai, 2, 0)
                myTimeSleep_big()
                waitClickImg_noWait(zudui_img.invite, 5, 1)
                myTimeSleep_big()
                waitClickImg_noWait(chaoguiwang_img.main, 10, 0)
                myTimeSleep(60)
            '''
            task_goto_place(PLACE.TOWN)
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.first, 2, 0)
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.second, 2, 0)
            myTimeSleep_big()
            #waitClickImg(chaoguiwang_img.monster, 2, 0)
            #myTimeSleep_big()
            waitClickImg(public_img.guiwang, 2, 0)
            myTimeSleep_big()
            curTime = 3
            while curTime > 0:
                curTime = curTime - 1
                waitClickImg_noWait(chaoguiwang_img.normal, 1, 1)
                if False == waitClickImg_withBool(public_img.guiwangFight, 10, 0):
                    break
                basic_operate.do_fight()
                myTimeSleep(20)
            tryTimes = tryTimes - 1
        
        return True
    
class task_xiaohaochaoguiwang(yys_task):
    def __init__(self):
        super().__init__(f"小号打超鬼王10次")
    def run(self):
        while True:
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.xiaohao, 2, 0)
            myTimeSleep_big()
            waitClickImg_withBool(public_img.guiwang, 10, 0)
            myTimeSleep_big()
            waitClickImg_noWait(chaoguiwang_img.jijie, 3, 0)
            myTimeSleep_big()
            waitClickImg_noWait(chaoguiwang_img.kongbai, 2, 0)
            myTimeSleep_big()
            waitClickImg_noWait(zudui_img.invite, 5, 1)
            myTimeSleep(60)
            waitClickImg_noWait(chaoguiwang_img.main, 10, 0)

            task_goto_place(PLACE.TOWN)
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.first, 2, 0)
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.second, 2, 0)
            myTimeSleep_big()
            waitClickImg(chaoguiwang_img.monster, 2, 2)

            while True:
                task_goto_place(PLACE.TOWN)
                myTimeSleep_big()
                waitClickImg(chaoguiwang_img.first, 2, 0)
                myTimeSleep_big()
                waitClickImg(chaoguiwang_img.second, 2, 0)
                myTimeSleep_big()
                if False == waitClickImg(chaoguiwang_img.monster, 2, 2):
                    break
                while True:
                    if False == waitClickImg_withBool(public_img.guiwangFight, 10, 0):
                        break
                    basic_operate.do_fight()
                    myTimeSleep(20)
        
        return True

class task_tansuo(yys_task):
    def __init__(self, num, easy=False):
        super().__init__(f"探索第{num}章")
        self.num = num
        self.easy = easy
    def run(self):
        task_goto_place(PLACE.SEARCH)
        #滑动到第一章
        template = tansuo_img.zhangjie
        num_sel = template.format(self.num)

        if waitClickImg_withBool(num_sel,1,1) == False:#一般使最后一章，先尝试查找
            if waitClickImg_withBool(tansuo_img.tansuo,2,1) == False:#正常打完在再次探索页面
                if self.num < 20:
                    max_tryTime = 10
                    while max_tryTime > 0 and waitFindImg_withBool(template.format(1),0.4,1) == False:
                        yys_dragAuto(tansuo_img.select_drag_up)
                        max_tryTime -=1
                max_tryTime = 10
                while max_tryTime > 0 and waitClickImg_withBool(num_sel,0.4,1) == False:
                    yys_dragAuto(tansuo_img.select_drag_down)
                    max_tryTime -=1
                
                #随意，不影响结果
                if self.easy == True:
                    waitClickImg_withBool(tansuo_img.easy,0.4,1)
                else:
                    waitClickImg_withBool(tansuo_img.kunnan,0.4,1)


        if waitClickImg_withBool(tansuo_img.tansuo,2,1) == False:
            
            task_goto_place(PLACE.SEARCH)
        #滑动到第一章
            template = tansuo_img.zhangjie
            num_sel = template.format(self.num)
            
            end = [1083+(random.randint(0,30)),600+(random.randint(0,30))]
            start  = [1077+(random.randint(0,30)),304+(random.randint(0,30))]
            if waitClickImg_withBool(tansuo_img.tansuo,2,1) == False:#正常打完在再次探索页面
                max_tryTime = 10
                while max_tryTime > 0 and waitFindImg_withBool(template.format(1),0.4,1) == False:
                    yys_dragAuto(tansuo_img.select_drag_up)
                    max_tryTime -=1
                max_tryTime = 10
                while max_tryTime > 0 and waitClickImg_withBool(num_sel,0.4,1) == False:
                    yys_dragAuto(tansuo_img.select_drag_down)
                    max_tryTime -=1
                
                #随意，不影响结果
                if self.easy == True:
                    waitClickImg_withBool(tansuo_img.easy,0.4,1)
                else:
                    waitClickImg_withBool(tansuo_img.kunnan,0.4,1)

                if waitClickImg_withBool(tansuo_img.tansuo,2,1) == False:
                    return False
        
        
        drag_times = 30
        while  drag_times > 0 and waitClickImg_withBool([tansuo_img.boss, tansuo_img.boss2, tansuo_img.boss3], 0.4, 0.4) == False:
            if waitClickImg_withBool(tansuo_img.xiaoguai, 1, 1):
                if waitFindImg_withBool(tansuo_img.backIco, 1, 1):
                    drag_times = 30
                    continue
                basic_operate.do_fight(0)
                waitFindImg(tansuo_img.backIco, 10, 1)
            else:
                yys_dragAuto(tansuo_img.tansuo_drag)
                drag_times-=1
            if drag_times  == 0:
                print("拖动到没有小怪的地方了")
                return False
            
        basic_operate.do_fight(0)
        waitFindImg(tansuo_img.backIco, 10, 1)

        #寻找小纸人宝箱
        while waitClickImg_withBool(tansuo_img.box, 3 ,1) == True:
            ret,pos = waitFindImg(tansuo_img.box_get, 3, 1)
            if ret:
                pcacc_mouse.click(pos[0]+random.randint(150,300),pos[1]-random.randint(100,120))
                if waitFindImg_withBool(tansuo_img.box_get, 1, 1):
                    pcacc_mouse.click(pos[0]+random.randint(150,300),pos[1]-random.randint(100,120))


        if waitClickImg_withBool([tansuo_img.big_box,tansuo_img.big_box2,tansuo_img.big_box3],3,0) == True:
            if waitClickImg_withBool(tansuo_img.big_box_get,2,1) == False:
                return False
        return True

class task_pata(yys_task):
    def __init__(self):
        super().__init__("爬塔")
    def run(self):
        waitClickImg(special_img.tiaozhan, 10, 1)
        basic_operate.do_fight(0)

class task_topo(yys_task):
    def __init__(self, retryTimes, person = True):
        if person:
            super().__init__("个人突破")
        else:
            super().__init__("阴阳寮突破")
        self.retryTimes = retryTimes
        self.person = person
    def run(self):
        while self.retryTimes:
            self.retryTimes = self.retryTimes - 1
            task_goto_place(PLACE.SEARCH)
            fail_time = 0
            fight_time = 0
            if waitClickImg_withBool(topo_img.topo,2,1) == False:
                return False
            if self.person == False:
                waitClickImg_withBool(topo_img.liaotopo, 2, 1)
            
            for i in range(5, -1, -1):
                myTimeSleep_big()
                star = topo_img.star
                sel = star.format(i)
                positions =list(pyautogui.locateAllOnScreen(sel, confidence=0.85))
                for position in positions:
                    #pyautogui.screenshot(imageFilename='yys_tmp.png', region=position)
                    region = (position[0] - 30,position[1]-100,280,150)
                    #pyautogui.screenshot(imageFilename='yys2.png', region=region)
                    myTimeSleep_big()
                    ret = pcacc_img.find_img_in_area(topo_img.fail, region)
                    ret2 = pcacc_img.find_img_in_area(topo_img.fail2, region)
                    ret3 = pcacc_img.find_img_in_area(topo_img.fail3, region)
                    print(f'find {sel}, {position}, {ret}, {ret2}, {ret3}')
                    if pcacc_img.find_img_in_area(sel, region) == False:
                        continue

                    if  ret == False and ret2 == False and ret3 == False:
                        click_pos = pcacc_img.choose_one_point_from_position(position)
                        star_tryTimes = 3
                        
                        #点击star位置
                        while star_tryTimes>0 and  waitFindImg_withBool(topo_img.fight,2,1) == False:
                            pcacc_mouse.click(click_pos[0], click_pos[1])
                            star_tryTimes-=1
                            myTimeSleep_small()
        
                        fight_tryTimes = 3
                        while fight_tryTimes>0 and waitFindImg_withBool(topo_img.fight,2,1) == True:
                            if waitClickImg_withBool(topo_img.fight,2,1) == False:
                                return False
                            fight_tryTimes-=1
                            myTimeSleep_small()
                            if fight_tryTimes == 0:
                                return False

                            
                        basic_operate.do_fight()
                        if waitClickImg_withBool(tansuo_img.big_box_get,2,1) == True:
                            print("tupo宝箱获取")
                        waitFindImg(topo_img.tupo_title, 10, 2)
                        myTimeSleep_small()
                        if waitFindImg_withBool(topo_img.box3, 1, 0) == True:
                            break
                        fight_time+=1
                #打满5次后刷新
                if fight_time == 6 or waitFindImg_withBool([topo_img.box3,topo_img.box4], 1, 0) == True:
                    if waitClickImg_withBool(topo_img.refresh,2,1) == True:
                        waitClickImg_noWait_withBool(topo_img.button_ok,1,1)
                        fight_time = 0
                        time.sleep(1)
                        break
            if waitClickImg_withBool(topo_img.refresh,2,1) == True:
                if waitClickImg_noWait_withBool(topo_img.button_ok,1,1) == False:
                    return False
        return True
    
class task_jiyang(yys_task):
    def __init__(self):
        super().__init__(f"结界寄养")
    def run(self):
        task_goto_place(PLACE.TOWN)
        if waitClickImg_withBool(yyl_img.head, 2, 1) == False:
            return False
        if waitClickImg_withBool(yyl_img.jiejie, 2, 1) == False:
            return False
        if waitClickImg_withBool(yyl_img.shishenGroup, 5, 3) == False:
            return False
        if waitClickImg_noWait_withBool(yyl_img.add_shishen, 5, 3) == False:
            return False
        if waitClickImg_withBool(yyl_img.enter_jiejie, 5, 3) == False:
            return False
        if waitFindImg_withBool(yyl_img.All_shishen, 5, 3) == False:
            return False
        while waitClickImg_withBool(yyl_img.enter, 1, 0.5) == False:
            ret, pos = waitFindImg(yyl_img.All_shishen, 2, 0.5)
            if ret == True:
                pcacc_mouse.click(pos[0] + 150, pos[1] - 90)
        return True

class task_AddPerson(yys_task):
    def __init__(self, refreshTimes):
        super().__init__(f"阴阳寮加人{refreshTimes}次")
        self.refreshTimes = refreshTimes
    def run(self):
        task_goto_place(PLACE.TOWN)
        if waitClickImg_withBool(yyl_img.head, 2, 1) == False:
            return False
        if waitClickImg_withBool(yyl_img.liaoInfo, 2, 1) == False:
            return False
        if waitClickImg_withBool(yyl_img.manage, 2, 1) == False:
            return False
        retryTimes = 3
        while retryTimes > 0 and waitClickImg_noWait_withBool(yyl_img.manageBtn, 2, 1):
            if waitClickImg_withBool(yyl_img.addPeople, 2, 1):
                break
            else:
                retryTimes -= 1
            if retryTimes == 0:
                return False
        
        while self.refreshTimes > 0:
            if waitClickImg_noWait_withBool(yyl_img.add, 1, 0.4) == False:
                waitClickImg_noWait_withBool(yyl_img.refreshBtn, 1, 0.5)
                self.refreshTimes -= 1
        return True

class task_fightzuidui(yys_task):
    def __init__(self):
        super().__init__(f"组队,100s超时")
    def run(self):
        task_goto_place(PLACE.TOWN)
        retryTimes = 40
        while True:
            if retryTimes <= 0:
                break
            retryTimes -= 1
            if waitFindImg_withBool([zudui_img.qiuqiu, zudui_img.pcacc_mini], 2, 0.5) == False:
                continue
            if waitClickImg_withBool(zudui_img.accept, 5, 0.5) == False:
                continue
            waitClickImg_withBool(zudui_img.accept, 2, 0.5)
            waitClickImg_withBool(zudui_img.accept, 2, 0.5)#防止没点到
            basic_operate.do_fight(60)
            retryTimes = 40

class task_yuhun(yys_task):
    def __init__(self):
        super().__init__(f"御魂100次")
    def run(self):
        task_goto_place(PLACE.TOWN)

        tryTimes = 100
        if waitClickImg_withBool(zudui_img.zudui, 2, 1) == False:
            return False
        if waitFindImg_withBool(zudui_img.createTeam, 2, 1) == False:
            return False
        #已经进入页面
        
        while waitClickImg_noWait_withBool(zudui_img.yuhun, 2, 1) == False:
            yys_dragAuto(zudui_img.up_drag_begin)
        while waitClickImg_noWait_withBool(zudui_img.ten, 1, 1) == False:
            yys_dragAuto(zudui_img.mid_drag)
        
        if waitClickImg_withBool(zudui_img.createTeam, 5, 1) == False:
            return False
        waitClickImg_withBool(zudui_img.not_pubulic, 5, 1)
        if waitClickImg_withBool(zudui_img.create, 5, 1) == False:
            return False
        
        while tryTimes > 0:
            tryTimes -= 1
            while waitFindImg_withBool(zudui_img.pcacc2, 1, 0.5) == False:
                if waitClickImg_noWait_withBool(zudui_img.AddPerson, 5, 1) == False:
                    return False
                if waitClickImg_noWait_withBool(zudui_img.pcacc, 5, 1) == False:
                    return False
                if waitClickImg_withBool(zudui_img.invite, 5, 1) == False:
                    return False
            if waitClickImg_withBool(zudui_img.attack, 10, 1) == False:
                return False
            basic_operate.do_fight(20)
            if waitClickImg_withBool(zudui_img.enter, 10, 1) == False:
                return False
            
class task_fightYaoqi(yys_task):
    def __init__(self, type : YAOQI):
        super().__init__(f"妖气封印{type}")
        self.type = type
    def run(self):
        dstImg = None
        if self.type == YAOQI.GUISHIHEI:
            dstImg = zudui_img.guishihei
        elif self.type == YAOQI.RIHEFANG:
            dstImg = zudui_img.rihefang

        task_goto_place(PLACE.TOWN)
        if waitClickImg_withBool(zudui_img.zudui, 2, 1) == False:
            return False

        #if waitFindImg_withBool(zudui_img.createTeam, 2, 1) == False:
        #    return False
        
        if waitFindImg_withBool(zudui_img.AutoPair, 1, 1) == False: #如果没找到自动匹配，意味着需要重新拉取
            while waitClickImg_noWait_withBool(zudui_img.fengyin, 1, 1) == False:
                yys_dragAuto(zudui_img.left_drag_begin)
            
            while waitClickImg_noWait_withBool(dstImg, 1, 1) == False:
                yys_dragAuto(zudui_img.mid_drag)
        
        if waitClickImg_withBool(zudui_img.AutoPair, 2, 1) == False:
            return False
        
        return basic_operate.do_fight(300)

class task_douji(yys_task):
    def __init__(self, tryTimes):
        super().__init__(f"斗技{tryTimes}次")
        self.tryTimes = tryTimes
    def run(self):
        task_goto_place(PLACE.OUTSIDE)
        if waitClickImg_withBool(douji_img.douji, 10, 5) == False:
                return False
        while self.tryTimes > 0:
            if waitClickImg_withBool([douji_img.fight,douji_img.fight2], 10, 5) == False:
                return False
            if waitClickImg_withBool([public_img.fight_begin,douji_img.AutoGo], 20, 5) == False:
                return False
            myTimeSleep_big()
            waitClickImg_withBool([douji_img.AutoGo,douji_img.shoudong], 10, 5)
            
            while waitClickImg_withBool([public_img.fight_fail, douji_img.success], 10, 1) == False:
                ret,pos = waitFindImg(douji_img.shuju, 1, 0)
                if ret:
                    pcacc_mouse.click(pos[0] - 100, pos[1] - 100)
                    myTimeSleep_small()

            self.tryTimes -=1
        return True

class task_baigui(yys_task):
    def __init__(self):
        super().__init__("百鬼夜行40次")
    def run(self):
        task_goto_place(PLACE.OUTSIDE)
        if waitClickImg_withBool(baigui_img.head, 10, 5) == False:
            return False
        tryTimes = 40
        while tryTimes > 0:
            tryTimes -= 1

            waitClickImg_noWait_withBool(baigui_img.invite, 4, 1)
            waitClickImg_withBool(baigui_img.friend, 4, 1)

            if waitClickImg_withBool(baigui_img.enter, 10, 2) == False:
                return False
            
            myTimeSleep_big()
            pointArr = []
            pointArr.append(get_yys_random_point(baigui_img.left))
            pointArr.append(get_yys_random_point(baigui_img.mid))
            pointArr.append(get_yys_random_point(baigui_img.right))

            random.shuffle(pointArr)
            for point in pointArr:
                pcacc_mouse.click(point[0], point[1])
                myTimeSleep_small()
            
            if waitClickImg_withBool(baigui_img.begin, 3, 1) == False:
                return False
            
            myTimeSleep_big()
            ret, position = find_yys_pos()
            while waitFindImg_withBool([baigui_img.end, baigui_img.invite], 0.1, 0) == False:
                pointArr = []
                ret, pos = pcacc_img.find_imgs(baigui_img.pic1)
                if ret == False:
                    pointArr.append((baigui_img.pos1, baigui_img.pic1))
                ret, pos = pcacc_img.find_imgs(baigui_img.pic2)
                if ret == False:
                    pointArr.append((baigui_img.pos2, baigui_img.pic2))
                ret, pos = pcacc_img.find_imgs(baigui_img.pic3)
                if ret == False:
                    pointArr.append((baigui_img.pos3, baigui_img.pic3))
                ret, pos = pcacc_img.find_imgs(baigui_img.pic4)
                if ret == False:
                    pointArr.append((baigui_img.pos4, baigui_img.pic4))
                random.shuffle(pointArr)
                for point in pointArr:
                    dst = (point[0][0] + random.randint(-10, 10) + position[0], point[0][1] + random.randint(-10, 10) + position[1])
                    
                    while True:
                        ret, pos = pcacc_img.find_imgs(place_img.back2)
                        if ret:
                            pcacc_mouse.quickclick(dst[0], dst[1])
                            ret, pos = pcacc_img.find_imgs(point[1])
                            if ret == False:
                                break
                            pcacc_mouse.quickclick(dst[0], dst[1])
                        else:
                            break
            
            waitClickImg_withBool(baigui_img.end, 3, 1)



if __name__ == '__main__':
    # 移动鼠标
    #computer_name = task_getComputerName()
    #print(f"Computer Name: {computer_name}")
    myTimeSleep_big()
    #task_xiaohaochaoguiwang().run()
    task_zhaohuan().run()
    task_yeyuanhuo().run()
    
    while True:
        task_fightYaoqi(YAOQI.RIHEFANG).run()
    task_baigui().run()
    
    tmpRet, tmpPos = find_window_pos('Mumu模拟器12')
    pyautogui.screenshot(imageFilename='yys.png', region=tmpPos)
    #print(task_goto_place(PLACE.OUTSIDE))
    
    
    




