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

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_Family")
public class SceneMain_Family_Info extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 2f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\back.png";
    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\rightDoor.png";
    private static String PathRightdoor2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\rightDoor2.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\goLeft.png";
    private static String PathReward1 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\reward1.png";
    private static String PathReward2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\reward2.png";
    private static String PathReward3 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\info\\reward3.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(5000);
                continue;
            }

            if (checkHas(PathRightdoor, AiManage.getInstance().getCheckPoint())||checkHas(PathRightdoor2, AiManage.getInstance().getCheckPoint())) {
                System.out.println("发现右边的门...");
                moveToClick(PathGoLeft, AiManage.getInstance().getCheckPoint(), new Point(-100, -70));
                System.out.println("往左边走一步");
                ThreadUtil.sleep(5000);
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        if (checkHas(PathReward1, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathReward1, AiManage.getInstance().getCheckPoint(),new Point(0,-50));
            ThreadUtil.sleep(2000);
            randomToClick();
        }else if (checkHas(PathReward2, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathReward2, AiManage.getInstance().getCheckPoint(),new Point(0,-50));
            ThreadUtil.sleep(2000);
            randomToClick();
        }else if (checkHas(PathReward3, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathReward3, AiManage.getInstance().getCheckPoint(),new Point(0,-50));
            ThreadUtil.sleep(2000);
            randomToClick();
        }
        getRecord().getData().setDone(true);
    }

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

}
