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

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_Energy_Home")
public class SceneMain_Energy_Home_SelectRes extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 1.0f;
    }

    private static String PathEnter_dark = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\enter_dark.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\back.png";
    private static String PathOnButton = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\onButton.png";

    private static String PathEnter0 = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\enter0.png";
    private static String PathEnter1 = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\enter1.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\enter2.png";
    private static String PathEnter3 = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\selectRes\\enter3.png";

    @JsonIgnore
    private int maxCount = 4;

    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
        isTempDone = false;
    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter_dark, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter_dark, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
            int count = getRecord().getData().getCount();
            switch (count){
                case 0:
                    moveToClick(PathEnter0, AiManage.getInstance().getCheckPoint(), new Point(0, 20));
                    break;
                case 1:
                    moveToClick(PathEnter1, AiManage.getInstance().getCheckPoint(), new Point(0, 20));
                    break;
                case 2:
                    moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint(), new Point(0, 20));
                    break;
                case 3:
                    moveToClick(PathEnter3, AiManage.getInstance().getCheckPoint(), new Point(0, 20));
                    break;
            }
            ThreadUtil.sleep(2000);
        }
    }

    @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();
        if (count < maxCount) {
            moveToClick(PathOnButton, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            getRecord().getData().setCount(count + 1);
        }
        isTempDone = true;
    }

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

}
