package com.sencorsta.rabs.obj.ai.scene.fight;

import cn.hutool.core.thread.ThreadUtil;
import com.sencorsta.rabs.annotation.SceneAnnotation;
import com.sencorsta.rabs.obj.ai.AiManage;
import com.sencorsta.rabs.obj.ai.api.BaseScene;
import com.sencorsta.rabs.obj.ai.api.Scene;

import java.awt.AWTException;

/**
 * 对决赛-快速挑战
 */
@SceneAnnotation("SceneMain_Fight_VS")
public class SceneMain_Fight_VS_Quick extends BaseScene implements Scene {
    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\back.png";


    private static String PathLow = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\low.png";
    private static String PathMax = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\max.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\start.png";
    private static String PathStart_black = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\start_black.png";
    private static String PathOK = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\OK.png";
    private static String PathEvil = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\quick\\evil.png";


    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
        System.out.println("点击退出快速挑战");
    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                System.out.println("发现快速挑战...");
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                System.out.println("点击快速挑战");
                continue;
            }
        }
    }

    @Override
    public boolean check() throws AWTException {
        if (checkHas(PathCheck, AiManage.getInstance().getCheckPoint())) {
            return true;
        }
        return false;
    }

    @Override
    public void think() throws AWTException {
        if (!checkHas(PathStart_black, AiManage.getInstance().getCheckPoint())) {
            //先点一下最低分
            moveToClick(PathLow, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            //再点一下最大
            moveToClick(PathMax, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            //再点一下开始挑战
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            while (AiManage.getInstance().isRunning() && !checkHas(PathOK, AiManage.getInstance().getCheckPoint())) {
                ThreadUtil.sleep(2000);
            }
        }
        //切换到怪人
        moveToClick(PathEvil, AiManage.getInstance().getCheckPoint());
        if (!checkHas(PathStart_black, AiManage.getInstance().getCheckPoint())) {
            //先点一下最低分
            moveToClick(PathLow, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            //再点一下最大
            moveToClick(PathMax, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            //再点一下开始挑战
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            while (AiManage.getInstance().isRunning() && !checkHas(PathOK, AiManage.getInstance().getCheckPoint())) {
                ThreadUtil.sleep(2000);
            }
        }
        getRecord().getData().setDone(true);
    }


    @Override
    public boolean isDone() {
        return getRecord().getData().isDone();
    }

}
