package com.example.jmacro.wjdr.task;

import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.util.Logger;

public class TaskRewards extends BaseTask {

    public TaskRewards(JMacro jMacro, ScreenRect screenRect) {
        super(jMacro, screenRect);
    }

    @Override
    public void run() {
        Logger.info("》》》探险奖励领取开始》》》");

        Logger.info("定位【探险】按钮");
        ScreenRect TAB_探险 = jMacro.waitAndMatchPic(this.screenRect, "TAB_探险_L35,881", 0.9);
        if (TAB_探险 == null) {
            return;
        }

        Logger.info("点击【探险】按钮");
        jMacro.mouseLeftClick(TAB_探险);

        ScreenRect 探险_按钮 = jMacro.waitAndMatchPic(this.screenRect, "探险_按钮_L240,854", 0.9);
        if (探险_按钮 == null) {
            Logger.info("进入探险界面失败");
            return;
        }
        Logger.info("进入探险界面成功");

        Logger.info("定位领取按钮");
        ScreenRect 探险_不可领取 = jMacro.waitAndMatchPic(this.screenRect, "探险_不可领取_L420,667", 0.8);
        if (探险_不可领取 != null) {
            Logger.info("探险不可领取");
            return;
        } else {
            Logger.info("定位领取按钮");
            ScreenRect 探险_领取 = jMacro.waitAndMatchPic(this.screenRect, "探险_领取_L426,667", 0.8);
            if (探险_领取 == null) {
                Logger.error("未检测到【探险_领取】，领取终止");
                return;
            }
            Logger.info("定位领取按钮成功，准备领取：{}", 探险_领取.toString());
            jMacro.mouseLeftClick(探险_领取);
            ScreenRect 探险_领取2 = jMacro.waitAndMatchPic(this.screenRect, "探险_领取2_L230,664", 0.8);
            if (探险_领取2 == null) {
                Logger.error("任务终止");
                return;
            }
            jMacro.mouseLeftClick(探险_领取2);

            ScreenRect 探险_获得奖励 = jMacro.waitAndMatchPic(this.screenRect, "探险_获得奖励_L196,218", 0.8);
            if (探险_获得奖励 == null) {
                Logger.error("任务终止");
                return;
            }
            jMacro.mouseLeftClick(探险_获得奖励);
        }

        ScreenRect 探险_返回 = jMacro.waitAndMatchPic(this.screenRect, "探险_返回_L4,4", 0.8);
        if (探险_返回 == null) {
            Logger.error("任务终止");
            return;
        }
        jMacro.mouseLeftClick(探险_返回);

        Logger.info("》》》探险奖励领取结束，返回城镇》》》");
    }
}
