自动采集

wjdr
wangbing 1 year ago
parent 7c56119647
commit 705f13a9be

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

@ -37,8 +37,8 @@ public abstract class JMacro {
public JMacro() {
try {
// 机器人初始化
this.robot = new Robot();
this.robot.setAutoDelay(30);
this.robot = new JRoot();
this.robot.setAutoDelay(100);
this.startFocus();
} catch (AWTException e) {
throw new RuntimeException(e);
@ -108,15 +108,18 @@ public abstract class JMacro {
* @param smooth
*/
public void mouseMove(ViewPoint point, boolean smooth) {
int endX = point.getX() + (point.isAbsolute() ? 0 : getFocusRect().getLeft());
int endY = point.getY() + (point.isAbsolute() ? 0 : getFocusRect().getTop());
if (smooth) {
// 获取当前鼠标位置
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
int startX = mousePoint.x;
int startY = mousePoint.y;
// 求两点距离
double absX = Math.abs(startX - point.getX());
double absY = Math.abs(startY - point.getY());
double absX = Math.abs(startX - endX);
double absY = Math.abs(startY - endY);
double absZ = Math.sqrt(Math.pow(absX, 2) + Math.pow(absY, 2));
int times = (int) (absZ / 30 + (absZ % 30 > 0 ? 1 : 0));
int interval = Math.min(500 / times, 10);
@ -125,13 +128,13 @@ public abstract class JMacro {
// 分times次移动到指定点
for (int i = 1; i <= times; i++) {
float d = i * 1.0f / times;
int dx = (int) (startX + (point.getX() - startX) * d);
int dy = (int) (startY + (point.getY() - startY) * d);
int dx = (int) (startX + (endX - startX) * d);
int dy = (int) (startY + (endY - startY) * d);
robot.mouseMove(dx, dy);
delay(RandomUtil.randomInt(interval - 10, interval + 10));
}
} else {
robot.mouseMove(point.getX(), point.getY());
robot.mouseMove(endX, endY);
}
}
@ -153,7 +156,7 @@ public abstract class JMacro {
* @param rect
*/
public void mouseLeftClick(ViewRect rect) {
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1]));
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1], true));
}
/**
@ -516,11 +519,11 @@ public abstract class JMacro {
}
return TaskUtil.timeTask(() -> {
while (JMainService.getInstance().run) {
delayUnstable();
ViewRect result = findPic(rect, pic, minSimilar);
if (result != null) {
return result;
}
delayUnstable();
}
return null;
}, seconds, TimeUnit.SECONDS);
@ -604,11 +607,63 @@ public abstract class JMacro {
if (matchPic != null) {
return matchPic;
}
delayUnstable();
}
return null;
}, seconds, TimeUnit.SECONDS);
}
/**
*
*
* @param legends
* @param seconds
* @return
*/
public ViewRect[] waitAndMatchLegend(String[] legends, long seconds) {
return TaskUtil.timeTask(() -> {
while (JMainService.getInstance().run) {
ViewRect[] viewRects = matchLegend(legends);
for (ViewRect viewRect : viewRects) {
if (viewRect != null) {
return viewRects;
}
}
delayUnstable();
}
return new ViewRect[legends.length];
}, seconds, TimeUnit.SECONDS);
}
/**
*
*
* @param legends
* @return
*/
public ViewRect[] matchLegend(String... legends) {
return matchLegend(legends, 1.0);
}
/**
*
*
* @param legends
* @param minSimilar
* @return
*/
public ViewRect[] matchLegend(String[] legends, double minSimilar) {
ViewRect[] viewRects = new ViewRect[legends.length];
for (int i = 0; i < legends.length; i++) {
String legend = legends[i];
viewRects[i] = matchLegend(Legend.inflate(legend), minSimilar);
if (viewRects[i] != null) {
return viewRects;
}
}
return viewRects;
}
/**
*
*

@ -0,0 +1,31 @@
package com.example.jmacro.wjdr;
import java.awt.*;
public class JRoot extends Robot {
private static final int MAX_DELAY = 60000;
public JRoot() throws AWTException {
}
public JRoot(GraphicsDevice screen) throws AWTException {
super(screen);
}
@Override
public synchronized void delay(int ms) {
checkDelayArgument(ms);
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
private void checkDelayArgument(int ms) {
if (ms < 0 || ms > MAX_DELAY) {
throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
}
}
}

@ -94,7 +94,7 @@ public class Legend {
} else {
int x = Convert.toInt(ReUtil.get("[\\S\\s]+#L([0-9]+),[0-9]+\\.png", file.getName(), 1), 0);
int y = Convert.toInt(ReUtil.get("[\\S\\s]+#L[0-9]+,([0-9]+)\\.png", file.getName(), 1), 0);
newLegend.location = new ViewPoint(x, y);
newLegend.location = new ViewPoint(x, y, false);
}
fileCache.put(name, newLegend);

@ -9,6 +9,11 @@ package com.example.jmacro.wjdr.base;
*/
public class ViewPoint {
/**
*
*/
private boolean absolute;
/**
* ()x
*/
@ -22,9 +27,20 @@ public class ViewPoint {
}
/**
*
*
* @param x x
* @param y y
*/
public ViewPoint(int x, int y) {
this(x, y, false);
}
public ViewPoint(int x, int y, boolean absolute) {
this.x = x;
this.y = y;
this.absolute = absolute;
}
public int getX() {
@ -43,6 +59,14 @@ public class ViewPoint {
this.y = y;
}
public boolean isAbsolute() {
return absolute;
}
public void setAbsolute(boolean absolute) {
this.absolute = absolute;
}
@Override
public String toString() {
return "ViewPoint{" +

@ -3,7 +3,6 @@ package com.example.jmacro.wjdr.util;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.cron.CronUtil;
import com.example.jmacro.wjdr.base.ViewRect;
import java.util.ArrayList;
import java.util.List;
@ -127,6 +126,37 @@ public class TaskUtil extends CronUtil {
return service.scheduleAtFixedRate(runnable, initialDelay, delay, TimeUnit.MILLISECONDS);
}
public static void main(String[] args) {
TaskUtil.execTask(new Runnable() {
@Override
public void run() {
System.out.println("1");
}
}, 3, 3000);
}
/**
*
*
* @param runnable
* @param count
* @param interval
*/
public static void execTask(Runnable runnable, int count, long interval) {
for (int i = 0; i < count; i++) {
try {
runnable.run();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 控制重试时间间隔
if (i < count) {
ThreadUtil.sleep(interval);
}
}
}
}
/**
* IO
*

@ -6,12 +6,9 @@ import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.JMainService;
import com.example.jmacro.wjdr.base.Legend;
import com.example.jmacro.wjdr.base.ViewRect;
import com.example.jmacro.wjdr.wjdr.task.Task_;
import com.example.jmacro.wjdr.wjdr.task.Task_;
import com.example.jmacro.wjdr.wjdr.task.Task_线;
import com.example.jmacro.wjdr.wjdr.task.Task_;
import com.example.jmacro.wjdr.util.Logger;
import com.example.jmacro.wjdr.util.TaskUtil;
import com.example.jmacro.wjdr.wjdr.task.*;
/**
*
@ -62,24 +59,22 @@ public class MacroForWJDR extends JMacro {
public void run() {
long startTime = System.currentTimeMillis();
Logger.info("任务线程开始", DateUtil.date(startTime).toString("yyyy-MM-dd HH:mm:ss"));
Logger.info("任务线程ID={}", Thread.currentThread().getId());
// 获取启动图标
Logger.info("定位启动图标");
ViewRect launch = waitAndFindPic(Legend.inflate("启动图标").getFile(), 0.9);
ViewRect launch = waitAndFindPic(Legend.inflate("启动图标").getFile(), 0.9, 5);
if (launch != null) {
Logger.info("启动图标坐标:", launch.toString());
Logger.info("启动程序");
delay();
delayUnstable();
mouseLeftClick(launch);
} else {
Logger.error("未定位到图标,可能已进入游戏");
Logger.info("继续定位城镇");
}
Logger.info("定位城镇");
// 定位城镇
Boolean inMain = TaskUtil.retryTask(() -> {
{ // 定位弹框,关闭弹框
delayUnstable();
ViewRect rect = matchLegend("城镇_充值", 0.8d);
if (rect != null) {
mouseLeftClick(rect);
@ -87,14 +82,16 @@ public class MacroForWJDR extends JMacro {
}
}
{// 定位离线收益
delayUnstable();
ViewRect rect = matchLegend("城镇_离线收益", 0.9);
if (rect != null) {
mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
}
// 定位城镇
{
{// 定位城镇
delayUnstable();
ViewRect rect = matchLegend("城镇", 0.9);
if (rect != null) {
Logger.info("当前区域【野外】");
@ -104,6 +101,7 @@ public class MacroForWJDR extends JMacro {
}
}
{// 定位野外
delayUnstable();
ViewRect rect = matchLegend("野外", 0.9);
if (rect != null) {
Logger.info("当前区域【城镇】");
@ -120,14 +118,16 @@ public class MacroForWJDR extends JMacro {
Logger.info("进入城镇成功");
Logger.info("领取探险奖励");
delay();
delayUnstable();
new Task_线(this, focusRect).run();
Logger.info("收留避难者");
delay();
delayUnstable();
new Task_(this, focusRect).run();
// 矿场攻击检测任务
delayUnstable(1000);
new Task_(this, focusRect).run();
Logger.info("启动循环任务");
while (JMainService.getInstance().run) {
// 矿场攻击检测任务
@ -138,13 +138,9 @@ public class MacroForWJDR extends JMacro {
delayUnstable(1000);
new Task_(this, focusRect).run();
// 矿场攻击检测任务
delayUnstable(1000);
new Task_(this, focusRect).run();
// 自动采矿任务
// delayUnstable(1000);
// new Task_自动采矿(this, focusRect).run();
delayUnstable(1000);
new Task_(this, focusRect).run();
}
}
}

@ -28,11 +28,8 @@ public class Task_探险领取 extends BaseTask {
}
Logger.info("进入探险界面成功");
Logger.info("定位领取按钮");
ViewRect _ = macro.waitAndMatchLegend("探险_不可领取", 0.8);
if (_ != null) {
Logger.info("探险不可领取");
} else {
ViewRect[] viewRects = macro.waitAndMatchLegend(new String[]{"探险_领取", "探险_不可领取"}, 5);
if (viewRects[0] != null) { // 可以领取
Logger.info("定位领取按钮");
ViewRect _ = macro.waitAndMatchLegend("探险_领取", 0.8);
if (_ == null) {
@ -56,6 +53,10 @@ public class Task_探险领取 extends BaseTask {
macro.mouseLeftClick(_);
}
if (viewRects[1] != null) { // 不可以领取
Logger.info("探险不可领取");
}
ViewRect _ = macro.waitAndMatchLegend("探险_返回", 0.8);
if (_ == null) {
Logger.error("任务终止");

@ -12,12 +12,12 @@ public class Task_收留避难者 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
ViewRect rect = macro.matchLegend("城镇_避难者", 0.9);
ViewRect rect = macro.waitAndMatchLegend("城镇_避难者", 0.9,3);
if (rect == null) {
Logger.info("未发现避难者");
return;
}
Logger.info("发现避难者");
Logger.info("发现避难者{}", rect);
Logger.info("收留避难者");
macro.mouseLeftClick(rect);

@ -18,6 +18,8 @@ public class Task_离线收益 extends BaseTask {
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
} else {
Logger.info("未检测到离线收益弹框");
}
macro.delayUnstable();
}

@ -5,8 +5,7 @@ import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ViewPoint;
import com.example.jmacro.wjdr.base.ViewRect;
import com.example.jmacro.wjdr.util.Logger;
import java.io.File;
import com.example.jmacro.wjdr.util.TaskUtil;
public class Task_ extends BaseTask {
@ -36,31 +35,27 @@ public class Task_自动采矿 extends BaseTask {
Logger.info("定位野外按钮成功");
}
Logger.info("定位资源搜索按钮");
// 因为搜索按钮透明,不好比对,通过定位其下面的任务图标定位
ViewRect _ = macro.waitAndMatchLegend("野外_任务", 0.9);
if (_ == null) {
Logger.error("未检测到【资源搜索按钮】,采矿终止");
return;
}
ViewPoint = new ViewPoint(_.getCenter()[0], _.getCenter()[1] - 125);
Logger.info("定位资源搜索按钮成功:{}", .toString());
macro.mouseLeftClick();
Logger.info("点击资源搜索按钮");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(33, 648));
// 因为搜索按钮透明,不好比对,通过定位其下面的任务图标定位
ViewRect _ = macro.waitAndMatchLegend("野外_搜索#L226,879.png", 0.9);
Logger.info("等待搜索面板");
ViewRect _ = macro.waitAndMatchLegend("野外_搜索", 0.9);
if (_ == null) {
Logger.error("未检测到【野外_搜索】,采矿终止");
Logger.error("未检测到【待搜索面板】,采矿终止");
return;
}
// todo
Logger.info("拖动面板");
macro.mouseLeftDrag(new ViewPoint(433, 679), new ViewPoint(61, 682), true);
Logger.info("开始采集资源");
String[] types = new String[]{
"生肉", "木材", "煤矿", "铁矿"
};
for (String type : types) {
Logger.info("搜索资源【{}】", type);
boolean collect = collect(type, 0);
boolean collect = collect(type, 4);
if (collect) { // 中断采集
break;
}
@ -88,59 +83,80 @@ public class Task_自动采矿 extends BaseTask {
* @return true,
*/
private boolean collect(String type, int level) {
Logger.info("定位【{}】图标", type);
ViewRect typeRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_" + type + ".png"), 0.9);
Logger.info("定位【野外_资源搜索_{}】图标", type);
ViewRect typeRect = macro.waitAndMatchLegend("野外_资源搜索_" + type, 0.9);
if (typeRect == null) {
Logger.error("定位【{}】图标失败", type);
return false;
}
Logger.info("定位【{}】图标成功", type);
Logger.info("单击【{}】图标,坐标[{},{}]", type, typeRect.getCenter()[0], typeRect.getCenter()[1]);
Logger.info("选择【{}】图标,坐标[{},{}]", type, typeRect.getCenter()[0], typeRect.getCenter()[1]);
macro.mouseLeftClick(typeRect);
if (level == 0) {
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_-.png"), 0.98);
while ( != null) {
macro.delayUnstable();
macro.mouseLeftClick();
= macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_-.png"), 0.98);
}
Logger.info("矿等级重置为1");
level = 1;
}
Logger.info("搜索{}{}级矿", type, level);
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_搜索.png"), 0.98);
macro.mouseLeftClick();
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_采集.png"), 0.98);
if ( == null) {
Logger.info("未搜索到{}{}级矿!", type, level);
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_+.png"), 0.98);
macro.mouseLeftClick();
return collect(type, level + 1);
int clevel = getLevel();
if (clevel > level) {
TaskUtil.execTask(() -> {
Logger.info("调整等级");
macro.delayUnstable(700);
macro.mouseLeftClick(new ViewPoint(51, 777));
}, clevel - level, 1000);
}
Logger.info("搜索到{}{}级矿", type, level);
Logger.info("采集{}{}级矿", type, level);
macro.mouseLeftClick();
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_采集队伍满.png"), 0.98);
if ( != null) {
Logger.info("出征队伍满,取消采集!");
Logger.info("关闭弹框!");
macro.mouseLeftClick(new ViewPoint(.getRight() - 17, .getBottom() - 20));
Logger.info("退出资源搜索!");
macro.mouseLeftClick(new ViewPoint(.getRight() - 17, .getBottom() - 20));
return true;
if (clevel < level) {
TaskUtil.execTask(() -> {
Logger.info("调整等级");
macro.delayUnstable(700);
macro.mouseLeftClick(new ViewPoint(360, 777));
}, level - clevel, 1000);
}
ViewRect = macro.waitAndFindPic(viewRect, new File("legend", "野外_资源_出征.png"), 0.98);
if ( == null) {
Logger.info("出征{}{}级矿失败!", type, level);
ViewRect _ = macro.matchLegend("野外_资源搜索", 0.9);
if (_ == null) {
Logger.error("定位【野外_资源搜索】失败采矿终止");
return false;
}
Logger.info("出征{}{}级矿", type, level);
macro.mouseLeftClick();
Logger.info("点击搜索{}{}级矿", type, level);
macro.delayUnstable();
macro.mouseLeftClick(_);
macro.delayUnstable();
ViewRect = macro.waitAndMatchLegend("野外_资源采集", 0.98);
if ( != null) {
macro.mouseLeftClick();
macro.delayUnstable(1000);
ViewRect[] viewRects = macro.matchLegend("野外_资源出征", "野外_资源无对队列");
if (viewRects[0] != null) {
Logger.info("出征");
macro.mouseLeftClick(viewRects[0]);
}
if (viewRects[1] != null) {
Logger.info("队列已满,取消采集");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(471, 250));
Logger.info("队列已满,取消采集");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(471, 250));
return false;
}
} else if (level > 1) {
return collect(type, level - 1);
}
return true;
}
private int getLevel() {
for (int i = 1; i <= 8; i++) {
ViewRect = macro.matchLegend("野外_资源等级" + i, 0.99);
if ( != null) {
return i;
}
}
return 0;
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.