|
|
|
|
@ -12,7 +12,6 @@ import org.sikuli.script.Mouse;
|
|
|
|
|
import org.sikuli.script.Pattern;
|
|
|
|
|
import org.sikuli.script.Region;
|
|
|
|
|
import org.sikuli.script.Screen;
|
|
|
|
|
import xyz.wbsite.jmacro.base.ColorLocation;
|
|
|
|
|
import xyz.wbsite.jmacro.base.Legend;
|
|
|
|
|
import xyz.wbsite.jmacro.util.Logger;
|
|
|
|
|
import xyz.wbsite.jmacro.util.MousePathUtil;
|
|
|
|
|
@ -398,6 +397,24 @@ public abstract class JMacro {
|
|
|
|
|
return new Region(match.getRect());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在区域查找图片
|
|
|
|
|
*
|
|
|
|
|
* @param region 区域
|
|
|
|
|
* @param legend 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public Region findLegend(Region region, String legend, double minSimilar) {
|
|
|
|
|
Pattern pattern = new Pattern(of(legend).getFile().getAbsolutePath())
|
|
|
|
|
.similar(minSimilar);
|
|
|
|
|
Match match = region.findBest(pattern);
|
|
|
|
|
if (match == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Region(match.getRect());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并查找图例
|
|
|
|
|
*
|
|
|
|
|
@ -419,6 +436,63 @@ public abstract class JMacro {
|
|
|
|
|
}, timeout, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图例组合匹配,图例区域结果和入参长度一致,任意图例检测到后则会返回,其他未检测到的区域则为null
|
|
|
|
|
* <p>
|
|
|
|
|
* 说明:一个操作之后可能会有多个预期结果,以发起【进攻】操作为例,可能会提示多种结果如下:
|
|
|
|
|
* 1.成功发起
|
|
|
|
|
* 2.敌人已逃走
|
|
|
|
|
* 3.兵力不足
|
|
|
|
|
* 不同的操作返回结果,会有不同的后续操作;如果以获取某预期结果去检测,考虑处理时间延迟等需要加上等待时间
|
|
|
|
|
* 不同结果的获取就会依次串行,这样检查肯定会浪费大量检测时间。因此正对此情况做了并联检测机制。
|
|
|
|
|
*
|
|
|
|
|
* @param legends 图例
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @return 匹配图片
|
|
|
|
|
*/
|
|
|
|
|
public Region[] matchLegends(String[] legends, double minSimilar) {
|
|
|
|
|
Region[] viewRects = new Region[legends.length];
|
|
|
|
|
for (int i = 0; i < legends.length; i++) {
|
|
|
|
|
String legend = legends[i];
|
|
|
|
|
viewRects[i] = findLegend(legend, minSimilar);
|
|
|
|
|
if (viewRects[i] != null) {
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例组合
|
|
|
|
|
*
|
|
|
|
|
* @param legends 图例组
|
|
|
|
|
* @param minSimilar 最低相似度
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配区域
|
|
|
|
|
*/
|
|
|
|
|
public Region[] waitAndMatchLegends(String[] legends, double minSimilar, long seconds) {
|
|
|
|
|
if (legends.length == 0) {
|
|
|
|
|
return new Region[0];
|
|
|
|
|
}
|
|
|
|
|
Logger.info("等待并匹配图例组合:{}", String.join(",", legends));
|
|
|
|
|
Region[] result = TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
Region[] viewRects = matchLegends(legends, minSimilar);
|
|
|
|
|
for (Region viewRect : viewRects) {
|
|
|
|
|
if (viewRect != null) {
|
|
|
|
|
return viewRects;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Region[legends.length];
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
if (result == null) {
|
|
|
|
|
result = new Region[legends.length];
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查找并点击图例
|
|
|
|
|
*
|
|
|
|
|
@ -457,27 +531,6 @@ public abstract class JMacro {
|
|
|
|
|
return new Location(x + ox, y + oy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为绝对坐标
|
|
|
|
|
*
|
|
|
|
|
* @param relativePoint 相对坐标
|
|
|
|
|
* @return 绝对区域
|
|
|
|
|
*/
|
|
|
|
|
public Location of(Location relativePoint) {
|
|
|
|
|
return of(relativePoint.getX(), relativePoint.getY());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为色值坐标
|
|
|
|
|
*
|
|
|
|
|
* @return 绝对坐标
|
|
|
|
|
*/
|
|
|
|
|
public ColorLocation of(int x, int y, String hexColor) {
|
|
|
|
|
int ox = getWorkRegion().getX();
|
|
|
|
|
int oy = getWorkRegion().getY();
|
|
|
|
|
return new ColorLocation(x + ox, y + oy, hexColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为色值坐标
|
|
|
|
|
*
|
|
|
|
|
@ -487,16 +540,6 @@ public abstract class JMacro {
|
|
|
|
|
return legends;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为色值坐标
|
|
|
|
|
*
|
|
|
|
|
* @param relativePoint 相对坐标
|
|
|
|
|
* @return 绝对区域
|
|
|
|
|
*/
|
|
|
|
|
public ColorLocation of(Location relativePoint, String hexColor) {
|
|
|
|
|
return of(relativePoint.getX(), relativePoint.getY(), hexColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取随机中心坐标
|
|
|
|
|
*
|
|
|
|
|
|