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

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
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;
import java.util.Calendar;

/**
 * 对决赛
 */
@SceneAnnotation("SceneMain_Fight")
public class SceneMain_Fight_VS extends BaseScene implements Scene {
    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\back.png";



    private static String PathReword = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\reword.png";
    private static String PathReword2 = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\reword2.png";
    private static String PathGoldOver = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\goldOver.png";
    private static String PathDimonOver = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\dimonOver.png";
    private static String PathShow = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\show.png";
    private static String PathShowStart = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\showStart.png";
    private static String PathShowNext = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\showNext.png";
    private static String PathShowHero = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\showHero.png";
    private static String PathShowEvil = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\vs\\showEvil.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())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(6000);

                if (checkHas(PathShow, AiManage.getInstance().getCheckPoint())) {
                    moveToClick(PathShowStart, AiManage.getInstance().getCheckPoint());
                    ThreadUtil.sleep(3000);
                    moveToClick(PathShowNext, AiManage.getInstance().getCheckPoint());
                    ThreadUtil.sleep(3000);
                    moveToClick(PathShowHero, AiManage.getInstance().getCheckPoint(),new Point(-40,125));
                    ThreadUtil.sleep(3000);
                    randomToClick();
                    ThreadUtil.sleep(3000);
                    moveToClick(PathShowEvil, AiManage.getInstance().getCheckPoint(),new Point(50,125));
                    ThreadUtil.sleep(3000);
                    randomToClick();
                    ThreadUtil.sleep(3000);
                }
            }



        }
    }

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

    @Override
    public void think() throws AWTException {
        if (checkHas(PathReword, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathReword, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);

            moveToClick(PathReword2, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        if (checkHas(PathGoldOver, AiManage.getInstance().getCheckPoint()) && checkHas(PathDimonOver, AiManage.getInstance().getCheckPoint())) {
            getRecord().getData().setDone(true);
        }
    }


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

    /**
     * 是否开启
     */
    @Override
    public boolean isOpen() {
        int weekDay = DateUtil.dayOfWeek(DateUtil.date());
        if (weekDay == Calendar.SATURDAY||weekDay == Calendar.SUNDAY) {
            return false;
        }
        return true;
    }

}
