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

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.*;

/**
 * 探索-王者挑战-地狱难度
 */
@SceneAnnotation("SceneMain_Explore_King")
public class SceneMain_Explore_King_hell extends BaseScene implements Scene {

    @JsonIgnore
    @Override
    public float getPriority() {
        return 1.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\enter.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\enter2.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\back.png";

    private static String PathFight = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\fight.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\start.png";
    private static String PathClose = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\close.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\hell\\over.png";

    private int maxCount = 9;

    @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);
            }
            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter2, 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(PathFight, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

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

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

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

}
