update:重构脚本执行方式
This commit is contained in:
@@ -3,47 +3,58 @@ package com.yutou.qqbot.Controllers;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.data.JianRScriptData;
|
||||
import com.yutou.qqbot.data.jianr.AndroidDevice;
|
||||
import com.yutou.qqbot.data.jianr.JianRScriptV2Data;
|
||||
import com.yutou.qqbot.utlis.JianRTaskManager;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class JianRScriptController {
|
||||
@RequestMapping("/jianr/run.do")
|
||||
@ResponseBody
|
||||
public JSONObject runScript(String task) {
|
||||
public JSONObject runScript(String task, String device, String modelName) {
|
||||
JSONObject json = new JSONObject();
|
||||
String data = RedisTools.get("jianrScript_Model_" + task);
|
||||
if (data == null) {
|
||||
String data = RedisTools.getHashMap(JianRTaskManager.Redis_Script, task);
|
||||
String deviceJsonString = RedisTools.getHashMap(JianRTaskManager.Redis_Device, device);
|
||||
if (data == null || deviceJsonString == null) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "没有找到该方案,请配置");
|
||||
json.put("msg", "没有找到该方案或设备错误,请配置");
|
||||
} else {
|
||||
JianRScriptData script = JSON.parseObject(data, JianRScriptData.class);
|
||||
JianRScriptV2Data script = JSON.parseObject(data, JianRScriptV2Data.class);
|
||||
AndroidDevice androidDevice = JSON.parseObject(deviceJsonString, AndroidDevice.class);
|
||||
JianRTaskManager manager = JianRTaskManager.getInstance();
|
||||
if (manager.isRunning()) {
|
||||
manager.stop();
|
||||
}
|
||||
manager.setTask(script);
|
||||
for (int i = 0; i < androidDevice.getDeviceDisplay().size(); i++) {
|
||||
if (androidDevice.getDeviceDisplay().get(i).getTitle().equals(modelName)) {
|
||||
manager.setModelId(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
manager.setTask(script, androidDevice);
|
||||
manager.start();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务创建成功");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/stop.do")
|
||||
@ResponseBody
|
||||
public JSONObject stop(){
|
||||
public JSONObject stop() {
|
||||
JianRTaskManager.getInstance().stop();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务已停止");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/status.do")
|
||||
@ResponseBody
|
||||
public JSONObject status() {
|
||||
@@ -64,8 +75,8 @@ public class JianRScriptController {
|
||||
public JSONObject tasks() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
Set<String> jianrScript_model = RedisTools.list_get("jianrScript_Model");
|
||||
array.addAll(jianrScript_model);
|
||||
Map<String, String> map = RedisTools.getHashMap(JianRTaskManager.Redis_Script);
|
||||
array.addAll(map.keySet());
|
||||
json.put("code", 0);
|
||||
json.put("data", array);
|
||||
return json;
|
||||
@@ -80,35 +91,150 @@ public class JianRScriptController {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
String taskName = data.getString("name");
|
||||
if (RedisTools.list_isExist("jianrScript_Model", taskName)) {
|
||||
String taskName = data.getString("title");
|
||||
if (RedisTools.getHashMap(JianRTaskManager.Redis_Script).containsKey(taskName)) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "该任务名称已存在");
|
||||
} else {
|
||||
RedisTools.list_add("jianrScript_Model", taskName);
|
||||
RedisTools.set("jianrScript_Model_"+taskName,task);
|
||||
RedisTools.setHashMap(JianRTaskManager.Redis_Script, taskName, task);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务创建成功");
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
@RequestMapping("/jianr/task/get.do")
|
||||
@ResponseBody
|
||||
public JSONObject getTask (String task){
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("data", RedisTools.get("jianrScript_Model_" + task));
|
||||
return json;
|
||||
}
|
||||
@RequestMapping("/jianr/task/remove.do")
|
||||
@ResponseBody
|
||||
public JSONObject removeTask (String task){
|
||||
RedisTools.remove("jianrScript_Model_" + task);
|
||||
RedisTools.list_remove("jianrScript_Model", task);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务删除成功");
|
||||
return json;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/get.do")
|
||||
@ResponseBody
|
||||
public JSONObject getTask(String task) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("data", RedisTools.getHashMap(JianRTaskManager.Redis_Script, task));
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/remove.do")
|
||||
@ResponseBody
|
||||
public JSONObject removeTask(String task) {
|
||||
RedisTools.removeHashMap(JianRTaskManager.Redis_Script, task);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务删除成功");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/connect.do")
|
||||
@ResponseBody
|
||||
public JSONObject connectDevice(String device) {
|
||||
JSONObject json = new JSONObject();
|
||||
JianRTaskManager.getInstance().connect(device);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "成功");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/add.do")
|
||||
@ResponseBody
|
||||
public JSONObject addDevice(String device) {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
if (hashMap.containsKey(device)) {
|
||||
json.put("msg", "设备已存在");
|
||||
} else {
|
||||
json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device,
|
||||
deviceJson.getString("title"), device) ?
|
||||
"设备添加成功" : "设备添加失败");
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/edit.do")
|
||||
@ResponseBody
|
||||
public JSONObject editDevice(String device, String oldDevice) {
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
RedisTools.removeHashMap(JianRTaskManager.Redis_Device, oldDevice);
|
||||
json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device,
|
||||
deviceJson.getString("title"), device) ?
|
||||
"设备修改成功" : "设备修改失败");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/del.do")
|
||||
@ResponseBody
|
||||
public JSONObject delDevice(String device) {
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
json.put("msg", RedisTools.removeHashMap(JianRTaskManager.Redis_Device) ?
|
||||
"设备修改成功" : "设备修改失败");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/list.do")
|
||||
@ResponseBody
|
||||
public JSONObject getDeviceList() {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
json.put("code", 0);
|
||||
hashMap.keySet().forEach(key -> {
|
||||
JSONObject device = JSONObject.parseObject(hashMap.get(key));
|
||||
JSONArray child = new JSONArray();
|
||||
JSONObject item = new JSONObject();
|
||||
JSONObject del = new JSONObject();
|
||||
JSONObject edit = new JSONObject();
|
||||
JSONObject select = new JSONObject();
|
||||
JSONObject connect = new JSONObject();
|
||||
item.put("title", key);
|
||||
del.put("title", "删除");
|
||||
del.put("data", "del");
|
||||
del.put("device", device);
|
||||
edit.put("title", "编辑");
|
||||
edit.put("data", "edit");
|
||||
edit.put("device", device);
|
||||
select.put("title", "选择");
|
||||
select.put("data", "select");
|
||||
select.put("device", device);
|
||||
connect.put("title", "连接设备");
|
||||
connect.put("data", "connect");
|
||||
connect.put("device", device);
|
||||
child.add(connect);
|
||||
child.add(select);
|
||||
child.add(del);
|
||||
child.add(edit);
|
||||
item.put("child", child);
|
||||
array.add(item);
|
||||
});
|
||||
json.put("data", array);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
json.put("code", 0);
|
||||
hashMap.keySet().forEach(key -> {
|
||||
JSONObject item = JSONObject.parseObject(hashMap.get(key));
|
||||
array.add(item);
|
||||
});
|
||||
json.put("data", array);
|
||||
System.out.println(json);
|
||||
}
|
||||
}
|
||||
|
||||
35
src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java
Normal file
35
src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AndroidDevice {
|
||||
String title;
|
||||
String deviceId;
|
||||
DeviceDisplay androidDevice;
|
||||
List<GameDisplay> deviceDisplay;
|
||||
|
||||
|
||||
@Data
|
||||
public static class DeviceDisplay {
|
||||
int width, height;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class GameDisplay {
|
||||
String title;
|
||||
double width, height;
|
||||
Vector2D start, end;
|
||||
|
||||
public double getWidth() {
|
||||
return end.getX() - start.getX();
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return end.getY() - start.getY();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yutou.qqbot.data;
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class JianRScriptV2Data {
|
||||
private String title;
|
||||
private List<Script> script;
|
||||
|
||||
@Data
|
||||
public static class Script {
|
||||
private String title;
|
||||
private String activity;
|
||||
private int nextWaitTime;
|
||||
private int randomNextWaitTime;
|
||||
}
|
||||
public static class ScriptModel {
|
||||
public static final String MAP = "map";
|
||||
public static final String attack = "attack";
|
||||
public static final String formationType = "formationType";
|
||||
public static final String dialog_go = "dialog_go";
|
||||
public static final String dialog_back = "dialog_back";
|
||||
}
|
||||
}
|
||||
38
src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java
Normal file
38
src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Data
|
||||
public class Vector2D {
|
||||
double x, y;
|
||||
boolean enableRandomX, enableRandomY;
|
||||
boolean absRandomX, absRandomY;
|
||||
int randomNumX, randomNumY;
|
||||
|
||||
|
||||
public double getX() {
|
||||
if (isEnableRandomX()) {
|
||||
double tmp = new Random().nextDouble(-randomNumX, randomNumX);
|
||||
if (isAbsRandomX()) {
|
||||
return Math.abs(tmp) + x;
|
||||
} else {
|
||||
return tmp + x;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
if(isEnableRandomY()){
|
||||
double tmp = new Random().nextDouble(-randomNumY, randomNumY);
|
||||
if (isAbsRandomY()) {
|
||||
return Math.abs(tmp) + y;
|
||||
} else {
|
||||
return tmp + y;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,26 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import com.yutou.qqbot.data.JianRScriptData;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.yutou.qqbot.data.jianr.AndroidDevice;
|
||||
import com.yutou.qqbot.data.jianr.JianRScriptData;
|
||||
import com.yutou.qqbot.data.jianr.JianRScriptV2Data;
|
||||
import com.yutou.qqbot.data.jianr.Vector2D;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class JianRTaskManager {
|
||||
public static final String Redis_Script ="jianrScript_Script";
|
||||
public static final String Redis_Device="jianrScript_Devices";
|
||||
public static final String Redis_RunIndex="jianrScript_RunIndex";
|
||||
private static JianRTaskManager instance;
|
||||
private JianRScriptData task;
|
||||
private JianRScriptV2Data task;
|
||||
private AndroidDevice device;
|
||||
private boolean running = false;
|
||||
private int runIndex = 0;
|
||||
private String log;
|
||||
private int modelId;
|
||||
|
||||
public static JianRTaskManager getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -22,17 +33,22 @@ public class JianRTaskManager {
|
||||
|
||||
}
|
||||
|
||||
public void setTask(JianRScriptData data) {
|
||||
public void setModelId(int modelId) {
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public void setTask(JianRScriptV2Data data, AndroidDevice device) {
|
||||
task = data;
|
||||
runIndex=0;
|
||||
String s = RedisTools.get("jianrScript_RunIndex_" + data.getName());
|
||||
this.device = device;
|
||||
runIndex = 0;
|
||||
String s = RedisTools.getHashMap(Redis_RunIndex,data.getTitle());
|
||||
if (s != null) {
|
||||
runIndex = Integer.parseInt(s);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if(running){
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
running = true;
|
||||
@@ -43,19 +59,21 @@ public class JianRTaskManager {
|
||||
while (running) {
|
||||
try {
|
||||
log("已运行: " + runIndex + " 次");
|
||||
for (JianRScriptData.Script script : task.getRun()) {
|
||||
log(script.getName());
|
||||
if (script.getModel().equals(JianRScriptData.Script.ScriptModel.CLICK)) {
|
||||
adbTap(task.getDevice(), script);
|
||||
for (JianRScriptV2Data.Script script : task.getScript()) {
|
||||
if(!isRunning()){
|
||||
log("任务已停止");
|
||||
break;
|
||||
}
|
||||
log(script.getTitle());
|
||||
JianRTaskManager.this.run(device, modelId, script);
|
||||
try {
|
||||
Thread.sleep((long) getRandom(0, script.getRandomNextWaitTime(), script.getNextWaitTime()));
|
||||
Thread.sleep((long) getRandom(0, script.getRandomNextWaitTime()*1000, script.getNextWaitTime()*1000));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
runIndex++;
|
||||
RedisTools.set("jianrScript_RunIndex_" + task.getName(), runIndex + "");
|
||||
RedisTools.setHashMap(Redis_RunIndex,task.getTitle(),runIndex+"");
|
||||
log("循环一次任务");
|
||||
} catch (Exception e) {
|
||||
running = false;
|
||||
@@ -67,6 +85,32 @@ public class JianRTaskManager {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void run(AndroidDevice device, int modelId, JianRScriptV2Data.Script script) {
|
||||
AndroidDevice.GameDisplay gameDisplay = device.getDeviceDisplay().get(modelId);
|
||||
Vector2D vector2D = null;
|
||||
switch (script.getActivity()) {
|
||||
case JianRScriptV2Data.ScriptModel.MAP:
|
||||
vector2D = getMapCoords(device, gameDisplay);
|
||||
break;
|
||||
case JianRScriptV2Data.ScriptModel.attack:
|
||||
vector2D = getAttackCoords(device, gameDisplay);
|
||||
break;
|
||||
case JianRScriptV2Data.ScriptModel.dialog_go:
|
||||
vector2D = getDialogCoords(device, gameDisplay, false);
|
||||
break;
|
||||
case JianRScriptV2Data.ScriptModel.dialog_back:
|
||||
vector2D = getDialogCoords(device, gameDisplay, true);
|
||||
break;
|
||||
default:
|
||||
if (script.getActivity().startsWith(JianRScriptV2Data.ScriptModel.formationType)) {
|
||||
vector2D = getNextFormationCoords(device, gameDisplay, Integer.parseInt(script.getActivity().split("#")[1]));
|
||||
}
|
||||
}
|
||||
if (vector2D != null) {
|
||||
adb(device, vector2D);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
task = null;
|
||||
running = false;
|
||||
@@ -80,6 +124,10 @@ public class JianRTaskManager {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* 老版本脚本执行命令
|
||||
*/
|
||||
@Deprecated
|
||||
private void adbTap(String deviceId, JianRScriptData.Script script) {
|
||||
String exec = String.format("adb -s %s shell input tap %f %f",
|
||||
deviceId,
|
||||
@@ -93,6 +141,7 @@ public class JianRTaskManager {
|
||||
this.log = String.format("[%s]%s",
|
||||
AppTools.getToDayNowTimeToString(),
|
||||
log);
|
||||
System.out.println(this.log);
|
||||
}
|
||||
|
||||
private float getRandom(int origin, int randomNum, int x) {
|
||||
@@ -106,7 +155,7 @@ public class JianRTaskManager {
|
||||
|
||||
public String getTaskName() {
|
||||
if (task != null) {
|
||||
return task.getName();
|
||||
return task.getTitle();
|
||||
}
|
||||
return "没有任务在运行";
|
||||
}
|
||||
@@ -114,4 +163,121 @@ public class JianRTaskManager {
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public void connect(String deviceId) {
|
||||
String exec = String.format("adb connect %s",
|
||||
deviceId);
|
||||
System.out.println(exec);
|
||||
AppTools.exec(exec
|
||||
, null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取出击坐标
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @return 坐标
|
||||
*/
|
||||
private Vector2D getAttackCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) {
|
||||
Vector2D v2d = new Vector2D();
|
||||
v2d.setX(gameDisplay.getWidth() * 0.8725 + gameDisplay.getStart().getX());
|
||||
v2d.setY(gameDisplay.getHeight() * 0.9161 + gameDisplay.getStart().getY());
|
||||
return v2d;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地图点击坐标
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @return 坐标
|
||||
*/
|
||||
private Vector2D getMapCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) {
|
||||
Vector2D v2d = new Vector2D();
|
||||
v2d.setX(gameDisplay.getWidth() * 0.5 + gameDisplay.getStart().getX());
|
||||
v2d.setY(gameDisplay.getHeight() * 0.5 + gameDisplay.getStart().getY());
|
||||
return v2d;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取阵型点击坐标
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @param type 阵型。0~4
|
||||
* @return 坐标
|
||||
*/
|
||||
private Vector2D getNextFormationCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay, int type) {
|
||||
Vector2D v2d = new Vector2D();
|
||||
v2d.setX(gameDisplay.getWidth() * 0.75 + gameDisplay.getStart().getX());
|
||||
v2d.setY(gameDisplay.getHeight() * 0.24835 + gameDisplay.getStart().getY());
|
||||
|
||||
for (int i = 0; i < type; i++) {
|
||||
v2d.setY(v2d.getY() + (gameDisplay.getHeight() * 0.1461));
|
||||
}
|
||||
return v2d;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取出击坐标
|
||||
*
|
||||
* @param device 设备信息
|
||||
* @return 坐标
|
||||
*/
|
||||
private Vector2D getDialogCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay, boolean isBack) {
|
||||
Vector2D v2d = new Vector2D();
|
||||
v2d.setY(gameDisplay.getHeight() * 0.61722 + gameDisplay.getStart().getY());
|
||||
if (isBack) {
|
||||
v2d.setX(gameDisplay.getWidth() * 0.6575 + gameDisplay.getStart().getX());
|
||||
} else {
|
||||
v2d.setX(gameDisplay.getWidth() * 0.344642857143 + gameDisplay.getStart().getX());
|
||||
}
|
||||
return v2d;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
AndroidDevice device = new AndroidDevice();
|
||||
AndroidDevice.DeviceDisplay deviceDisplay = new AndroidDevice.DeviceDisplay();
|
||||
AndroidDevice.GameDisplay gameDisplay = new AndroidDevice.GameDisplay();
|
||||
deviceDisplay.setHeight(1800);
|
||||
deviceDisplay.setWidth(2800);
|
||||
Vector2D start = new Vector2D();
|
||||
Vector2D end = new Vector2D();
|
||||
start.setX(2000);
|
||||
start.setY(57);
|
||||
end.setX(2800);
|
||||
end.setY(581);
|
||||
gameDisplay.setStart(start);
|
||||
gameDisplay.setEnd(end);
|
||||
List<AndroidDevice.GameDisplay> displays = new ArrayList<>();
|
||||
displays.add(gameDisplay);
|
||||
device.setDeviceDisplay(displays);
|
||||
device.setAndroidDevice(deviceDisplay);
|
||||
device.setDeviceId("192.168.31.142:6666");
|
||||
device.setTitle("SAMSUNG-TAB-S7+");
|
||||
|
||||
JianRTaskManager manager = new JianRTaskManager();
|
||||
Vector2D mapCoords;
|
||||
// mapCoords = manager.getMapCoords(device,device.getGameDisplay().get(0));
|
||||
// mapCoords = manager.getAttackCoords(device,device.getGameDisplay().get(0));
|
||||
// mapCoords = manager.getNextFormationCoords(device,device.getGameDisplay().get(0), 0);
|
||||
mapCoords = manager.getDialogCoords(device, device.getDeviceDisplay().get(0), true);
|
||||
// adb(device, mapCoords);
|
||||
System.out.println("device = " + device);
|
||||
String jsonString = "{\"name\":\"1-1Test\",\"script\":[{\"name\":\"点击地图\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"出击\",\"activity\":\"attack\",\"nextWaitTime\":12,\"randomNextWaitTime\":2},{\"name\":\"战斗\",\"activity\":\"attack\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"选择单纵\",\"activity\":\"formationType#0\",\"nextWaitTime\":20,\"randomNextWaitTime\":5},{\"name\":\"结算1\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"结算2\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"获取舰娘\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"前进\",\"activity\":\"dialog_go\",\"nextWaitTime\":12,\"randomNextWaitTime\":3},{\"name\":\"战斗\",\"activity\":\"attack\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"选择梯形\",\"activity\":\"formationType#3\",\"nextWaitTime\":20,\"randomNextWaitTime\":5},{\"name\":\"结算1\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"结算2\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"获取舰娘\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3}]}";
|
||||
JianRScriptV2Data script = JSON.parseObject(jsonString, JianRScriptV2Data.class);
|
||||
manager.setTask(script,device);
|
||||
manager.setModelId(0);
|
||||
manager.start();
|
||||
}
|
||||
|
||||
private void adb(AndroidDevice device, Vector2D v2d) {
|
||||
String exec = String.format("adb -s %s shell input tap %f %f",
|
||||
device.getDeviceId(),
|
||||
v2d.getX(),
|
||||
v2d.getY());
|
||||
System.out.println(exec);
|
||||
AppTools.exec(exec
|
||||
, null, false, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user