import time
from . import common
# 导入系统资源模块
from ascript.android.system import R
# 导入图色检索模块
from ascript.android.screen import FindImages

from ascript.android.screen import FindColors

pngs = ["押送普通","确定"]
def yabiaorenwu():
    while True:

        if common.isfire():
            print("----------战斗中----------")
            sleep(60)
            continue

        res_huodong = common.huodong()
        if res_huodong:
            print("打开活动")
            sleep(1)
            res_mjxy = common.zhaorenwu("押镖任务.png")
            if res_mjxy is not None:
                res_wancheng = common.zhaowancheng_text(res_mjxy)
                if res_wancheng is not None:
                    print("押镖任务完成,进行下一项")
                    common.closeAllbtn()
                    sleep(2)
                    return

                res_canjia = common.zhaocanjia_text(res_mjxy)
                if res_canjia is not None:
                    common.findandclick(res_canjia)
                    print("点击参加，押镖任务")
                    sleep(2)

                    res_btns = zhaobtn(pngs)
                    if res_btns is not None:
                        common.findandclick(res_btns)
                        sleep(2)

                    res_btns = zhaobtn(pngs)
                    if res_btns is not None:
                        common.findandclick(res_btns)
                        sleep(2)

        sleep(5)

def zhaobtn(pngs):
    # 找各种任务按钮
    images = [R.img(png + ".png") for png in pngs]
    return FindImages.find(images, rect=[172, 96, 1005, 714], confidence=0.95)

def sleep(num):
    time.sleep(num)
