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

/**
 * 组织-争霸
 */
@SceneAnnotation("SceneMain_Family")
public class SceneMain_Family_Battle extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 5f;
    }

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

    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\family\\battle\\start.png";
    private static String PathStart2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\battle\\start2.png";

    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\family\\battle\\rightDoor.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\family\\battle\\goLeft.png";
    private static String PathPaper = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\paper.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(PathPaper, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathPaper, AiManage.getInstance().getCheckPoint(), new Point(300, 0));
                ThreadUtil.sleep(2000);
            }

            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint(), new Point(-150, -35));
                ThreadUtil.sleep(5000);
                continue;
            }

            moveToClick(PathGoLeft, AiManage.getInstance().getCheckPoint(), new Point(430, -70));
            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(PathStart, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);

            if (checkHas(PathStart2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathStart2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            //TODO ice 补充逻辑
            getRecord().getData().setDone(true);
        } else {
            //今天没有比赛
            getRecord().getData().setDone(true);
        }
    }

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

}
