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

/**
 * 组织-信息
 */
@SceneAnnotation("SceneMain_Family_Out")
public class SceneMain_Family_Out_Boss extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 2.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\back.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\start.png";
    private static String PathStart2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\start2.png";
    private static String PathSkip = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\skip.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\over.png";
    private static String PathCancel = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\cancel.png";
    private static String PathReward = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\boss\\reward.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());
                ThreadUtil.sleep(5000);
                continue;
            }
        }
    }

    @Override
    public boolean check() throws AWTException {
        if (checkHas(PathCheck, AiManage.getInstance().getCheckPoint())) {
            return true;
        }
        return false;
    }
    static int maxTime=3;
    @Override
    public void think() throws AWTException {
        int count = getRecord().getData().getCount();

        if (count==0){
            ThreadUtil.sleep(5000);
            randomToClick();
            ThreadUtil.sleep(3000);
            if (checkHas(PathReward, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathReward, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
        }

        if (count<maxTime){
            while (AiManage.getInstance().isRunning() && !checkHas(PathStart, AiManage.getInstance().getCheckPoint())) {
                if (checkHas(PathReward, AiManage.getInstance().getCheckPoint())) {
                    moveToClick(PathReward, AiManage.getInstance().getCheckPoint());
                    ThreadUtil.sleep(2000);
                }
                ThreadUtil.sleep(1000);
            }
            ThreadUtil.sleep(4000);
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(3000);

            if (checkHas(PathCancel,AiManage.getInstance().getCheckPoint())){
                getRecord().getData().setCount(count+1);
            }else {
                moveToClick(PathStart2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);

                while (AiManage.getInstance().isRunning() && !checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
                    if (checkHas(PathSkip, AiManage.getInstance().getCheckPoint())) {
                        moveToClick(PathSkip, AiManage.getInstance().getCheckPoint());
                        ThreadUtil.sleep(2000);
                    }
                    ThreadUtil.sleep(1000);
                }
                ThreadUtil.sleep(5000);
                moveToClick(PathOver, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(6000);

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

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

}
