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

/**
 * 体力领取-家园研究
 */
@SceneAnnotation("SceneMain_Energy")
public class SceneMain_Energy_Home extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 1.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\back.png";
    private static String PathOver = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\over.png";
    private static String PathObTake = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\ObTake.png";
    private static String PathReward = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\reward.png";
    private static String PathRewardRes = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\rewardRes.png";
    private static String PathTec_dark = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\tec_dark.png";
    private static String PathRes_dark = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\home\\res_dark.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(2000);
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        if (checkHas(PathOver, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathOver, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);

            moveToClick(PathObTake, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(5000);

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

        if (getChildren().stream().anyMatch(o -> o.isDone() && "SceneMain_Energy_Home_Select".equals(o.getClass().getSimpleName()))) {
            if (checkHas(PathTec_dark, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathTec_dark, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }

            if (checkHas(PathReward, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathReward, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                int count = getRecord().getData().getCount();
                getRecord().getData().setCount(count+1);
            }
        }

        if (getChildren().stream().anyMatch(o -> o.isDone() && "SceneMain_Energy_Home_SelectRes".equals(o.getClass().getSimpleName()))) {
            if (checkHas(PathRes_dark, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathRes_dark, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }

            if (checkHas(PathRewardRes, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathRewardRes, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                randomToClick();
                ThreadUtil.sleep(2000);
                int count = getRecord().getData().getCount();
                getRecord().getData().setCount(count+1);
            }
        }
    }

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

}
