diff --git a/legend/一键领取#L215,744.png b/legend/一键领取#L215,744.png new file mode 100644 index 0000000..706eb60 Binary files /dev/null and b/legend/一键领取#L215,744.png differ diff --git a/legend/启动图标#L438,485.png b/legend/启动图标#L438,485.png new file mode 100644 index 0000000..9a855de Binary files /dev/null and b/legend/启动图标#L438,485.png differ diff --git a/legend/启动图标.png b/legend/启动图标.png deleted file mode 100644 index b9c5f98..0000000 Binary files a/legend/启动图标.png and /dev/null differ diff --git a/legend/每日任务关闭#L496,80.png b/legend/每日任务关闭#L496,80.png new file mode 100644 index 0000000..4901c62 Binary files /dev/null and b/legend/每日任务关闭#L496,80.png differ diff --git a/legend/点击任意位置退出#L190,862.png b/legend/点击任意位置退出#L190,862.png new file mode 100644 index 0000000..f9986f2 Binary files /dev/null and b/legend/点击任意位置退出#L190,862.png differ diff --git a/legend/返回#L4,4.png b/legend/返回#L4,4.png new file mode 100644 index 0000000..303c1ce Binary files /dev/null and b/legend/返回#L4,4.png differ diff --git a/src/main/java/xyz/wbsite/jmacro/JMacro.java b/src/main/java/xyz/wbsite/jmacro/JMacro.java index ee0bb2b..9d202af 100644 --- a/src/main/java/xyz/wbsite/jmacro/JMacro.java +++ b/src/main/java/xyz/wbsite/jmacro/JMacro.java @@ -1,6 +1,7 @@ package xyz.wbsite.jmacro; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.RandomUtil; import xyz.wbsite.jmacro.base.Legend; import xyz.wbsite.jmacro.base.ViewColor; @@ -409,6 +410,7 @@ public abstract class JMacro { // 因为坐标取像素点是从0开始,因此需要-1 int yMax = viewRect.getBottom() - pic.getHeight(); + double maxSimilar = 0; for (int y = yMin; y <= yMax; y++) { for (int x = xMin; x <= xMax; x++) { // 对关键点进行先期匹配,降低运算复杂度。如果关键点本身就不匹配,就没必要再去匹配小图的每一个像素点 @@ -434,12 +436,16 @@ public abstract class JMacro { } // 计算相似度 double similar = (double) samePixels / (pic.getWidth() * pic.getHeight()); + maxSimilar = Math.max(maxSimilar, similar); if (similar >= minSimilar) { return new ViewRect(x, y, x + pic.getWidth(), y + pic.getHeight(), similar); } } } } + if (maxSimilar > 0.5D) { + Logger.info("最大相似度{}", NumberUtil.formatPercent(maxSimilar, 0)); + } return null; } @@ -462,7 +468,7 @@ public abstract class JMacro { * @return 匹配图片区域 */ public ViewRect findLegend(Legend legend, double minSimilar) { - return findPic(legend.getFile(), minSimilar); + return findLegend(getFocusRect(), legend, minSimilar); } /** @@ -484,6 +490,7 @@ public abstract class JMacro { * @return 匹配图片区域 */ public ViewRect findLegend(ViewRect rect, Legend legend, double minSimilar) { + Logger.info("查找图例:{}", legend.getName()); return findPic(rect, legend.getFile(), minSimilar); } @@ -616,7 +623,6 @@ public abstract class JMacro { if (result != null) { return result; } - delayUnstable(); } return null; }, seconds, TimeUnit.SECONDS); @@ -787,7 +793,7 @@ public abstract class JMacro { BufferedImage image = ImageUtil.load(legend.getFile()); viewRect.setRight(viewRect.getLeft() + image.getWidth()); viewRect.setBottom(viewRect.getTop() + image.getHeight()); - ImageUtil.show(viewRect); + //ImageUtil.show(viewRect); return findPic(viewRect, image, minSimilar); } diff --git a/src/main/java/xyz/wbsite/jmacro/JMainApplication.java b/src/main/java/xyz/wbsite/jmacro/JMainApplication.java index 2d26658..777b86d 100644 --- a/src/main/java/xyz/wbsite/jmacro/JMainApplication.java +++ b/src/main/java/xyz/wbsite/jmacro/JMainApplication.java @@ -10,6 +10,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Stage; +import xyz.wbsite.jmacro.wjdr.MacroForWJDR; import java.awt.event.KeyEvent; import java.io.File; @@ -66,27 +67,7 @@ public class JMainApplication extends Application { }); // 服务初始化 - JMainService.init(new JMacro() { - @Override - public ViewRect focus() { - return new ViewRect(0, 0, 1920, 1080); - } - - @Override - public void run() { - ViewRect 电脑 = findLegend(of(0, 0, 159, 168), "电脑", 0.99); - if (电脑 == null) { - return; - } - mouseLeftDoubleClick(电脑); - ViewRect 关闭 = waitAndFindLegend(of("关闭"), 0.99, 10); - - if (关闭 == null) { - return; - } - mouseLeftClick(关闭); - } - }, new File("legend")); + JMainService.init(new MacroForWJDR(), new File("legend")); } public static void main(String[] args) { diff --git a/src/main/java/xyz/wbsite/jmacro/base/Legend.java b/src/main/java/xyz/wbsite/jmacro/base/Legend.java index 30d93b2..0ffdc3b 100644 --- a/src/main/java/xyz/wbsite/jmacro/base/Legend.java +++ b/src/main/java/xyz/wbsite/jmacro/base/Legend.java @@ -5,6 +5,7 @@ import cn.hutool.cache.CacheUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReUtil; +import xyz.wbsite.jmacro.util.Logger; import java.io.File; import java.util.List; @@ -81,6 +82,7 @@ public class Legend { List files = FileUtil.loopFiles(defaultBase, pathname -> pathname.getName().startsWith(name)); if (files.size() == 0) { + Logger.error(defaultBase.getAbsolutePath() + " not found the legend of " + name); throw new RuntimeException(defaultBase.getAbsolutePath() + " not found the legend of " + name); } File file = files.get(0); diff --git a/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java b/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java index ee432cb..f437bcd 100644 --- a/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java +++ b/src/main/java/xyz/wbsite/jmacro/tool/PickLegend.java @@ -219,7 +219,7 @@ public class PickLegend extends JFrame { if (returnVal == JFileChooser.APPROVE_OPTION) { // 默认文件 File file = jFileChooser.getSelectedFile(); - String name = file.getName(); + String name = file.getName().replaceAll("\\.png",""); String legendName = name.split("#")[0]; String prefix = legendName + "#"; diff --git a/src/main/java/xyz/wbsite/jmacro/wjdr/MacroForWJDR.java b/src/main/java/xyz/wbsite/jmacro/wjdr/MacroForWJDR.java index 6f0670c..c49eeba 100644 --- a/src/main/java/xyz/wbsite/jmacro/wjdr/MacroForWJDR.java +++ b/src/main/java/xyz/wbsite/jmacro/wjdr/MacroForWJDR.java @@ -1,21 +1,16 @@ package xyz.wbsite.jmacro.wjdr; -import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import xyz.wbsite.jmacro.JMacro; import xyz.wbsite.jmacro.JMainService; import xyz.wbsite.jmacro.base.Legend; import xyz.wbsite.jmacro.base.ViewRect; import xyz.wbsite.jmacro.util.Logger; -import xyz.wbsite.jmacro.util.TaskUtil; -import xyz.wbsite.jmacro.wjdr.task.Task_探险领取; import xyz.wbsite.jmacro.wjdr.task.Task_收留避难者; -import xyz.wbsite.jmacro.wjdr.task.Task_离线收益; import xyz.wbsite.jmacro.wjdr.task.Task_自动采矿; +import xyz.wbsite.jmacro.wjdr.task.Task_返回城镇; import xyz.wbsite.jmacro.wjdr.task.Task_采矿被攻击; -import java.util.concurrent.TimeUnit; - /** * 无尽冬日脚本 * @@ -67,77 +62,31 @@ public class MacroForWJDR extends JMacro { Logger.info("任务线程开始", DateUtil.date(startTime).toString("yyyy-MM-dd HH:mm:ss")); // 获取启动图标 Logger.info("定位启动图标"); - ViewRect launch = waitAndFindPic(Legend.inflate("启动图标").getFile(), 0.9, 5); + ViewRect launch = waitAndFindPic(of("启动图标").getFile(), 0.9, 10); if (launch != null) { Logger.info("启动图标坐标:", launch.toString()); Logger.info("启动程序"); - delayUnstable(); mouseLeftClick(launch); + delay(10 * 1000); } Logger.info("定位城镇"); - - // 定位城镇 - Boolean inMain = TaskUtil.timeTask(() -> { - { // 定位弹框,关闭弹框 - delayUnstable(); - ViewRect rect = findLegend(of(437, 28, 491, 106), "城镇_礼包", 0.7); - if (rect != null) { - mouseLeftClick(rect); - Logger.info("检测到充值广告弹框,关闭弹框"); - } - } - {// 定位离线收益 - delayUnstable(); - ViewRect rect = matchLegend("城镇_离线收益", 0.9); - if (rect != null) { - mouseLeftClick(rect); - Logger.info("检测到离线收益弹框,关闭弹框"); - } - } - - {// 定位城镇 - delayUnstable(); - ViewRect rect = matchLegend("城镇", 0.9); - if (rect != null) { - Logger.info("当前区域【野外】"); - Logger.info("返回区域【城镇】"); - mouseLeftClick(rect); - return false; - } - } - {// 定位野外 - delayUnstable(); - ViewRect rect = matchLegend("野外", 0.9); - if (rect != null) { - Logger.info("当前区域【城镇】"); - return true; - } - } - return false; - }, 60, TimeUnit.SECONDS); - - if (!Convert.toBool(inMain, false)) { - Logger.info("未进入城镇:退出线程"); - return; - } - - Logger.info("进入城镇成功"); - - delayUnstable(); - new Task_离线收益(this, focusRect).run(); - - delayUnstable(); - new Task_收留避难者(this, focusRect).run(); - - // 矿场攻击检测任务 - delayUnstable(1000); - new Task_探险领取(this, focusRect).run(); +// +// delayUnstable(); +// new Task_离线收益(this, focusRect).run(); +// +// delayUnstable(); +// new Task_收留避难者(this, focusRect).run(); +// +// // 矿场攻击检测任务 +// delayUnstable(1000); +// new Task_探险领取(this, focusRect).run(); Logger.info("启动循环任务"); while (JMainService.getInstance().run) { + new Task_返回城镇(this, focusRect).run(); + // 矿场攻击检测任务 - delayUnstable(1000); new Task_采矿被攻击(this, focusRect).run(); // 避难者 diff --git a/src/main/java/xyz/wbsite/jmacro/wjdr/task/BaseTask.java b/src/main/java/xyz/wbsite/jmacro/wjdr/task/BaseTask.java index 60e5064..15f34fa 100644 --- a/src/main/java/xyz/wbsite/jmacro/wjdr/task/BaseTask.java +++ b/src/main/java/xyz/wbsite/jmacro/wjdr/task/BaseTask.java @@ -36,6 +36,7 @@ public abstract class BaseTask { this.task(macro, viewRect); Logger.info("》》》任务[{}]结束》》》", name); } catch (Exception e) { + e.printStackTrace(); Logger.info("》》》任务[{}]异常中断》》》", name); throw e; } diff --git a/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_离线收益.java b/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_离线收益.java index 716866e..05bdd18 100644 --- a/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_离线收益.java +++ b/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_离线收益.java @@ -14,7 +14,7 @@ public class Task_离线收益 extends BaseTask { public void task(JMacro macro, ViewRect viewRect) { macro.delayUnstable(); // 定位离线收益弹框,关闭弹框 - ViewRect rect = macro.waitAndMatchLegend("城镇_离线收益", 0.9); + ViewRect rect = macro.matchLegend("城镇_离线收益", 0.9); if (rect != null) { macro.mouseLeftClick(rect); Logger.info("检测到离线收益弹框,关闭弹框"); diff --git a/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_返回城镇.java b/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_返回城镇.java new file mode 100644 index 0000000..5b848b9 --- /dev/null +++ b/src/main/java/xyz/wbsite/jmacro/wjdr/task/Task_返回城镇.java @@ -0,0 +1,93 @@ +package xyz.wbsite.jmacro.wjdr.task; + +import xyz.wbsite.jmacro.JMacro; +import xyz.wbsite.jmacro.base.ViewRect; +import xyz.wbsite.jmacro.util.Logger; + +public class Task_返回城镇 extends BaseTask { + + public Task_返回城镇(JMacro macro, ViewRect viewRect) { + super(macro, viewRect); + } + + @Override + public void task(JMacro macro, ViewRect viewRect) { + while (true) { + {// 野外返回 + ViewRect rect = macro.matchLegend("野外", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("当前位置:城镇"); + return; + } + } + {// 野外返回 + ViewRect rect = macro.matchLegend("城镇", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("返回城镇"); + } + } + {// 其他页面返回 + ViewRect rect = macro.matchLegend("返回", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("返回城镇"); + } + } + { // 定位弹框,关闭弹框 + ViewRect rect = macro.findLegend(macro.of(437, 28, 491, 106), "城镇_礼包", 0.7); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("关闭充值广告弹框"); + } + } + {// 定位离线收益 + ViewRect rect = macro.matchLegend("城镇_离线收益", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("关闭离线收益弹框"); + } + } + {// 无行军队列弹框 + ViewRect rect = macro.matchLegend("野外_资源无对队列", 0.9); + if (rect != null) { + macro.mouseLeftClick(macro.of(471, 250)); + Logger.info("关闭弹框无对队列弹框"); + } + } + {// 无行军队列弹框 + ViewRect rect = macro.matchLegend("野外_搜索", 0.9); + if (rect != null) { + macro.mouseLeftClick(macro.of(253, 426)); + Logger.info("关闭野外搜索弹框"); + } + } + {// 一键领取弹框 + ViewRect rect = macro.matchLegend("一键领取", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("一键领取"); + macro.delay(500); + continue; + } + } + {// 点击任务位置退出 + ViewRect rect = macro.matchLegend("点击任意位置退出", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("点击任意位置退出"); + macro.delay(500); + continue; + } + } + {// 每日任务 + ViewRect rect = macro.matchLegend("每日任务关闭", 0.9); + if (rect != null) { + macro.mouseLeftClick(rect); + Logger.info("关闭每日任务关闭弹框"); + } + } + } + } +}