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

import cn.hutool.core.thread.ThreadUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
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_Endless")
public class SceneMain_Fight_Endless_Quick extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 2.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\back.png";

    private static String PathMax = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\max.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\start.png";
    private static String PathOk = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\quick\\ok.png";
    private int maxCount = 20;
    ;

    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
        int count = getRecord().getData().getCount();
        if (count < maxCount) {
            isTempDone = false;
        }
    }

    @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());
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        int count = getRecord().getData().getCount();
        if (count < maxCount) {
            while (AiManage.getInstance().isRunning() && !checkHas(PathStart, AiManage.getInstance().getCheckPoint())) {
                ThreadUtil.sleep(2000);
            }
            moveToClick(PathMax, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            int tempCount = 0;
            while (AiManage.getInstance().isRunning() && !checkHas(PathOk, AiManage.getInstance().getCheckPoint()) && tempCount < 30) {
                ThreadUtil.sleep(2000);
                tempCount++;
            }
            if (tempCount < 30) {
                getRecord().getData().setCount(count + 10);
            }else {
                getRecord().getData().setCount(count + 1);
            }
        }
        isTempDone = true;
    }


    @Override
    public boolean isDone() {
        if (getRecord().getData().getCount() >= maxCount) {
            return true;
        }
        return isTempDone;
    }

}
