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

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_Challenge")
public class SceneMain_Challenge_Extreme extends BaseScene implements Scene {
    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\back.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\start.png";
    private static String PathStart2 = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\start2.png";
    private static String PathJoin = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\join.png";
    private static String PathCreate = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\create.png";
    private static String PathSkip = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\skip.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\over.png";
    private static String PathOb = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\ob.png";
    private static String PathOk = System.getProperty("user.dir") + "\\opencv\\scene\\challenge\\extreme\\ok.png";


    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        ThreadUtil.sleep(2000);
        moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        //尝试加入别人的队伍
        moveToClick(PathJoin, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(6000);
        if (checkHas(PathJoin,AiManage.getInstance().getCheckPoint())){
            //如果还在此界面 点击创建
            moveToClick(PathCreate, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        moveToClick(PathStart2, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(6000);

        moveToClick(PathStart2, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);

        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathSkip, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathSkip, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            ThreadUtil.sleep(1000);
        }

        randomToClick();
        ThreadUtil.sleep(3000);

        randomToClick();
        ThreadUtil.sleep(3000);

        randomToClick();
        ThreadUtil.sleep(6000);

        moveToClick(PathOb, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(4000);

        moveToClick(PathOk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        randomToClick();
        ThreadUtil.sleep(3000);

        getRecord().getData().setDone(true);
    }

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

}
