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

import java.awt.AWTException;

/**
 * 竞技界面
 */
@SceneAnnotation("SceneMain")
public class SceneMain_Fight extends BaseScene implements Scene {
    @Override
    public float getPriority() {
        return 2.0f;
    }

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

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\enter.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\enter2.png";
    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\rightDoor.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\goLeft.png";
    private static String PathGoRight = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\goRight.png";

    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
        System.out.println("点击退出竞技界面");
    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                System.out.println("发现游戏竞技界面...");
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                System.out.println("点击竞技界面");
                continue;
            }
            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
                System.out.println("发现游戏竞技界面(夜晚)...");
                moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint());
                System.out.println("点击竞技界面(夜晚)");
                continue;
            }
            if (checkHas(PathRightdoor, AiManage.getInstance().getCheckPoint())) {
                System.out.println("发现右边的门...");
                moveToClick(PathGoLeft, AiManage.getInstance().getCheckPoint(), new Point(0, -50));
                System.out.println("往左边走一步");
                ThreadUtil.sleep(6000);
            } else {
                moveToClick(PathGoRight, AiManage.getInstance().getCheckPoint(), new Point(0, -50));
                System.out.println("往右边走一步");
                ThreadUtil.sleep(6000);
            }
        }
    }

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

    @Override
    public void think() {
    }

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

}
