自动采集

wjdr
wangbing 1 year ago
parent 9a71ce99ee
commit cf2bad116d

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

@ -108,15 +108,14 @@ 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());
int endX = point.getX();
int endY = point.getY();
if (smooth) {
// 获取当前鼠标位置
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
int startX = mousePoint.x;
int startY = mousePoint.y;
// 求两点距离
double absX = Math.abs(startX - endX);
double absY = Math.abs(startY - endY);
@ -156,7 +155,7 @@ public abstract class JMacro {
* @param rect
*/
public void mouseLeftClick(ViewRect rect) {
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1], true));
mouseLeftClick(new ViewPoint(rect.getCenter()[0], rect.getCenter()[1]));
}
/**
@ -178,11 +177,11 @@ public abstract class JMacro {
*/
public void mouseLeftDrag(ViewPoint start, ViewPoint end, boolean smooth) {
mouseMove(start, smooth);
delayUnstable();
delay();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
delayUnstable();
delay();
mouseMove(end, smooth);
delayUnstable();
delay();
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
@ -347,6 +346,18 @@ public abstract class JMacro {
return findPic(getFocusRect(), pic, minSimilar);
}
/**
*
*
* @param viewRect
* @param pic
* @param minSimilar
* @return
*/
public ViewRect findPic(ViewRect viewRect, File pic, double minSimilar) {
return findPic(viewRect, ImageUtil.load(pic), minSimilar);
}
/**
*
*
@ -371,6 +382,7 @@ public abstract class JMacro {
// 获取实时屏幕
BufferedImage screen = capture(robot, viewRect);
ImageUtil.show(screen);
int[][] screenData = ImageUtil.getImageRGB(screen);
int[][] picData = ImageUtil.getImageRGB(pic);
@ -416,6 +428,72 @@ public abstract class JMacro {
return null;
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect findLegend(String legend, double minSimilar) {
return findLegend(Legend.inflate(legend), minSimilar);
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect findLegend(Legend legend, double minSimilar) {
return findPic(legend.getFile(), minSimilar);
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect findLegend(ViewRect rect, String legend, double minSimilar) {
return findLegend(rect, Legend.inflate(legend), minSimilar);
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect findLegend(ViewRect rect, Legend legend, double minSimilar) {
return findPic(rect, legend.getFile(), minSimilar);
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect waitAndFindLegend(Legend legend, double minSimilar, long seconds) {
return waitAndFindPic(legend.getFile(), minSimilar, seconds);
}
/**
*
*
* @param legend
* @param minSimilar
* @return
*/
public ViewRect waitAndFindLegend(ViewRect rect, Legend legend, double minSimilar, long seconds) {
return waitAndFindPic(rect, legend.getFile(), minSimilar, seconds);
}
/**
*
*
@ -743,4 +821,46 @@ public abstract class JMacro {
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar, long seconds) {
return waitAndMatchPic(legend.getFile(), legend.getLocation(), minSimilar, seconds);
}
/**
*
*
* @return
*/
public ViewRect of(int left, int top, int right, int bottom) {
int ox = getFocusRect().getLeft();
int oy = getFocusRect().getTop();
return new ViewRect(left + ox, top + oy, right + ox, bottom + oy);
}
/**
*
*
* @param relativeRect
* @return
*/
public ViewRect of(ViewRect relativeRect) {
return new ViewRect(relativeRect.getLeft(), relativeRect.getTop(), relativeRect.getRight(), relativeRect.getBottom());
}
/**
*
*
* @return
*/
public ViewPoint of(int x, int y) {
int ox = getFocusRect().getLeft();
int oy = getFocusRect().getTop();
return new ViewPoint(x + ox, y + oy);
}
/**
*
*
* @param relativePoint
* @return
*/
public ViewPoint of(ViewPoint relativePoint) {
return of(relativePoint.getX(), relativePoint.getY());
}
}

@ -68,17 +68,7 @@ public class JMainApplication extends Application {
});
// 服务初始化
JMainService.init(new JMacro() {
@Override
public ViewRect focus() {
return new ViewRect(0,0,500,500);
}
@Override
public void run() {
}
}, new File("legend"));
JMainService.init(new MacroForWJDR(), new File("legend"));
}
public static void main(String[] args) {

@ -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, false);
newLegend.location = new ViewPoint(x, y);
}
fileCache.put(name, newLegend);

@ -9,11 +9,6 @@ package com.example.jmacro.wjdr.base;
*/
public class ViewPoint {
/**
*
*/
private boolean absolute;
/**
* ()x
*/
@ -34,13 +29,8 @@ public class ViewPoint {
* @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() {
@ -59,14 +49,6 @@ 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{" +

@ -100,8 +100,8 @@ public class Location extends JFrame {
x = e.getX();
y = e.getY();
Logger.info("坐标采集:");
Logger.info("屏幕坐标:[{},{}]用法new ViewPoint({},{},true)", x, y, x, y);
Logger.info("相对坐标:[{},{}],用法:new ViewPoint({},{})", x - originX, y - originY, x - originX, y - originY);
Logger.info("屏幕坐标:[{},{}]", x, y);
Logger.info("相对坐标:[{},{}],用法:macro.of({},{})", x - originX, y - originY, x - originX, y - originY);
String hexColor = Integer.toHexString(capture.getRGB(x, y) & 0xFFFFFF);
Logger.info("坐标色值:[#{}]", hexColor);
close();

@ -75,7 +75,7 @@ public class MacroForWJDR extends JMacro {
Boolean inMain = TaskUtil.retryTask(() -> {
{ // 定位弹框,关闭弹框
delayUnstable();
ViewRect rect = matchLegend("城镇_充值", 0.8d);
ViewRect rect = findLegend("城镇_礼包", 0.7);
if (rect != null) {
mouseLeftClick(rect);
Logger.info("检测到充值广告弹框,关闭弹框");

@ -37,7 +37,7 @@ public class Task_自动采矿 extends BaseTask {
Logger.info("点击资源搜索按钮");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(33, 648));
macro.mouseLeftClick(macro.of(33, 648));
Logger.info("等待搜索面板");
ViewRect _ = macro.waitAndMatchLegend("野外_搜索", 0.9);
@ -47,7 +47,7 @@ public class Task_自动采矿 extends BaseTask {
}
Logger.info("拖动面板");
macro.mouseLeftDrag(new ViewPoint(433, 679), new ViewPoint(61, 682), true);
macro.mouseLeftDrag(macro.of(433, 679), macro.of(61, 682), true);
Logger.info("开始采集资源");
String[] types = new String[]{
@ -98,14 +98,14 @@ public class Task_自动采矿 extends BaseTask {
TaskUtil.execTask(() -> {
Logger.info("调整等级");
macro.delayUnstable(700);
macro.mouseLeftClick(new ViewPoint(51, 777));
macro.mouseLeftClick(macro.of(51, 777));
}, clevel - level, 1000);
}
if (clevel < level) {
TaskUtil.execTask(() -> {
Logger.info("调整等级");
macro.delayUnstable(700);
macro.mouseLeftClick(new ViewPoint(360, 777));
macro.mouseLeftClick(macro.of(360, 777));
}, level - clevel, 1000);
}
@ -126,7 +126,7 @@ public class Task_自动采矿 extends BaseTask {
macro.delayUnstable(1000);
ViewRect[] viewRects = macro.matchLegend("野外_资源出征", "野外_资源无对队列");
ViewRect[] viewRects = macro.matchLegend("野外_资源出征", "野外_资源无对队列", "野外_资源无士兵");
if (viewRects[0] != null) {
Logger.info("出征");
@ -135,11 +135,17 @@ public class Task_自动采矿 extends BaseTask {
if (viewRects[1] != null) {
Logger.info("队列已满,取消采集");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(471, 250));
macro.mouseLeftClick(macro.of(471, 250));
Logger.info("队列已满,取消采集");
macro.delayUnstable(1000);
macro.mouseLeftClick(new ViewPoint(471, 250));
macro.mouseLeftClick(macro.of(471, 250));
return false;
}
if (viewRects[2] != null) {
Logger.info("士兵不足,取消采集");
macro.delayUnstable(1000);
macro.mouseLeftClick(macro.of(32,30));
return false;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.