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

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\back.png";

    private static String PathItem = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\item.png";
    private static String PathAdd = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\add.png";
    private static String PathBuy = System.getProperty("user.dir") + "\\opencv\\scene\\energy\\buy\\buy.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 {
        moveToClick(PathItem,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

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

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

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

        getRecord().getData().setDone(true);
    }

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

}
