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

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_Role extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 3.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\role\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\role\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\role\\back.png";
    private static String PathBack2 = System.getProperty("user.dir") + "\\opencv\\scene\\role\\back2.png";
    private static String PathDropPoint = System.getProperty("user.dir") + "\\opencv\\scene\\role\\dropPoint.png";
    private static String PathLevel = System.getProperty("user.dir") + "\\opencv\\scene\\role\\level.png";
    private static String PathCanLvup = System.getProperty("user.dir") + "\\opencv\\scene\\role\\canLvup.png";
    private static String PathExp = System.getProperty("user.dir") + "\\opencv\\scene\\role\\exp.png";
    private static String PathQuick = System.getProperty("user.dir") + "\\opencv\\scene\\role\\quick.png";
    private static String PathTime3 = System.getProperty("user.dir") + "\\opencv\\scene\\role\\time3.png";
    private static String PathTime30 = System.getProperty("user.dir") + "\\opencv\\scene\\role\\time30.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\role\\over.png";
    private static String PathClose = System.getProperty("user.dir") + "\\opencv\\scene\\role\\close.png";
    private static String PathOb = System.getProperty("user.dir") + "\\opencv\\scene\\role\\ob.png";
    private static String PathSkill = System.getProperty("user.dir") + "\\opencv\\scene\\role\\skill.png";
    private static String PathSkillUp = System.getProperty("user.dir") + "\\opencv\\scene\\role\\skillUp.png";
    private static String PathShop = System.getProperty("user.dir") + "\\opencv\\scene\\role\\shop.png";
    private static String PathFast = System.getProperty("user.dir") + "\\opencv\\scene\\role\\fast.png";
    private static String PathCancle = System.getProperty("user.dir") + "\\opencv\\scene\\role\\cancle.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());
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        ThreadUtil.sleep(3000);
        for (int i = 0; i < 15; i++) {
            //拉到最左边
            moveToDrop(PathDropPoint, AiManage.getInstance().getCheckPoint(), new Point(0, 100), new Point(-850, 100));
            ThreadUtil.sleep(100);
        }
        ThreadUtil.sleep(3000);
        //点击等级最低的角色
        moveToClick(PathDropPoint, AiManage.getInstance().getCheckPoint(), new Point(0, 100));
        ThreadUtil.sleep(2000);

        moveToClick(PathLevel, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        while (AiManage.getInstance().isRunning() && !checkHas(PathCanLvup, AiManage.getInstance().getCheckPoint())) {
            moveToHold(PathExp, AiManage.getInstance().getCheckPoint(), new Point(0, 0), 10000);
            ThreadUtil.sleep(2000);
        }

        //依次点击4个位置快速完成一遍
        moveToClick(PathCanLvup, AiManage.getInstance().getCheckPoint(), new Point(-130, -274));
        ThreadUtil.sleep(2000);
        moveToClick(PathQuick, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathTime3, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathShop, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathShop, AiManage.getInstance().getCheckPoint());
            }
            if (checkHas(PathFast, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathFast, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(5000);
            }
            if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                break;
            }

            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        //第二个位置
        moveToClick(PathCanLvup, AiManage.getInstance().getCheckPoint(), new Point(-46, -274));
        ThreadUtil.sleep(2000);
        moveToClick(PathOb, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathTime30, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathShop, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathShop, AiManage.getInstance().getCheckPoint());
            }
            if (checkHas(PathFast, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathFast, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(5000);
            }
            if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                break;
            }
            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        //第三个位置
        moveToClick(PathCanLvup, AiManage.getInstance().getCheckPoint(), new Point(42, -274));
        ThreadUtil.sleep(2000);
        moveToClick(PathOb, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathTime30, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathShop, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathShop, AiManage.getInstance().getCheckPoint());
            }
            if (checkHas(PathFast, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathFast, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(5000);
            }
            if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                break;
            }
            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        //第四个位置
        moveToClick(PathCanLvup, AiManage.getInstance().getCheckPoint(), new Point(122, -274));
        ThreadUtil.sleep(2000);
        moveToClick(PathOb, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathTime30, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathShop, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathShop, AiManage.getInstance().getCheckPoint());
            }
            if (checkHas(PathFast, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathFast, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(5000);
            }
            if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                break;
            }
            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        moveToClick(PathClose, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);


        moveToClick(PathCanLvup, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);

        randomToClick();
        ThreadUtil.sleep(3000);

        moveToClick(PathSkill, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);

        //点3下技能
        for (int i = 0; i < 3; i++) {
            moveToClick(PathSkillUp, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(3000);
        }
        getRecord().getData().setDone(true);
        //关闭退出
        moveToClick(PathBack2, AiManage.getInstance().getCheckPoint());
    }

    @Override

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

}
