diff --git a/legend/野外_搜索.png b/legend/野外_搜索.png index 47857ec..4a889c8 100644 Binary files a/legend/野外_搜索.png and b/legend/野外_搜索.png differ diff --git a/legend/野外_资源_采集队伍满.png b/legend/野外_资源_采集队伍满.png new file mode 100644 index 0000000..012d989 Binary files /dev/null and b/legend/野外_资源_采集队伍满.png differ diff --git a/legend/首页_广告关闭按钮.png b/legend/首页_广告关闭按钮.png index 6b2f95e..651b74a 100644 Binary files a/legend/首页_广告关闭按钮.png and b/legend/首页_广告关闭按钮.png differ diff --git a/src/main/java/com/example/jmacro/wjdr/JMacro.java b/src/main/java/com/example/jmacro/wjdr/JMacro.java index 9f5442f..8980298 100644 --- a/src/main/java/com/example/jmacro/wjdr/JMacro.java +++ b/src/main/java/com/example/jmacro/wjdr/JMacro.java @@ -5,6 +5,7 @@ import com.example.jmacro.wjdr.base.ScreenPoint; import com.example.jmacro.wjdr.base.ScreenRect; import com.example.jmacro.wjdr.util.ColorUtil; import com.example.jmacro.wjdr.util.Imager; +import com.example.jmacro.wjdr.util.Logger; import com.example.jmacro.wjdr.util.TaskUtil; import java.awt.*; @@ -61,15 +62,24 @@ public class JMacro { /** * 鼠标左键单击 * - * @param rect 矩形区域 + * @param rect 点 */ - public void mouseLeftClick(ScreenRect rect) { - mouseMove(new ScreenPoint(rect.getCenter()[0], rect.getCenter()[1])); + public void mouseLeftClick(ScreenPoint rect) { + mouseMove(rect); robot.mousePress(InputEvent.BUTTON1_MASK); waitTap(); robot.mouseRelease(InputEvent.BUTTON1_MASK); } + /** + * 鼠标左键单击 + * + * @param rect 矩形区域 + */ + public void mouseLeftClick(ScreenRect rect) { + mouseLeftClick(new ScreenPoint(rect.getCenter()[0], rect.getCenter()[1])); + } + /** * 鼠标滚轮单击 * diff --git a/src/main/java/com/example/jmacro/wjdr/Main.java b/src/main/java/com/example/jmacro/wjdr/Main.java index 7b0e768..839acca 100644 --- a/src/main/java/com/example/jmacro/wjdr/Main.java +++ b/src/main/java/com/example/jmacro/wjdr/Main.java @@ -3,6 +3,7 @@ package com.example.jmacro.wjdr; import cn.hutool.core.date.DateUtil; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.RandomUtil; +import com.example.jmacro.wjdr.base.ScreenPoint; import com.example.jmacro.wjdr.base.ScreenRect; import com.example.jmacro.wjdr.task.TaskMining; import com.example.jmacro.wjdr.util.Imager; @@ -44,7 +45,7 @@ public class Main { if (DateUtil.isIn(DateUtil.date(), DateUtil.parse(workStart), DateUtil.parse(workEnd))) { int anInt = RandomUtil.randomInt(5, 20); - Logger.info("等待{}分钟后,重新启动游戏线程"); + Logger.info("等待{}分钟后,重新启动游戏线程", anInt); jMacro.setThread(new GameThread(jMacro)); TaskUtil.schedule(jMacro.getThread(), anInt, TimeUnit.MINUTES); } @@ -84,7 +85,7 @@ public class Main { Logger.info("扫描游戏主界面:"); ScreenRect 城镇 = TaskUtil.timeTask(() -> { while (true) { - ScreenRect screenRect1 = locationHome(jMacro); + ScreenRect screenRect1 = locationHome(jMacro, gameScreen); if (screenRect1 != null) { return screenRect1; } @@ -119,10 +120,10 @@ public class Main { } } - public static ScreenRect locationHome(JMacro jMacro) { + public static ScreenRect locationHome(JMacro jMacro, ScreenRect gameScreen) { { // 定位弹框,关闭弹框 BufferedImage image = Imager.load(new File("legend", "首页_广告关闭按钮.png")); - ScreenRect rect = jMacro.findPic(image, 0.80d); + ScreenRect rect = jMacro.findPic(gameScreen, image, 0.95d); if (rect != null) { jMacro.mouseLeftClick(rect); Logger.info("检测到弹框,关闭弹框"); @@ -131,7 +132,7 @@ public class Main { { // 定位主程序 BufferedImage legend = Imager.load(new File("legend", "城镇.png")); - ScreenRect rect = jMacro.findPic(legend, 0.80d); + ScreenRect rect = jMacro.findPic(gameScreen, legend, 0.2d); if (rect != null) { Logger.info("程序主界面已就绪"); return rect; @@ -142,7 +143,7 @@ public class Main { public static ScreenRect locationMuMu(JMacro jMacro) { BufferedImage image = Imager.load(new File("legend", "慕慕_工具栏.png")); - return jMacro.findPic(image, 0.99d); + return jMacro.findPic(image, 0.95d); } /** diff --git a/src/main/java/com/example/jmacro/wjdr/task/TaskMining.java b/src/main/java/com/example/jmacro/wjdr/task/TaskMining.java index a4a99a0..20e8816 100644 --- a/src/main/java/com/example/jmacro/wjdr/task/TaskMining.java +++ b/src/main/java/com/example/jmacro/wjdr/task/TaskMining.java @@ -1,6 +1,7 @@ package com.example.jmacro.wjdr.task; import com.example.jmacro.wjdr.JMacro; +import com.example.jmacro.wjdr.base.ScreenPoint; import com.example.jmacro.wjdr.base.ScreenRect; import com.example.jmacro.wjdr.util.Logger; @@ -32,28 +33,34 @@ public class TaskMining { ScreenRect 野外搜索 = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_搜索.png"), 0.9); jMacro.mouseLeftClick(野外搜索); - - boolean collect = false; - - while (!collect) { - + String[] types = new String[]{ + "生肉", "木材", "煤矿", "铁矿" + }; + for (String type : types) { + boolean collect = collect(type, 0); + if (collect) { // 中断采集 + break; + } } - collect("生肉", 0); - collect("木材", 0); - collect("煤矿", 0); - collect("铁矿", 0); + ScreenRect 搜索 = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_资源_搜索.png"), 0.98); + if (搜索 != null) { + Logger.info("退出资源搜索界面"); + jMacro.mouseLeftClick(screenRect); + } ScreenRect 城镇 = jMacro.waitAndFindPic(screenRect, new File("legend", "城镇.png"), 0.9); if (城镇 == null) { Logger.error("未检测到【城镇】,采矿终止"); return; } + Logger.error("采矿完成,返回城镇"); } /** - * @param level - * @return + * @param type 资源类型 + * @param level 等级(0为重置) + * @return 采集是否结束(满队则返回true,接下来的采集也不需要了) */ private boolean collect(String type, int level) { ScreenRect typeRect = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_" + type + ".png"), 0.9); @@ -83,6 +90,17 @@ public class TaskMining { Logger.info("搜索到{}{}级矿", type, level); Logger.info("采集{}{}级矿", type, level); jMacro.mouseLeftClick(采集); + + ScreenRect 采集队伍满 = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_资源_采集队伍满.png"), 0.98); + if (采集队伍满 != null) { + Logger.info("出征队伍满,取消采集!"); + Logger.info("关闭弹框!"); + jMacro.mouseLeftClick(new ScreenPoint(采集队伍满.getRight() - 17, 采集队伍满.getBottom() - 20)); + Logger.info("退出资源搜索!"); + jMacro.mouseLeftClick(new ScreenPoint(采集队伍满.getRight() - 17, 采集队伍满.getBottom() - 20)); + return true; + } + ScreenRect 出征 = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_资源_出征.png"), 0.98); if (出征 == null) { Logger.info("出征{}{}级矿失败!", type, level); diff --git a/src/main/java/com/example/jmacro/wjdr/util/ColorUtil.java b/src/main/java/com/example/jmacro/wjdr/util/ColorUtil.java index 32c4a5b..919206f 100644 --- a/src/main/java/com/example/jmacro/wjdr/util/ColorUtil.java +++ b/src/main/java/com/example/jmacro/wjdr/util/ColorUtil.java @@ -1,5 +1,8 @@ package com.example.jmacro.wjdr.util; +import java.awt.image.BufferedImage; +import java.io.File; + public class ColorUtil { /** @@ -27,10 +30,22 @@ public class ColorUtil { } public static boolean isSimilar(int colorInt1, int colorInt2) { + // 透明色认为相似 + if ("ffffff".equals(Integer.toHexString(colorInt1))) { + return true; + } + if ("ffffff".equals(Integer.toHexString(colorInt2))) { + return true; + } return calculateSimilarity(colorInt1, colorInt2) > 0.90d; } public static void main(String[] args) { + + BufferedImage image = Imager.load(new File("legend", "首页_广告关闭按钮 - 副本.png")); + int[][] imageRGB = Imager.getImageRGB(image); + + int color1 = 0xffffff; // 白色 int color2 = 0xfefefe; // 非常接近白色的颜色 diff --git a/src/main/java/com/example/jmacro/wjdr/util/Imager.java b/src/main/java/com/example/jmacro/wjdr/util/Imager.java index 11394f9..c0dbf93 100644 --- a/src/main/java/com/example/jmacro/wjdr/util/Imager.java +++ b/src/main/java/com/example/jmacro/wjdr/util/Imager.java @@ -2,6 +2,7 @@ package com.example.jmacro.wjdr.util; import cn.hutool.core.img.ImgUtil; +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; @@ -62,12 +63,15 @@ public class Imager { public static int[][] getImageRGB(BufferedImage bfImage) { int width = bfImage.getWidth(); int height = bfImage.getHeight(); + boolean b = bfImage.getColorModel().hasAlpha(); int[][] result = new int[width][height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 对某个像素点的RGB编码并存入数据库 - result[x][y] = bfImage.getRGB(x, y) & 0xFFFFFF; - + int rgb = bfImage.getRGB(x, y); + result[x][y] = rgb & 0xFFFFFF; +// System.out.println(Integer.toHexString(rgb)); +// System.out.println(alpha); // 单独获取每一个像素点的Red,Green,和Blue的值。 // int r = (bfImage.getRGB(x, y) & 0xFF0000) >> 16; // int g = (bfImage.getRGB(x, y) & 0xFF00) >> 8;