自动采集

wjdr
wangbing 12 months ago
parent bb091ababd
commit 84d20c4290

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 B

@ -16,6 +16,10 @@ import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
@ -846,18 +850,72 @@ public abstract class JMacro {
}
/**
*
* 0~1
*
* @param point
* @return
* @param color :#ffffff
* @return
*/
public double findColor(int left, int top, int right, int bottom, String color) {
return findColor(of(left, top, right, bottom), color);
}
/**
* 0~1
*
* @param rect
* @param color :#ffffff
* @return
*/
public String takeColor(ViewPoint point) {
ViewRect of = of(point.getX(), point.getY(), point.getX(), point.getY());
public double findColor(ViewRect rect, String color) {
// 获取实时屏幕
BufferedImage pointImage = capture(robot, of);
ImageUtil.show(pointImage);
int[][] pointData = ImageUtil.getImageRGB(pointImage);
return "#" + Integer.toHexString(pointData[0][0]);
BufferedImage capture = capture(robot, rect);
ImageUtil.show(capture);
List<String> colors = new ArrayList<>();
for (int y = 0; y < capture.getHeight(); y++) {
for (int x = 0; x < capture.getWidth(); x++) {
colors.add("#" + Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF));
}
}
Map<String, Integer> countMap = new HashMap<>();
for (String c : colors) {
countMap.put(c, countMap.getOrDefault(c, 0) + 1);
}
return countMap.getOrDefault(color, 0);
}
/**
*
*
* @param color :#ffffff
* @return
*/
public boolean hasColor(int left, int top, int right, int bottom, String... color) {
return hasColor(of(left, top, right, bottom), color);
}
/**
*
*
* @param rect
* @param color :#ffffff
* @return
*/
public boolean hasColor(ViewRect rect, String... color) {
// 获取实时屏幕
BufferedImage capture = capture(robot, rect);
ImageUtil.show(capture);
for (int y = 0; y < capture.getHeight(); y++) {
for (int x = 0; x < capture.getWidth(); x++) {
String col = "#" + Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF);
for (String s : color) {
if (col.equals(s)) {
return true;
}
}
}
}
return false;
}
/**

@ -1,18 +1,18 @@
package xyz.wbsite.jmacro.tool;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.StaticLog;
import xyz.wbsite.jmacro.util.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.*;
/**
*
@ -120,10 +120,40 @@ public class PickRect extends JFrame {
Logger.info("=========================区域采集=========================");
Logger.info("屏幕区域:[{},{},{},{}]", left, top, right, bottom);
Logger.info("相对区域:[{},{},{},{}]", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("-------------------");
Logger.info("色值统计(TOP5)");
List<String> colors = new ArrayList<>();
for (int y = top; y < bottom; y++) {
for (int x = left; x < right; x++) {
colors.add("#" + Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF));
}
}
Map<String, Integer> countMap = new HashMap<>();
for (String c : colors) {
countMap.put(c, countMap.getOrDefault(c, 0) + 1);
}
LinkedHashMap<String, Integer> sim = (LinkedHashMap<String, Integer>) MapUtil.sortByValue(countMap, true);
int topP = 1;
int length = StrUtil.length(colors.size() + "");
List<String> topColor = new ArrayList<>();
for (String c : sim.keySet()) {
if (topP > 6) {
break;
}
double v = 1.0D * sim.get(c) / colors.size();
if (v > 0.01D) {
topP++;
topColor.add(c);
Logger.info("{} {} {}", c, StrUtil.padPre(Convert.toStr(sim.get(c)), length, "0"), NumberUtil.formatPercent(1.0D * sim.get(c) / colors.size(), 0));
}
}
Logger.info("-------------------");
Logger.info("用法示例:");
Logger.info("1、区域点击mouseLeftClick(of({},{},{},{}));", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("2、区域查找findLegend(of({},{},{},{}), \"按钮\", 0.99);", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("区域点击macro.mouseLeftClick(macro.of({},{},{},{}));", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("区域查找macro.findLegend(macro.of({},{},{},{}), \"按钮\", 0.99);", left - originX, top - originY, right - originX, bottom - originY);
Logger.info("区域查色macro.findColor(macro.of({},{},{},{}), \"{}\");", left - originX, top - originY, right - originX, bottom - originY, topColor.get(0));
Logger.info("区域找色macro.hasColor(macro.of({},{},{},{}), \"{}\");", left - originX, top - originY, right - originX, bottom - originY, String.join("\",\"", topColor));
Logger.info("=========================区域采集=========================");
close();
@ -157,6 +187,25 @@ public class PickRect extends JFrame {
setVisible(true);
}
public static void main(String[] args) {
List<String> colors = new ArrayList<>();
colors.add("ffffff");
colors.add("000000");
colors.add("111111");
colors.add("111111");
colors.add("111111");
Map<String, Integer> countMap = new LinkedHashMap<>();
for (String c : colors) {
countMap.put(c, countMap.getOrDefault(c, 0) + 1);
}
Map<String, Integer> sim = MapUtil.sortByValue(countMap, true);
for (String s : sim.keySet()) {
System.out.println(s + " ==> " + sim.get(s) + "" + NumberUtil.formatPercent(sim.get(s) / colors.size(), 0));
}
}
@Override
public void doLayout() {
super.doLayout();

@ -95,16 +95,16 @@ public class MacroForWJDR extends JMacro {
// 可按优先级排序以下任务
{
// 矿场攻击检测任务
new Task_(this, focusRect).run();
// 避难者
new Task_(this, focusRect).run();
// 自动练兵
new Task_(this, focusRect).run();
// 自动采矿任务
new Task_(this, focusRect).run();
// new Task_采矿被攻击(this, focusRect).run();
//
// // 避难者
// new Task_收留避难者(this, focusRect).run();
//
// // 自动练兵
// new Task_自动练兵(this, focusRect).run();
//
// // 自动采矿任务
// new Task_自动采矿(this, focusRect).run();
// 探险领取
new Task_(this, focusRect).run();

@ -6,6 +6,33 @@ import xyz.wbsite.jmacro.util.Logger;
public class Task_ extends BaseTask {
String[] numColor = new String[]{
"#f15252",
"#fe3838",
"#e33335",
"#f23335",
"#e12929",
"#f65455",
"#d44446",
"#871829",
"#c22526",
"#e92f2f",
"#d02020",
"#b64046",
"#cb4840",
"#f93a3a",
"#962433",
"#f73132",
"#c82a28",
"#c21b1d",
"#e22424",
"#fd3e3e",
"#ff3939",
"#a42e38",
"#c83532",
"#f83838",
};
public Task_(JMacro macro, ViewRect viewRect) {
super(macro, viewRect);
}
@ -13,34 +40,47 @@ public class Task_任务奖励领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
Logger.info("检测任务奖励");
ViewRect[] viewRects = macro.matchLegends(0.3, "任务奖励_待领取", "任务奖励_待领取2");
if (viewRects[0] == null && viewRects[1] == null) {
boolean hasColor = macro.hasColor(macro.of(38, 752, 58, 764), numColor);
if (!hasColor) {
Logger.info("无任务奖励,跳过");
return;
}
Logger.info("进入任务页面,领取奖励");
macro.mouseLeftClick(macro.of(43, 758));
macro.delay(1000);
Logger.info("检测章节任务");
ViewRect = macro.matchLegend("任务奖励_章节任务", 0.5);
if ( != null) {
boolean = macro.hasColor(macro.of(158, 849, 171, 857), numColor);
if () {
Logger.info("领取章节任务");
macro.mouseLeftClick();
macro.mouseLeftClick(macro.of(158, 849, 171, 857));
macro.delay(500);
ViewRect ;
do {
= macro.matchLegend("任务奖励_章节任务领取按钮", 0.9);
= macro.matchLegend("任务奖励_底部领取按钮", 0.9);
if ( != null) {
macro.mouseLeftClick();
}
ViewRect = macro.matchLegend("任务奖励_底部领取按钮", 0.9);
if ( != null) {
= ;
macro.mouseLeftClick();
macro.delay(1000);
ViewRect _退 = macro.waitAndMatchLegend("任务奖励_点击退出", 0.5, 2);
if (_退 != null) {
macro.mouseLeftClick(_退);
macro.delay(500);
}
}
} while ( != null);
}
Logger.info("检测成长任务");
ViewRect = macro.matchLegend("任务奖励_成长任务", 0.5);
if ( != null) {
boolean = macro.hasColor(macro.of(330, 848, 342, 857), numColor);
if () {
Logger.info("领取成长任务");
macro.mouseLeftClick();
macro.mouseLeftClick(macro.of(330, 848, 342, 857));
macro.delay(500);
ViewRect ;
do {
@ -53,10 +93,10 @@ public class Task_任务奖励领取 extends BaseTask {
}
Logger.info("检测每日任务");
ViewRect = macro.matchLegend("任务奖励_每日任务", 0.5);
if ( != null) {
boolean = macro.hasColor(macro.of(497, 846, 518, 858), "#e2d4d4", "#a74f52", "#ff3c3c","#ef3435","#e9e1e2","#fb3838","#f7f4f4","#fcfbfb");
if () {
Logger.info("领取每日任务");
macro.mouseLeftClick();
macro.mouseLeftClick(macro.of(499, 847, 517, 858));
macro.delay(500);
ViewRect ;
do {

Loading…
Cancel
Save

Powered by TurnKey Linux.