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

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 com.sencorsta.rabs.util.ResettableData;
import org.opencv.core.Point;

import java.awt.AWTException;

/**
 * 纹章试炼
 */
@SceneAnnotation("SceneMain")
public class SceneMain_Emblem extends BaseScene implements Scene {
    @Override
    public float getPriority() {
        return 1.9f;
    }

    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\back.png";
    private static String PathEnter1 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\enter1.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\enter2.png";
    private static String PathEnter3 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\enter3.png";
    private static String PathEnter4 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\enter4.png";
    private static String PathEnter5 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\enter5.png";
    private static String PathPick1 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\pick1.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\start.png";
    private static String PathStart2 = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\start2.png";
    private static String PathSkip = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\skip.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\over.png";
    private static String PathChoose = System.getProperty("user.dir") + "\\opencv\\scene\\tactic\\emblem\\choese.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(PathEnter1, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter1, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathEnter3, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter3, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathEnter4, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter4, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathEnter4, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter4, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathPick1, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathPick1, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathChoose, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathChoose, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathEnter5, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter5, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }

        }
    }

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

    int maxTimes = 4;

    @Override
    public void think() throws AWTException {
        int count = getRecord().getData().getCount();
        for (int i = count; i < maxTimes; i++) {
            while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
                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);
                }

                if (checkHas(PathSkip, AiManage.getInstance().getCheckPoint())) {
                    moveToClick(PathSkip, AiManage.getInstance().getCheckPoint());
                    ThreadUtil.sleep(2000);
                }
            }
            randomToClick();
            ThreadUtil.sleep(2000);
            count++;
        }

        //领奖
        moveToClick(PathCheck, AiManage.getInstance().getCheckPoint(), new Point(0, 360));
        ThreadUtil.sleep(2000);
        randomToClick();
        ThreadUtil.sleep(2000);

        moveToClick(PathCheck, AiManage.getInstance().getCheckPoint(), new Point(0, 295));
        ThreadUtil.sleep(2000);
        randomToClick();
        ThreadUtil.sleep(2000);

        moveToClick(PathCheck, AiManage.getInstance().getCheckPoint(), new Point(0, 228));
        ThreadUtil.sleep(2000);
        randomToClick();
        ThreadUtil.sleep(2000);

        moveToClick(PathCheck, AiManage.getInstance().getCheckPoint(), new Point(0, 162));
        ThreadUtil.sleep(2000);
        randomToClick();
        ThreadUtil.sleep(2000);

        moveToClick(PathCheck, AiManage.getInstance().getCheckPoint(), new Point(0, 90));
        ThreadUtil.sleep(2000);
        randomToClick();
        ThreadUtil.sleep(2000);

        getRecord().getData().setCount(count);

    }

    @Override
    public boolean isDone() {
        return getRecord().getData().getCount() >= maxTimes;
    }


    /**
     * 重置
     */
    @Override
    public ResettableData.ResetType getType(){
        return ResettableData.ResetType.WEEKLY1_4;
    }

}
