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

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 java.awt.*;

/**
 * 探索-王者挑战-王者难度
 */
@SceneAnnotation("SceneMain_Explore_King")
public class SceneMain_Explore_King_kings extends BaseScene implements Scene {

    @JsonIgnore
    @Override
    public float getPriority() {
        return 2.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\enter.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\enter2.png";
    private static String PathEnter3 = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\enter3.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\back.png";
    private static String PathFight = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\fight.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\start.png";
    private static String PathSkip = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\skip.png";
    private static String PathSkip2 = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\skip2.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\over.png";
    private static String PathCancle = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\cancle.png";
    private static String PathReward = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\reward.png";
    private static String PathTake = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\take.png";
    private static String PathWeek = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\week.png";
    private static String PathDay = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\day.png";
    private static String PathClose = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\close.png";
    private static String PathIKnow = System.getProperty("user.dir") + "\\opencv\\scene\\explore\\king\\kings\\iKnow.png";




    private int maxCount=9;
    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
    }

    @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(2000);
            }
            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        int count = getRecord().getData().getCount();
        ThreadUtil.sleep(5000);

        if (checkHas(PathIKnow, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathIKnow, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }

        if (count==2){
            moveToClick(PathDay, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);

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

            while (AiManage.getInstance().isRunning() && checkHas(PathTake, AiManage.getInstance().getCheckPoint()+0.05)){
                moveToClick(PathTake, AiManage.getInstance().getCheckPoint()+0.05);
                ThreadUtil.sleep(2000);
                randomToClick();
                ThreadUtil.sleep(2000);
            }

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

            while (AiManage.getInstance().isRunning() && checkHas(PathTake, AiManage.getInstance().getCheckPoint()+0.05)){
                moveToClick(PathTake, AiManage.getInstance().getCheckPoint()+0.05);
                ThreadUtil.sleep(2000);
                randomToClick();
                ThreadUtil.sleep(2000);
            }

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

        if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
            ThreadUtil.sleep(2000);
            moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            getRecord().getData().setCount(maxCount);
            return;
        }

        while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            if (checkHas(PathSkip, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathSkip, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathSkip2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathSkip2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathCheck, AiManage.getInstance().getCheckPoint())) {
                //有的时候会回到界面 循环没有结束 如果有就直接跳出
                break;
            }
            ThreadUtil.sleep(5000);

        }
        ThreadUtil.sleep(2000);
        randomToClick();

        getRecord().getData().setCount(count+1);
    }

    @Override
    public boolean isDone() {
        if (getRecord().getData().getCount()>= maxCount){
            return true;
        }
        return false;
    }

}
