上传备份

wjdr
王兵 1 year ago
parent 350d9c1180
commit a92b480d50

@ -2,6 +2,8 @@
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources/lib" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

@ -49,6 +49,15 @@
<artifactId>jintellitype</artifactId>
<version>1.4.0</version>
</dependency>
<!-- 皮肤依赖 -->
<dependency>
<groupId>org.jb2011.lnf</groupId>
<artifactId>beautyeye</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/beautyeye_lnf.jar</systemPath>
</dependency>
</dependencies>
<build>

@ -114,7 +114,7 @@ public class JMacro {
public void mouseLeftClick(ScreenPoint rect) {
mouseMove(rect);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
waitTap();
delayTap();
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
@ -146,11 +146,11 @@ public class JMacro {
*/
public void mouseLeftDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
mouseMove(start, smooth);
waitTap();
delayTap();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
waitTap();
delayTap();
mouseMove(end, smooth);
waitTap();
delayTap();
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
@ -173,11 +173,11 @@ public class JMacro {
*/
public void mouseRightDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
mouseMove(start, smooth);
waitTap();
delayTap();
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
waitTap();
delayTap();
mouseMove(end, smooth);
waitTap();
delayTap();
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
}
@ -187,11 +187,11 @@ public class JMacro {
* @param rect
*/
public void mouseWheelClick(ScreenRect rect) {
waitTap();
delayTap();
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
waitTap();
delayTap();
robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
waitTap();
delayTap();
robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
}
@ -201,11 +201,11 @@ public class JMacro {
* @param rect
*/
public void mouseRightClick(ScreenRect rect) {
waitTap();
delayTap();
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
waitTap();
delayTap();
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
waitTap();
delayTap();
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
}
@ -215,9 +215,9 @@ public class JMacro {
* @param rect
*/
public void mouseLeftDoubleClick(ScreenRect rect) {
waitTap();
delayTap();
robot.mouseMove(rect.getCenter()[0], rect.getCenter()[1]);
waitTap();
delayTap();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(100);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
@ -242,6 +242,20 @@ public class JMacro {
return new ScreenRect(0, 0, tk.getScreenSize().width, tk.getScreenSize().height);
}
/**
*
*
* @param legendName
* @param minSimilar
* @return
*/
public ScreenRect findPic(String legendName, double minSimilar) {
if (!legendName.endsWith(".png")) {
legendName = legendName + ".png";
}
return findPic(new File(legend, legendName), minSimilar);
}
/**
*
*
@ -264,6 +278,31 @@ public class JMacro {
return findPic(getScreenRect(), pic, minSimilar);
}
/**
*
*
* @param screenRect
* @param legendName
* @param minSimilar
* @return
*/
public ScreenRect findPic(ScreenRect screenRect, String legendName, double minSimilar) {
return findPic(screenRect, new File(legend, legendName), minSimilar);
}
/**
*
*
* @param screenRect
* @param legend
* @param minSimilar
* @return
*/
public ScreenRect findPic(ScreenRect screenRect, File legend, double minSimilar) {
return findPic(screenRect, Imager.load(legend), minSimilar);
}
/**
*
*
@ -316,18 +355,23 @@ public class JMacro {
return null;
}
public void waitTap() {
int i = RandomUtil.randomInt(100, 200);
public void delay() {
delayNormal();
}
public void delayTap() {
int i = RandomUtil.randomInt(100, 500);
robot.delay(i);
}
public void waitNormal() {
public void delayNormal() {
int i = RandomUtil.randomInt(500, 1500);
robot.delay(i);
}
public void waitLong() {
int i = RandomUtil.randomInt(2000, 5000);
public void delayLong() {
int i = RandomUtil.randomInt(1500, 3000);
robot.delay(i);
}
@ -354,6 +398,21 @@ public class JMacro {
return waitAndFindPic(rect, file, minSimilar, 10, TimeUnit.SECONDS);
}
/**
*
*
* @param rect
* @param legendName
* @param minSimilar
* @return
*/
public ScreenRect waitAndFindPic(ScreenRect rect, String legendName, double minSimilar) {
if (!legendName.endsWith(".png")) {
legendName = legendName + ".png";
}
return waitAndFindPic(rect, new File(legend, legendName), minSimilar, 10, TimeUnit.SECONDS);
}
/**
*
*
@ -390,7 +449,7 @@ public class JMacro {
}
while (true) {
waitTap();
delayTap();
ScreenRect pic = findPic(rect, image, minSimilar);
if (pic != null) {
return pic;
@ -463,5 +522,4 @@ public class JMacro {
}
return matchPic(rect, new File(legend, legendName), minSimilar) != null;
}
}

@ -1,17 +1,19 @@
package com.example.jmacro.wjdr;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.task.TaskMineAttack;
import com.example.jmacro.wjdr.task.TaskMining;
import com.example.jmacro.wjdr.util.Imager;
import com.example.jmacro.wjdr.util.Logger;
import com.example.jmacro.wjdr.util.TaskUtil;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -22,7 +24,7 @@ import java.util.concurrent.TimeUnit;
* @version 0.0.1
* @since 1.8
*/
public class MainTask {
public class MainTask extends JFrame {
/**
* 线
@ -41,36 +43,80 @@ public class MainTask {
private boolean noDelay = true;
private JMacro jMacro;
public void start() throws AWTException {
// 加载主题
try {
org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
} catch (Exception e) {
e.printStackTrace();
}
// 设置标题
setTitle("无限工具");
// 设置图标
URL icon = this.getClass().getClassLoader().getResource("icon.png");
setIconImage(ImgUtil.read(icon));
// 脚本初始化
Logger.info("初始化脚本");
jMacro = new JMacro(new File("legend"));
// 设置窗口的宽度和高度
setSize(400, 300); // 设置窗口的宽度为400像素高度为300像素
// 添加一个标签作为示例内容
getContentPane().add(new JLabel("Hello, Swing!"));
// 设置窗口关闭时的操作
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 启动后台线程
startBack();
center();
// 显示窗口
setVisible(true);
}
/**
*
*/
private void center() {
// 获取屏幕尺寸
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// 获取窗口尺寸
java.awt.Dimension frameSize = getSize();
// 计算窗口居中位置
setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
/**
* 线
*/
public void startBack() {
Logger.setDebug(true);
Logger.info("初始化脚本");
JMacro jMacro = new JMacro(new File("legend"));
new Thread(() -> {
while (true) {
ThreadUtil.sleep(1000);
while (true) {
ThreadUtil.sleep(1000);
// 立即执行
if (noDelay) {
if (schedule != null) {
schedule.cancel(true);
}
// 立即执行
if (noDelay) {
noDelay = false;
Logger.info("启动线程");
schedule = TaskUtil.schedule(new MacroThread(jMacro), 0, TimeUnit.SECONDS);
continue;
}
if (schedule != null) {
schedule.cancel(true);
continue;
}
noDelay = false;
Logger.info("启动线程");
schedule = TaskUtil.schedule(new MacroThread(jMacro), 0, TimeUnit.SECONDS);
continue;
}
if (schedule != null) {
continue;
}
if (DateUtil.isIn(DateUtil.date(), DateUtil.parse(workStart), DateUtil.parse(workEnd))) {
int delay = RandomUtil.randomInt(5, 20);
Logger.info("等待{}分钟后,重新启动线程", delay);
schedule = TaskUtil.schedule(new MacroThread(jMacro), delay, TimeUnit.MINUTES);
if (DateUtil.isIn(DateUtil.date(), DateUtil.parse(workStart), DateUtil.parse(workEnd))) {
int delay = RandomUtil.randomInt(5, 20);
Logger.info("等待{}分钟后,重新启动线程", delay);
schedule = TaskUtil.schedule(new MacroThread(jMacro), delay, TimeUnit.MINUTES);
}
}
}
}).start();
}
/**
@ -87,12 +133,12 @@ public class MainTask {
super(jMacro);
// 定位mumu bar
Logger.info("定位慕慕窗口");
ScreenRect mumu = locationMuMu(jMacro);
ScreenRect mumu = jMacro.findPic("慕慕_工具栏", 0.95d);
if (mumu == null) {
throw new IllegalStateException("未检测到MuMu请开启MuMu模拟器");
}
Logger.info("定位慕慕窗口成功");
// 获取窗口返回
// 计算应用窗口返回
gameScreen = new ScreenRect();
gameScreen.setLeft(mumu.getLeft() - 428);
gameScreen.setTop(mumu.getBottom() + 7);
@ -106,10 +152,11 @@ public class MainTask {
public void run() {
// 获取启动图标
Logger.info("定位启动图标");
ScreenRect launch = jMacro.waitAndFindPic(gameScreen, new File("legend", "启动图标.png"), 0.8, 5, TimeUnit.SECONDS);
ScreenRect launch = jMacro.waitAndFindPic(gameScreen, "启动图标", 0.8);
if (launch != null) {
Logger.info("启动图标坐标:", launch.toString());
Logger.info("启动程序");
jMacro.delay();
jMacro.mouseLeftClick(launch);
} else {
Logger.info("启动图标失败,继续定位主界面");
@ -117,11 +164,31 @@ public class MainTask {
Logger.info("定位主界面");
ScreenRect = TaskUtil.timeTask(() -> {
while (true) {
ScreenRect screenRect1 = locationHome(jMacro, gameScreen);
if (screenRect1 != null) {
return screenRect1;
jMacro.delay();
{ // 定位弹框,关闭弹框
ScreenRect rect = jMacro.findPic(gameScreen, "首页_广告关闭按钮", 0.95d);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到广告弹框,关闭弹框");
}
}
jMacro.delay();
{ // 定位离线收益弹框,关闭弹框
ScreenRect rect = jMacro.matchPic(gameScreen, new File("legend", "L204,734-城镇_离线收益.png"), 0.9);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
}
jMacro.delay();
// 定位主程序
ScreenRect rect = jMacro.matchPic(gameScreen, new File("legend", "L444,888-野外.png"), 0.9);
if (rect != null) {
Logger.info("程序主界面已就绪");
return rect;
}
ThreadUtil.sleep(1000);
}
}, 30 * 1000, TimeUnit.MILLISECONDS);
@ -129,6 +196,7 @@ public class MainTask {
schedule.cancel(true);
schedule = null;
Logger.info("未扫描到主界面:退出线程");
return;
}
@ -137,62 +205,20 @@ public class MainTask {
Logger.info("进入任务线程");
TaskUtil.timeTask((Runnable) () -> {
while (true) {
jMacro.waitNormal();
Logger.info("检测矿场攻击状态开始");
taskMineAttack(jMacro, gameScreen);
Logger.info("检测矿场攻击状态结束");
// 矿场攻击检测任务
jMacro.delayNormal();
new TaskMineAttack(jMacro, gameScreen).run();
// 自动采矿
Logger.info("自动采矿开始");
new TaskMining(jMacro, gameScreen).start();
Logger.info("自动采矿结束");
// 自动采矿任务
jMacro.delayNormal();
new TaskMining(jMacro, gameScreen).run();
}
}, 10, TimeUnit.MINUTES);
}
}
public static ScreenRect locationHome(JMacro jMacro, ScreenRect gameScreen) {
{ // 定位弹框,关闭弹框
BufferedImage image = Imager.load(new File("legend", "首页_广告关闭按钮.png"));
ScreenRect rect = jMacro.findPic(gameScreen, image, 0.95d);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到广告弹框,关闭弹框");
}
}
{ // 定位离线收益弹框,关闭弹框
ScreenRect rect = jMacro.matchPic(gameScreen, new File("legend", "L204,734-城镇_离线收益.png"), 0.9);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
}
{ // 定位主程序
ScreenRect rect = jMacro.matchPic(gameScreen, new File("legend", "L444,888-野外.png"), 0.9);
if (rect != null) {
Logger.info("程序主界面已就绪");
return rect;
}
}
return null;
}
public static ScreenRect locationMuMu(JMacro jMacro) {
BufferedImage image = Imager.load(new File("legend", "慕慕_工具栏.png"));
return jMacro.findPic(image, 0.95d);
}
/**
*
*/
public static void taskMineAttack(JMacro jMacro, ScreenRect screenRect) {
}
/**
*
*/

@ -0,0 +1,22 @@
package com.example.jmacro.wjdr.task;
import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ScreenRect;
public abstract class BaseTask implements Runnable {
/**
*
*/
protected JMacro jMacro;
/**
*
*/
protected ScreenRect screenRect;
public BaseTask(JMacro jMacro, ScreenRect screenRect) {
this.jMacro = jMacro;
this.screenRect = screenRect;
}
}

@ -0,0 +1,19 @@
package com.example.jmacro.wjdr.task;
import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.util.Logger;
public class TaskMineAttack extends BaseTask {
public TaskMineAttack(JMacro jMacro, ScreenRect screenRect) {
super(jMacro, screenRect);
}
@Override
public void run() {
Logger.info("》》》检测被攻击状态开始》》》");
Logger.info("未实现,跳过");
Logger.info("》》》检测被攻击状态结束》》》");
}
}

@ -8,17 +8,14 @@ import com.example.jmacro.wjdr.util.Logger;
import java.io.File;
public class TaskMining {
private JMacro jMacro;
private ScreenRect screenRect;
public class TaskMining extends BaseTask {
public TaskMining(JMacro jMacro, ScreenRect screenRect) {
this.jMacro = jMacro;
this.screenRect = screenRect;
super(jMacro, screenRect);
}
public void start() {
@Override
public void run() {
Logger.info("》》》自动采矿开始》》》");
Logger.info("定位【野外】");
@ -81,13 +78,13 @@ public class TaskMining {
}
Logger.info("定位【{}】图标成功", type);
Logger.info("单击【{}】图标,坐标[{},{}]",type, typeRect.getCenter()[0], typeRect.getCenter()[1]);
Logger.info("单击【{}】图标,坐标[{},{}]", type, typeRect.getCenter()[0], typeRect.getCenter()[1]);
jMacro.mouseLeftClick(typeRect);
if (level == 0) {
ScreenRect = jMacro.waitAndFindPic(screenRect, new File("legend", "野外_资源_-.png"), 0.98);
while ( != null) {
jMacro.waitTap();
jMacro.delayTap();
jMacro.mouseLeftClick();
= jMacro.waitAndFindPic(screenRect, new File("legend", "野外_资源_-.png"), 0.98);
}
@ -128,8 +125,4 @@ public class TaskMining {
jMacro.mouseLeftClick();
return true;
}
public static void main(String[] args) {
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Loading…
Cancel
Save

Powered by TurnKey Linux.