自动采集

wjdr
wangbing 1 year ago
parent 79521e8700
commit 467ad6b040

@ -11,5 +11,5 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 743 B

@ -444,6 +444,23 @@ public class JMacro {
return waitAndFindPic(getScreenRect(), file, minSimilar, time, unit);
}
/**
*
*
* @param rect
* @param legendName
* @param minSimilar
* @param time
* @param unit
* @return
*/
public ScreenRect waitAndFindPic(ScreenRect rect, String legendName, double minSimilar, long time, TimeUnit unit) {
if (!legendName.endsWith(".png")) {
legendName = legendName + ".png";
}
return waitAndMatchPic(rect, new File(legend, legendName), minSimilar, time, unit);
}
/**
*
*

@ -12,9 +12,14 @@ import com.example.jmacro.wjdr.base.ScreenRect;
public abstract class JMacroThread implements Runnable {
protected JMacro jMacro;
protected ScreenRect screenRect;
public JMacroThread(JMacro jMacro) {
this.jMacro = jMacro;
this.screenRect = location();
if (this.screenRect == null) {
throw new RuntimeException("未定位到视口区域");
}
}
/**
@ -22,5 +27,13 @@ public abstract class JMacroThread implements Runnable {
*
* @return
*/
public abstract ScreenRect getScreen();
public abstract ScreenRect location();
public ScreenRect getScreenRect() {
return screenRect;
}
public JMacro getMacro() {
return jMacro;
}
}

@ -1,6 +1,5 @@
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.ResourceUtil;
import javafx.application.Application;
@ -32,8 +31,8 @@ public class JMainApplication extends Application {
stage.getIcons().add(icon);
// 展示UI
stage.show();
// 启动服务
JMainService.start();
// 服务初始化
JMainService.init();
}
public static void main(String[] args) {

@ -15,7 +15,7 @@ public class JMainController {
*/
@FXML
private void onCapture() throws AWTException {
ScreenRect screen = JMainService.getInstance().getThread().getScreen();
ScreenRect screen = JMainService.getInstance().getThread().getScreenRect();
File legend = JMainService.getInstance().getMacro().getLegend();
if (screen == null) {
Logger.error("请等待窗口定位");
@ -27,4 +27,20 @@ public class JMainController {
awtException.printStackTrace();
}
}
/**
*
*/
@FXML
private void onStart() throws AWTException {
JMainService.start();
}
/**
*
*/
@FXML
private void onStop() throws AWTException {
JMainService.stop();
}
}

@ -52,7 +52,15 @@ public class JMainService {
*/
private boolean run;
public static void init() {
}
public static void start() throws AWTException {
if (JMainService.getInstance().run) {
Logger.error("服务已启动");
return;
}
// 启动服务
Logger.info("启动服务");
JMainService.getInstance().run = true;
@ -61,6 +69,10 @@ public class JMainService {
}
public static void stop() throws AWTException {
if (!JMainService.getInstance().run) {
Logger.error("服务未启动");
return;
}
Logger.info("停止服务");
JMainService.getInstance().run = false;
JMainService.getInstance().serviceThread.interrupt();

@ -3,9 +3,10 @@ package com.example.jmacro.wjdr.demo;
import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.JMacroThread;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.demo.task.TaskMineAttack;
import com.example.jmacro.wjdr.demo.task.TaskMining;
import com.example.jmacro.wjdr.demo.task.TaskRewards;
import com.example.jmacro.wjdr.demo.task.Task_;
import com.example.jmacro.wjdr.demo.task.Task_线;
import com.example.jmacro.wjdr.demo.task.Task_;
import com.example.jmacro.wjdr.demo.task.Task_;
import com.example.jmacro.wjdr.util.Logger;
import com.example.jmacro.wjdr.util.TaskUtil;
@ -14,11 +15,6 @@ import java.util.concurrent.TimeUnit;
public class DemoThread extends JMacroThread {
/**
*
*/
private ScreenRect gameScreen;
/**
* 线
*/
@ -44,30 +40,31 @@ public class DemoThread extends JMacroThread {
}
@Override
public ScreenRect getScreen() {
return gameScreen;
}
@Override
public void run() {
// 定位mumu bar
Logger.info("定位慕慕窗口");
public synchronized ScreenRect location() {
// 定位窗口
Logger.info("定位窗口");
ScreenRect mumu = jMacro.findPic("慕慕_工具栏", 0.95d);
if (mumu == null) {
throw new IllegalStateException("未检测到MuMu请开启MuMu模拟器");
Logger.error("定位窗口失败");
return null;
}
Logger.info("定位慕慕窗口成功");
// 计算应用窗口返回
gameScreen = new ScreenRect();
ScreenRect gameScreen = new ScreenRect();
gameScreen.setLeft(mumu.getLeft() - 428);
gameScreen.setTop(mumu.getBottom() + 7);
gameScreen.setRight(mumu.getRight());
gameScreen.setBottom(mumu.getBottom() + 951);
Logger.info("应用窗口位置:" + gameScreen.toString());
Logger.info("应用窗口大小:{}x{}", gameScreen.getRight() - gameScreen.getLeft(), gameScreen.getBottom() - gameScreen.getTop());
return gameScreen;
}
@Override
public void run() {
// 获取启动图标
Logger.info("定位启动图标");
ScreenRect launch = jMacro.waitAndFindPic(gameScreen, "启动图标", 0.8);
ScreenRect launch = jMacro.waitAndFindPic(screenRect, "启动图标", 0.9, 5, TimeUnit.SECONDS);
if (launch != null) {
Logger.info("启动图标坐标:", launch.toString());
Logger.info("启动程序");
@ -81,38 +78,45 @@ public class DemoThread extends JMacroThread {
while (true) {
jMacro.delay();
{ // 定位弹框,关闭弹框
Logger.info("检测到广告弹框");
ScreenRect rect = jMacro.matchPic(gameScreen, "城镇_充值_L448,36", 0.8d);
ScreenRect rect = jMacro.matchPic(screenRect, "城镇_充值_L448,36", 0.8d);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到广告弹框,关闭弹框");
}
}
jMacro.delay();
{ // 定位离线收益弹框,关闭弹框
ScreenRect rect = jMacro.matchPic(gameScreen, "城镇_离线收益_L204,734", 0.9);
{// 定位离线收益
jMacro.delay();
ScreenRect rect = jMacro.matchPic(screenRect, "城镇_离线收益_L204,734", 0.9);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
}
jMacro.delay();
// 定位主程序
ScreenRect rect = jMacro.matchPic(gameScreen, "野外_L444,888", 0.9);
if (rect != null) {
Logger.info("程序主界面已就绪");
return rect;
{// 定位野外
jMacro.delay();
ScreenRect rect = jMacro.matchPic(screenRect, "野外_L444,888", 0.9);
if (rect != null) {
Logger.info("当前区域【城镇】");
return rect;
}
}
// 定位城镇
{
jMacro.delay();
ScreenRect rect = jMacro.matchPic(screenRect, "城镇_L456,887", 0.9);
if (rect != null) {
Logger.info("当前区域【野外】");
Logger.info("返回区域【城镇】");
jMacro.mouseLeftClick(rect);
}
}
}
}, 30, TimeUnit.SECONDS);
if ( == null) {
if ( == null && schedule != null) {
schedule.cancel(true);
schedule = null;
Logger.info("未扫描到主界面:退出线程");
return;
}
@ -121,17 +125,21 @@ public class DemoThread extends JMacroThread {
Logger.info("进入任务线程");
TaskUtil.timeTask((Runnable) () -> {
while (true) {
// 欢迎回来弹框
jMacro.delayNormal();
new Task_线(jMacro, screenRect).run();
// 矿场攻击检测任务
jMacro.delayNormal();
new TaskMineAttack(jMacro, gameScreen).run();
new Task_(jMacro, screenRect).run();
// 矿场攻击检测任务
jMacro.delayNormal();
new TaskRewards(jMacro, gameScreen).run();
new Task_(jMacro, screenRect).run();
// 自动采矿任务
jMacro.delayNormal();
new TaskMining(jMacro, gameScreen).run();
new Task_(jMacro, screenRect).run();
}
}, 10, TimeUnit.MINUTES);
}

@ -4,9 +4,9 @@ import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.util.Logger;
public class TaskRewards extends BaseTask {
public class Task_ extends BaseTask {
public TaskRewards(JMacro jMacro, ScreenRect screenRect) {
public Task_(JMacro jMacro, ScreenRect screenRect) {
super(jMacro, screenRect);
}
@ -15,7 +15,7 @@ public class TaskRewards extends BaseTask {
Logger.info("》》》探险奖励领取开始》》》");
Logger.info("定位【探险】按钮");
ScreenRect TAB_ = jMacro.waitAndMatchPic(this.screenRect, "TAB_探险_L35,881", 0.9);
ScreenRect TAB_ = jMacro.waitAndMatchPic(this.screenRect, "城镇_探险_L35,881", 0.9);
if (TAB_ == null) {
return;
}
@ -34,7 +34,6 @@ public class TaskRewards extends BaseTask {
ScreenRect _ = jMacro.waitAndMatchPic(this.screenRect, "探险_不可领取_L420,667", 0.8);
if (_ != null) {
Logger.info("探险不可领取");
return;
} else {
Logger.info("定位领取按钮");
ScreenRect _ = jMacro.waitAndMatchPic(this.screenRect, "探险_领取_L426,667", 0.8);

@ -0,0 +1,25 @@
package com.example.jmacro.wjdr.demo.task;
import com.example.jmacro.wjdr.JMacro;
import com.example.jmacro.wjdr.base.ScreenRect;
import com.example.jmacro.wjdr.util.Logger;
public class Task_线 extends BaseTask {
public Task_线(JMacro jMacro, ScreenRect screenRect) {
super(jMacro, screenRect);
}
@Override
public void run() {
Logger.info("》》》检测离线收益弹框开始》》》");
jMacro.delay();
// 定位离线收益弹框,关闭弹框
ScreenRect rect = jMacro.matchPic(screenRect, "城镇_离线收益_L204,734", 0.9);
if (rect != null) {
jMacro.mouseLeftClick(rect);
Logger.info("检测到离线收益弹框,关闭弹框");
}
Logger.info("》》》检测离线收益弹框结束》》》");
}
}

@ -8,9 +8,9 @@ import com.example.jmacro.wjdr.util.Logger;
import java.io.File;
public class TaskMining extends BaseTask {
public class Task_ extends BaseTask {
public TaskMining(JMacro jMacro, ScreenRect screenRect) {
public Task_(JMacro jMacro, ScreenRect screenRect) {
super(jMacro, screenRect);
}
@ -24,12 +24,12 @@ public class TaskMining extends BaseTask {
Logger.info("当前界面【野外】");
} else {
Logger.info("定位【野外】");
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_L449,885", 0.99);
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_L444,888", 0.99);
if ( == null) {
Logger.error("定位【野外】失败,采矿终止");
return;
}
Logger.error("定位【野外】成功,{}", .toString());
Logger.info("定位【野外】成功,{}", .toString());
Logger.info("点击【野外】,坐标{}", JSONUtil.toJsonStr(.getCenter()));
jMacro.mouseLeftClick();
@ -37,7 +37,7 @@ public class TaskMining extends BaseTask {
}
Logger.info("定位资源搜索按钮");
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_搜索_L15,632", 0.8);
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_搜索_L33,636", 0.5);
if ( == null) {
Logger.error("未检测到【资源搜索按钮】,采矿终止");
return;
@ -57,7 +57,7 @@ public class TaskMining extends BaseTask {
}
// 检测是否是搜索界面
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_搜索_L233,881", 0.98);
ScreenRect = jMacro.waitAndMatchPic(this.screenRect, "野外_搜索_L18,633", 9);
if ( != null) {
Logger.info("退出资源搜索界面");
jMacro.mouseLeftClick(this.screenRect);

@ -4,9 +4,9 @@ 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 class Task_ extends BaseTask {
public TaskMineAttack(JMacro jMacro, ScreenRect screenRect) {
public Task_(JMacro jMacro, ScreenRect screenRect) {
super(jMacro, screenRect);
}

@ -214,9 +214,8 @@ public class Capture extends JFrame {
}
public void close() {
// 关闭应用时要释放资源
setVisible(false);
dispose();
System.exit(0);
}
/**

@ -1,45 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<AnchorPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.jmacro.wjdr.JMainController">
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.jmacro.wjdr.JMainController">
<children>
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="任务" />
<Button mnemonicParsing="false" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="60.0" text="开始">
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
<Button mnemonicParsing="false" onMouseClicked="#onStop" prefHeight="30.0" prefWidth="60.0" text="停止">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" />
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="工具"/>
<Button mnemonicParsing="false" prefHeight="30.0" prefWidth="80.0" text="采集图例" onMouseClicked="#onCapture">
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="工具" />
<Button mnemonicParsing="false" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="80.0" text="采集图例">
<HBox.margin>
<Insets/>
<Insets />
</HBox.margin>
</Button>
</children>
</HBox>
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
<GridPane layoutX="71.0" layoutY="139.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0">
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" />
<GridPane layoutX="71.0" layoutY="139.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="82.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>

Loading…
Cancel
Save

Powered by TurnKey Linux.