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

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 org.opencv.core.Point;

import java.awt.*;

/**
 * 琦玉任务
 */
@SceneAnnotation("SceneMain")
public class SceneMain_Qiyu extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 9.0f;
    }

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

    private static String PathFinish = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\enter.png";
    private static String PathBigbox = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\bigbox.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());
                continue;
            }

            if (checkHas(PathBigbox, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathBigbox, AiManage.getInstance().getCheckPoint(),new Point(0,20));
                ThreadUtil.sleep(5000);
                java.awt.Point lastClickPoint = AiManage.getInstance().getLastClickPoint();
                lastClickPoint.setLocation(lastClickPoint.x+300,lastClickPoint.y+200);
                randomToClick();
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        if (checkHas(PathFinish, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathFinish, AiManage.getInstance().getCheckPoint());
        }
        if (checkHas(PathBigbox, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathBigbox, AiManage.getInstance().getCheckPoint(),new Point(0,20));
            ThreadUtil.sleep(3000);
            randomToClick();
        }
    }

    @Override
    public boolean isDone() {
        return hasChildDone();
    }

}
