自动采集

wjdr
wangbing 11 months ago
parent fa1e325e7c
commit 2b9dc91d9a

@ -32,8 +32,6 @@ public class JMainApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
Logger.setDebug(true);
stage.setTitle("无限工具");
stage.setMinWidth(400);
stage.setMinHeight(300);

@ -0,0 +1,11 @@
package xyz.wbsite.jmacro.ex;
/**
*
*/
public class MacroErrorException extends RuntimeException {
public MacroErrorException(String message) {
super(message);
}
}

@ -0,0 +1,7 @@
package xyz.wbsite.jmacro.ex;
/**
*
*/
public class ServiceInterruptException extends RuntimeException {
}

@ -1,6 +1,8 @@
package xyz.wbsite.jmacro.util;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.caller.CallerUtil;
import cn.hutool.core.util.StrUtil;
import xyz.wbsite.jmacro.JMainService;
@ -13,29 +15,28 @@ import xyz.wbsite.jmacro.JMainService;
*/
public class Logger {
public static boolean isDebug = false;
public static void setDebug(boolean isDebug) {
Logger.isDebug = isDebug;
}
public static void debug(String log, Object... arg) {
if (isDebug) {
System.out.println("[DEBUG]" + DateUtil.date() + " " + StrUtil.format(log, arg));
}
}
public static void info(String log, Object... arg) {
System.out.println("[INFO ]" + DateUtil.date() + " " + StrUtil.format(log, arg));
public static void info(String format, Object... arg) {
DateTime date = DateUtil.date();
String level = "INFO";
String log = StrUtil.format(format, arg);
String name = CallerUtil.getCallerCaller().getSimpleName();
// 获取当前线程的堆栈追踪
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// 通常堆栈追踪数组的第三个元素是logMessage方法的调用者
int lineNumber = stackTrace[2].getLineNumber();
System.out.println(StrUtil.format("[{}] [{}] {} [{}:{}]", date, level, log, name, lineNumber));
}
public static void error(String log, Object... arg) {
System.out.println("[ERROR]" + DateUtil.date() + " " + StrUtil.format(log, arg));
while (JMainService.getInstance().run){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
info(log, arg);
// 中断1分钟
for (int i = 0; i < 60; i++) {
if (JMainService.getInstance().run) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}

@ -6,6 +6,7 @@ import cn.hutool.core.util.RandomUtil;
import xyz.wbsite.jmacro.JMacro;
import xyz.wbsite.jmacro.JMainService;
import xyz.wbsite.jmacro.base.ViewRect;
import xyz.wbsite.jmacro.ex.MacroErrorException;
import xyz.wbsite.jmacro.util.Logger;
import xyz.wbsite.jmacro.wjdr.task.*;
@ -76,18 +77,22 @@ public class MacroForWJDR extends JMacro {
int count = 99;
while (JMainService.getInstance().run && count > 0) {
count--;
// 任意界面优先返回城镇
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();
new Task_(this, focusRect).run();
try {
// 任意界面优先返回城镇
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();
new Task_(this, focusRect).run();
} catch (MacroErrorException ignored) {
}
}
} else {
Logger.info("当前时间为非工作时间,休眠待命!");

@ -3,6 +3,7 @@ package xyz.wbsite.jmacro.wjdr.task;
import xyz.wbsite.jmacro.JMacro;
import xyz.wbsite.jmacro.JMainService;
import xyz.wbsite.jmacro.base.ViewRect;
import xyz.wbsite.jmacro.ex.MacroErrorException;
import xyz.wbsite.jmacro.util.Logger;
/**
@ -33,13 +34,6 @@ public abstract class BaseTask {
String name = getClass().getSimpleName();
try {
Logger.info("》》》任务[{}]开始》》》", name);
ViewRect rect;
do {
rect = macro.matchLegend("野外", 0.9);
if (rect == null) {
Logger.info("请返回城镇");
}
} while (rect == null);
this.task(macro, viewRect);
Logger.info("》》》任务[{}]结束》》》", name);
} catch (Exception e) {
@ -48,6 +42,18 @@ public abstract class BaseTask {
}
}
public void isReady() {
for (int i = 0; i < 10; i++) {
ViewRect rect = macro.matchLegend("野外", 0.9);
if (rect != null) {
return;
}
macro.delay(100);
}
throw new MacroErrorException("请返回城镇");
}
/**
*
*

@ -12,6 +12,8 @@ public class Task_仓库奖励领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("打开面板");
ViewRect[] viewRects = macro.matchLegends(macro.of("城镇_面板1选中", "城镇_面板2选中"), 0.9);
if (viewRects[0] == null && viewRects[1] == null) {
@ -86,6 +88,6 @@ public class Task_仓库奖励领取 extends BaseTask {
macro.mouseLeftClick(_);
}
}
macro.delay(1000);
macro.delay(2000);
}
}

@ -59,6 +59,8 @@ public class Task_任务奖励领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("检测任务奖励");
boolean hasColor = macro.hasColor(macro.of(38, 751, 56, 765), numColor);
if (!hasColor) {
@ -179,5 +181,6 @@ public class Task_任务奖励领取 extends BaseTask {
Logger.info("关闭任务奖励面板");
macro.mouseLeftClick(_);
}
macro.delay(2000);
}
}

@ -12,6 +12,8 @@ public class Task_探险奖励领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
boolean = macro.matchColor(macro.of(71,877,"#ff1e1f"));
if (!) {
Logger.info("探险奖励未满,跳过");
@ -55,5 +57,6 @@ public class Task_探险奖励领取 extends BaseTask {
return;
}
macro.mouseLeftClick(_);
macro.delay(2000);
}
}

@ -12,6 +12,8 @@ public class Task_收留避难者 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
ViewRect rect = macro.matchLegend("城镇_避难者", 0.9);
if (rect == null) {
Logger.info("未发现避难者");
@ -31,5 +33,6 @@ public class Task_收留避难者 extends BaseTask {
macro.mouseLeftClick(rect1);
Logger.info("返回城镇");
macro.delay(2000);
}
}

@ -12,9 +12,11 @@ public class Task_自动练兵 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
(macro, viewRect);
(macro, viewRect);
(macro, viewRect);
macro.delay(2000);
}
private void (JMacro macro, ViewRect viewRect) {

@ -20,6 +20,8 @@ public class Task_自动采矿 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
ViewRect[] viewRects = macro.matchLegends(macro.of("城镇_面板1选中", "城镇_面板2选中"), 0.9);
if (viewRects[0] == null && viewRects[1] == null) {
Logger.info("面板未打开");
@ -149,6 +151,7 @@ public class Task_自动采矿 extends BaseTask {
}
macro.mouseLeftClick(1);
Logger.info("返回城镇");
macro.delay(2000);
}
/**

@ -21,6 +21,8 @@ public class Task_自动野怪 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("读取体力值");
double color = macro.findColor(macro.of(12, 62, 57, 65), "#26c200");
Logger.info("体力值" + NumberUtil.formatPercent(color, 0));
@ -153,13 +155,14 @@ public class Task_自动野怪 extends BaseTask {
macro.mouseLeftClick(this.viewRect);
}
ViewRect 1 = macro.waitAndMatchLegend("城镇", 0.9);
ViewRect 1 = macro.waitAndMatchLegend("城镇", 0.6);
if (1 == null) {
Logger.error("未检测到【城镇】,异常终止");
return;
}
macro.mouseLeftClick(1);
Logger.info("返回城镇");
macro.delay(2000);
}
/**

@ -12,6 +12,8 @@ public class Task_英雄招募领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("打开面板");
boolean _ = macro.matchLegendAndClick("城镇_打开面板", 0.6);
if (!_) {
@ -45,7 +47,7 @@ public class Task_英雄招募领取 extends BaseTask {
macro.delay(1000);
Logger.info("检测任意位置继续");
ViewRect 退 = macro.waitAndMatchLegend("英雄招募_点击任意位置退出", 0.5, 3);
ViewRect 退 = macro.waitAndMatchLegend("英雄招募_奖励清单", 0.9, 3);
if (退 != null) {
Logger.info("点击任意位置退出");
macro.mouseLeftClick(退);
@ -61,7 +63,7 @@ public class Task_英雄招募领取 extends BaseTask {
macro.delay(1000);
Logger.info("检测任意位置继续");
ViewRect 退 = macro.waitAndMatchLegend("英雄招募_点击任意位置退出", 0.25, 3);
ViewRect 退 = macro.waitAndMatchLegend("英雄招募_奖励清单", 0.9, 3);
if (退 != null) {
Logger.info("点击任意位置退出");
macro.mouseLeftClick(退);
@ -71,5 +73,6 @@ public class Task_英雄招募领取 extends BaseTask {
}
macro.matchLegendAndClick("英雄招募_返回", 0.9);
macro.delay(2000);
}
}

@ -60,6 +60,8 @@ public class Task_邮件奖励领取 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("检测邮箱待领取礼包");
boolean hasColor = macro.hasColor(macro.of(503,745,518,756), numColor);
@ -152,10 +154,8 @@ public class Task_邮件奖励领取 extends BaseTask {
}
}
ViewRect rect = macro.matchLegend("邮件_返回", 0.9);
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("返回城镇");
}
Logger.info("返回城镇");
macro.matchLegendAndClick("邮件_返回", 0.9);
macro.delay(2000);
}
}

@ -12,6 +12,8 @@ public class Task_采矿被攻击 extends BaseTask {
@Override
public void task(JMacro macro, ViewRect viewRect) {
isReady();
Logger.info("开发中...");
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.