自动采集

wjdr
wangbing 1 year ago
parent 16e4767372
commit db77c22f04

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -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]));
}
/**
*
*

@ -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);
}
/**

@ -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);

@ -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; // 非常接近白色的颜色

@ -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);
// 单独获取每一个像素点的RedGreen和Blue的值。
// int r = (bfImage.getRGB(x, y) & 0xFF0000) >> 16;
// int g = (bfImage.getRGB(x, y) & 0xFF00) >> 8;

Loading…
Cancel
Save

Powered by TurnKey Linux.