上传备份

wjdr
王兵 1 year ago
parent b0445c77a5
commit cb4b2215d7

@ -369,11 +369,6 @@ public class JMacro {
}
}
}
// try {
// ImgUtil.write(screen,"png", new FileOutputStream("D://1.png"));
// } catch (FileNotFoundException e) {
//
// }
return null;
}
@ -571,7 +566,13 @@ public class JMacro {
BufferedImage image = ImageUtil.load(file);
viewRect.setRight(viewRect.getLeft() + image.getWidth());
viewRect.setBottom(viewRect.getTop() + image.getHeight());
return findPic(viewRect, image, minSimilar);
ViewRect pic = findPic(viewRect, image, minSimilar);
if (pic == null && Logger.isDebug) {
ImageUtil.show(viewRect);
}
return pic;
}
/**

@ -2,6 +2,7 @@ package com.example.jmacro.wjdr;
import com.example.jmacro.wjdr.demo.DemoThread;
import com.example.jmacro.wjdr.ui.FXMLUtil;
import com.example.jmacro.wjdr.util.Logger;
import com.example.jmacro.wjdr.util.ResourceUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
@ -22,6 +23,8 @@ public class JMainApplication extends Application {
@Override
public void start(Stage stage) throws Exception {
Logger.setDebug(true);
stage.setTitle("无限工具");
stage.setMinWidth(400);
stage.setMinHeight(300);

@ -118,6 +118,7 @@ public class JMainService {
@Override
public void run() {
while (run) {
Logger.info("守护线程ID={}", Thread.currentThread().getId());
ThreadUtil.sleep(1000);
if (macroThread == null) {
Logger.error("脚本线程未设置");

@ -1,5 +1,7 @@
package com.example.jmacro.wjdr.demo;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.JMacroThread;
import com.example.jmacro.wjdr.base.ViewRect;
@ -31,6 +33,11 @@ public class DemoThread extends JMacroThread {
*/
private final String workEnd = "24:00:00";
/**
* (ms)
*/
private final long workTime = 30 * 60 * 1000;
public DemoThread(JMacro macro) {
super(macro);
}
@ -58,6 +65,9 @@ public class DemoThread extends JMacroThread {
@Override
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 = macro.waitAndFindPic(viewRect, "启动图标", 0.9, 5, TimeUnit.SECONDS);
@ -67,71 +77,70 @@ public class DemoThread extends JMacroThread {
macro.delay();
macro.mouseLeftClick(launch);
} else {
Logger.info("启动图标失败,继续定位主界面");
Logger.error("未定位到图标,可能已进入游戏");
Logger.info("继续定位城镇");
}
Logger.info("定位主界面");
ViewRect = TaskUtil.timeTask(() -> {
while (true) {
macro.delay();
{ // 定位弹框,关闭弹框
ViewRect rect = macro.matchPic(viewRect, "城镇_充值_L448,36", 0.8d);
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("检测到广告弹框,关闭弹框");
}
Logger.info("定位城镇");
// 定位城镇
Boolean inMain = TaskUtil.retryTask(() -> {
{ // 定位弹框,关闭弹框
ViewRect rect = macro.matchPic(viewRect, "城镇_充值_L448,36", 0.8d);
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("检测到充值广告弹框,关闭弹框");
}
{// 定位离线收益
macro.delay();
ViewRect rect = macro.matchPic(viewRect, "城镇_离线收益_L204,734", 0.9);
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
}
{// 定位离线收益
ViewRect rect = macro.matchPic(viewRect, "城镇_离线收益_L204,734", 0.9);
if (rect != null) {
macro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
{// 定位野外
macro.delay();
ViewRect rect = macro.matchPic(viewRect, "野外_L444,888", 0.9);
if (rect != null) {
Logger.info("当前区域【城镇】");
return rect;
}
}
// 定位城镇
{
ViewRect rect = macro.matchPic(viewRect, "城镇_L456,887", 0.9);
if (rect != null) {
Logger.info("当前区域【野外】");
Logger.info("返回区域【城镇】");
macro.mouseLeftClick(rect);
return false;
}
// 定位城镇
{
macro.delay();
ViewRect rect = macro.matchPic(viewRect, "城镇_L456,887", 0.9);
if (rect != null) {
Logger.info("当前区域【野外】");
Logger.info("返回区域【城镇】");
macro.mouseLeftClick(rect);
}
}
{// 定位野外
ViewRect rect = macro.matchPic(viewRect, "野外_L444,888", 0.9);
if (rect != null) {
Logger.info("当前区域【城镇】");
return true;
}
}
}, 30, TimeUnit.SECONDS);
return false;
}, 10, 10);
if ( == null) {
Logger.info("未扫描到主界面:退出线程");
if (!Convert.toBool(inMain, false)) {
Logger.info("未进入城镇:退出线程");
return;
}
Logger.info("进入主界面");
Logger.info("进入城镇成功");
Logger.info("进入任务线程");
while (!Thread.currentThread().isInterrupted()) {
// 欢迎回来弹框
macro.delayNormal();
new Task_线(macro, viewRect).run();
Logger.info("领取探险奖励");
macro.delay();
new Task_线(macro, viewRect).run();
Logger.info("启动循环任务");
while (!Thread.currentThread().isInterrupted()) {
// 矿场攻击检测任务
macro.delayNormal();
macro.delay();
new Task_(macro, viewRect).run();
// 矿场攻击检测任务
macro.delayNormal();
macro.delay();
new Task_(macro, viewRect).run();
// 自动采矿任务
macro.delayNormal();
macro.delay();
new Task_(macro, viewRect).run();
}
}

@ -1,7 +1,13 @@
package com.example.jmacro.wjdr.util;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.example.jmacro.wjdr.base.ViewRect;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
@ -103,4 +109,75 @@ public class ImageUtil {
}
return (double) similar / (smallWidth * smallHeight);
}
public static void main(String[] args) {
try {
Robot robot = new Robot();
BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(0, 0, 1920, 1080));
show(screenCapture);
} catch (AWTException e) {
e.printStackTrace();
}
}
/**
*
*
* @param rect
*/
public static void show(ViewRect rect) {
try {
Robot robot = new Robot();
BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight()));
show(screenCapture);
} catch (AWTException e) {
e.printStackTrace();
}
}
/**
*
*
* @param image
*/
public static void show(BufferedImage image) {
JFrame frame = new JFrame();
BufferedImage read = ImgUtil.read("icon.png");
frame.setIconImage(read);
int viewSize = 500;
Image showImage = image;
// 图片太大时进行缩放显示
if (image.getWidth() > viewSize || image.getHeight() > viewSize) {
if (image.getWidth() > image.getHeight()) {
showImage = ImgUtil.scale(showImage, 1.0f * viewSize / image.getWidth());
} else {
showImage = ImgUtil.scale(showImage, 1.0f * viewSize / image.getHeight());
}
}
ImageIcon imageIcon = new ImageIcon(showImage);
JLabel jLabel = new JLabel(imageIcon);
frame.add(jLabel);
frame.setSize(viewSize, viewSize);
frame.setVisible(true);
boolean[] wait = new boolean[]{true};
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER:
case KeyEvent.VK_ESCAPE: {
wait[0] = false;
frame.setVisible(false);
}
break;
}
}
});
while (wait[0]) {
ThreadUtil.sleep(300);
}
}
}

@ -11,7 +11,7 @@ import cn.hutool.core.util.StrUtil;
*/
public class Logger {
private static boolean isDebug = false;
public static boolean isDebug = false;
public static void setDebug(boolean isDebug) {
Logger.isDebug = isDebug;
@ -28,7 +28,6 @@ public class Logger {
}
public static void error(String log, Object... arg) {
System.err.println(DateUtil.date() + " " + StrUtil.format(log, arg));
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.