update:优化脚本执行

This commit is contained in:
Yutousama 2022-07-27 01:22:32 +08:00
parent 21dd8033d1
commit 5209843e86
3 changed files with 25 additions and 10 deletions

View File

@ -22,5 +22,6 @@ public class JianRScriptV2Data {
public static final String formationType = "formationType"; public static final String formationType = "formationType";
public static final String dialog_go = "dialog_go"; public static final String dialog_go = "dialog_go";
public static final String dialog_back = "dialog_back"; public static final String dialog_back = "dialog_back";
public static final String dialog_assets = "dialog_assets";
} }
} }

View File

@ -11,9 +11,9 @@ import java.util.List;
import java.util.Random; import java.util.Random;
public class JianRTaskManager { public class JianRTaskManager {
public static final String Redis_Script ="jianrScript_Script"; public static final String Redis_Script = "jianrScript_Script";
public static final String Redis_Device="jianrScript_Devices"; public static final String Redis_Device = "jianrScript_Devices";
public static final String Redis_RunIndex="jianrScript_RunIndex"; public static final String Redis_RunIndex = "jianrScript_RunIndex";
private static JianRTaskManager instance; private static JianRTaskManager instance;
private JianRScriptV2Data task; private JianRScriptV2Data task;
private AndroidDevice device; private AndroidDevice device;
@ -41,7 +41,7 @@ public class JianRTaskManager {
task = data; task = data;
this.device = device; this.device = device;
runIndex = 0; runIndex = 0;
String s = RedisTools.getHashMap(Redis_RunIndex,data.getTitle()); String s = RedisTools.getHashMap(Redis_RunIndex, data.getTitle());
if (s != null) { if (s != null) {
runIndex = Integer.parseInt(s); runIndex = Integer.parseInt(s);
} }
@ -60,20 +60,20 @@ public class JianRTaskManager {
try { try {
log("已运行: " + runIndex + ""); log("已运行: " + runIndex + "");
for (JianRScriptV2Data.Script script : task.getScript()) { for (JianRScriptV2Data.Script script : task.getScript()) {
if(!isRunning()){ if (!isRunning()) {
log("任务已停止"); log("任务已停止");
break; break;
} }
log(script.getTitle()); log(script.getTitle());
JianRTaskManager.this.run(device, modelId, script); JianRTaskManager.this.run(device, modelId, script);
try { try {
Thread.sleep((long) getRandom(0, script.getRandomNextWaitTime()*1000, script.getNextWaitTime()*1000)); Thread.sleep((long) getRandom(0, script.getRandomNextWaitTime() * 1000, script.getNextWaitTime() * 1000));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
runIndex++; runIndex++;
RedisTools.setHashMap(Redis_RunIndex,task.getTitle(),runIndex+""); RedisTools.setHashMap(Redis_RunIndex, task.getTitle(), runIndex + "");
log("循环一次任务"); log("循环一次任务");
} catch (Exception e) { } catch (Exception e) {
running = false; running = false;
@ -101,6 +101,9 @@ public class JianRTaskManager {
case JianRScriptV2Data.ScriptModel.dialog_back: case JianRScriptV2Data.ScriptModel.dialog_back:
vector2D = getDialogCoords(device, gameDisplay, true); vector2D = getDialogCoords(device, gameDisplay, true);
break; break;
case JianRScriptV2Data.ScriptModel.dialog_assets:
vector2D = getDialogAssetsCoords(device, gameDisplay);
break;
default: default:
if (script.getActivity().startsWith(JianRScriptV2Data.ScriptModel.formationType)) { if (script.getActivity().startsWith(JianRScriptV2Data.ScriptModel.formationType)) {
vector2D = getNextFormationCoords(device, gameDisplay, Integer.parseInt(script.getActivity().split("#")[1])); vector2D = getNextFormationCoords(device, gameDisplay, Integer.parseInt(script.getActivity().split("#")[1]));
@ -233,6 +236,18 @@ public class JianRTaskManager {
return v2d; return v2d;
} }
/**
* 获取资源对抗确定坐标
*
* @return 坐标
*/
private Vector2D getDialogAssetsCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) {
Vector2D v2d = new Vector2D();
v2d.setX(gameDisplay.getWidth() * 0.5 + gameDisplay.getStart().getX());
v2d.setY(gameDisplay.getHeight() * 0.5433 + gameDisplay.getStart().getY());
return v2d;
}
public static void main(String[] args) { public static void main(String[] args) {
AndroidDevice device = new AndroidDevice(); AndroidDevice device = new AndroidDevice();
AndroidDevice.DeviceDisplay deviceDisplay = new AndroidDevice.DeviceDisplay(); AndroidDevice.DeviceDisplay deviceDisplay = new AndroidDevice.DeviceDisplay();
@ -264,7 +279,7 @@ public class JianRTaskManager {
System.out.println("device = " + device); 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}]}"; 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); JianRScriptV2Data script = JSON.parseObject(jsonString, JianRScriptV2Data.class);
manager.setTask(script,device); manager.setTask(script, device);
manager.setModelId(0); manager.setModelId(0);
manager.start(); manager.start();
} }
@ -274,7 +289,6 @@ public class JianRTaskManager {
device.getDeviceId(), device.getDeviceId(),
v2d.getX(), v2d.getX(),
v2d.getY()); v2d.getY());
System.out.println(exec);
AppTools.exec(exec AppTools.exec(exec
, null, false, false); , null, false, false);
} }

View File

@ -48,7 +48,7 @@
' "script":[\n' + ' "script":[\n' +
' {\n' + ' {\n' +
' "title":"",\n' + ' "title":"",\n' +
' "activity":"map|attack|formationType#{0-4}|dialog_go|dialog_back",\n' + ' "activity":"map|attack|formationType#{0-4}|dialog_go|dialog_back|dialog_assets",\n' +
' "nextWaitTime": 0,\n' + ' "nextWaitTime": 0,\n' +
' "randomNextWaitTime": 0\n' + ' "randomNextWaitTime": 0\n' +
' }\n' + ' }\n' +