mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
docs: 更新3.4-任务流程协议
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
{
|
||||
"TaskName" : { // 任务名
|
||||
|
||||
"baseTask": "xxx" // 以xxx任务为模板生成任务,详细见下方特殊任务类型中的Base Task
|
||||
"baseTask": "xxx", // 以xxx任务为模板生成任务,详细见下方特殊任务类型中的Base Task
|
||||
|
||||
"algorithm": "MatchTemplate", // 可选项,表示识别算法的类型
|
||||
// 不填写时默认为 MatchTemplate
|
||||
@@ -60,7 +60,7 @@
|
||||
// 以 1280 * 720 为基准自动缩放;不填写时默认 [ 0, 0, 1280, 720 ]
|
||||
// 尽量填写,减小识别范围可以减少性能消耗,加快识别速度
|
||||
|
||||
"cache": true, // 可选项,表示该任务是否使用缓存,默认为 true;
|
||||
"cache": true, // 可选项,表示该任务是否使用缓存,默认为 true;
|
||||
// 第一次识别到后,以后永远只在第一次识别到的位置进行识别,开启可大幅节省性能
|
||||
// 但仅适用于待识别目标位置完全不会变的任务,若待识别目标位置会变请设为 false
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
// 例如识别到了 A ,但实际要点击的是 A 下方 10 像素 5 * 2 区域的某个位置,
|
||||
// 则可填写[ 0, 10, 5, 2 ],可以的话尽量直接识别要点击的位置,不建议使用该选项
|
||||
// 额外的,当 action 为 Swipe 时有效且必选,表示滑动终点。
|
||||
|
||||
|
||||
"reduceOtherTimes": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// 可选项,执行后减少其他任务的执行计数。
|
||||
// 例如执行了吃理智药,则说明上一次点击蓝色开始行动按钮没生效,所以蓝色开始行动要-1
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
"specialParams": [ int, ... ], // 某些特殊识别器需要的参数
|
||||
// 额外的,当 action 为 Swipe 时可选,[0] 表示 duration,[1] 表示 是否启用额外滑动
|
||||
|
||||
|
||||
/* 以下字段仅当 algorithm 为 MatchTemplate 时有效 */
|
||||
|
||||
"template": "xxx.png", // 可选项,要匹配的图片文件名
|
||||
@@ -92,7 +92,6 @@
|
||||
"maskRange": [ 1, 255 ], // 可选项,灰度掩码范围。例如将图片不需要识别的部分涂成黑色(灰度值为 0)
|
||||
// 然后设置"maskRange"的范围为 [ 1, 255 ], 匹配的时候即刻忽略涂黑的部分
|
||||
|
||||
|
||||
/* 以下字段仅当 algorithm 为 OcrDetect 时有效 */
|
||||
|
||||
"text": [ "接管作战", "代理指挥" ], // 必选项,要识别的文字内容,只要任一匹配上了即认为识别到了
|
||||
@@ -127,7 +126,7 @@ Template task 与 base task 合称**模板任务**。
|
||||
|
||||
允许把某个任务 "A" 当作模板,然后 "B@A" 表示由 "A" 生成的任务。
|
||||
|
||||
- 如果 `tasks.json` 中未显式定义任务 "B@A",则在 `sub`, `next`, `onErrorNext`, `exceededNext`, `reduceOtherTimes` 字段中增加 `B@` 前缀(如遇任务名开头为 `#` 则增加 `B` 前缀),其余参数与 "A" 任务相同。就是说如果任务 "A" 有以下参数:
|
||||
- 如果 `tasks.json` 中未显式定义任务 "B@A",则在 `sub`, `next`, `onErrorNext`, `exceededNext`, `reduceOtherTimes` 字段中增加 `B@` 前缀(如遇任务名开头为 `#` 则增加 `B` 前缀),其余参数与 "A" 任务相同。就是说如果任务 "A" 有以下参数:
|
||||
|
||||
```jsonc
|
||||
"A": {
|
||||
|
||||
@@ -8,155 +8,230 @@ Usage of `resource/tasks.json` and description of each field
|
||||
{
|
||||
"TaskName" : { // Task name
|
||||
|
||||
"algorithm": "MatchTemplate", // Recognition algorithm, optional
|
||||
// MatchTemplate by default
|
||||
// - JustReturn: Proceed action without recognition
|
||||
// - MatchTemplate: Matching template image
|
||||
// - OcrDetect: OCR detection
|
||||
// - Hash: Hash calculation
|
||||
"baseTask": "xxx", // use xxx task as a template to generate tasks, see Base Task in the special task type below for details
|
||||
|
||||
"template": "xxx.png", // Available only when `algorithm` is `MatchTemplate`; Image file for matching, optional
|
||||
// "任务名.png" by default
|
||||
"algorithm": "MatchTemplate", // Optional, indicating the type of recognition algorithm
|
||||
// defaults to MatchTemplate when not filled in
|
||||
// - JustReturn: Execute the action directly without recognition
|
||||
// - MatchTemplate: match the image
|
||||
// - OcrDetect: text recognition
|
||||
// - Hash: Hash calculation
|
||||
|
||||
"text": [ "接管作战", "代理指挥" ], // Available only when `algorithm` is `OcrDetect`; text to recognize, required, matched when any of the texts are found
|
||||
|
||||
"action": "ClickSelf", // Action after recognition, optional
|
||||
// DoNothing by default
|
||||
// - ClickSelf: Clicking the position recognized (random position within the region)
|
||||
// - ClickRand: Clicking any position in the screen
|
||||
// - DoNothing: Doing nothing
|
||||
// - Stop: Stopping current task
|
||||
// - ClickRect: Clicking in the specified rectangle. See the specificRect field, not recommended
|
||||
// - SwipeToTheLeft: Swiping to the left
|
||||
// - SwipeToTheRight: Swiping to the right
|
||||
// - SlowlySwipeToTheLeft: Slowly swiping to the left
|
||||
// - SlowlySwipeToTheRight: Slowly swiping to the right
|
||||
"action": "ClickSelf", // Optional, indicates the action after recognition
|
||||
// defaults to DoNothing if not filled in
|
||||
// - ClickSelf: Click on the recognized location (a random point within the recognized target range)
|
||||
// - ClickRand: Click on a random position in the whole screen
|
||||
// - ClickRect: Click on the specified area, corresponds to the specificRect field, not recommended to use this option
|
||||
// - DoNothing: Do nothing
|
||||
// - Stop: Stop the current task
|
||||
// - Swipe: slide, corresponds to the specificRect and rectMove fields
|
||||
|
||||
"sub": [ "SubTaskName1", "SubTaskName2" ],
|
||||
// Subtasks, optional. Will be executed in the order of the list after execution of the current task.
|
||||
// Subtasks can contain other subtasks. Pay attention to the infinite loop.
|
||||
// Optional, subtasks. Will execute each subtask in turn after the current task is executed
|
||||
// Optional, sub-tasks and then sub-tasks. But be careful not to write a dead loop
|
||||
|
||||
"subErrorIgnored": true, // Whether to ignore the error of the subtask, optional
|
||||
// `false` by default
|
||||
// `false` for not executing proceeding subtasks when one of the subtasks fails (considered as a failure of the current task).
|
||||
// `true` for ignoring subtask errors.
|
||||
"subErrorIgnored": true, // Optional, if or not to ignore subtask errors.
|
||||
// default false if not filled
|
||||
// If false, if a subtask has an error, it will not continue to execute subsequent tasks (equivalent to this task having an error)
|
||||
// When true, it has no effect on whether a subtask has an error or not
|
||||
|
||||
"next": [ "OtherTaskName1", "OtherTaskName2"],
|
||||
// Next tasks to be executed after the current task is finished, optional
|
||||
// Will be recognized from the first item of the list and execute the first matched one.
|
||||
// Empty list means to stop the task after the current task is finished.
|
||||
"next": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// Optional, indicating the next task to be executed after the current task and the sub task are executed
|
||||
// will be identified from front to back, and the first matching one will be executed
|
||||
// default stop after the current task is executed
|
||||
// For the same task, the second time will not be recognized after the first recognition.
|
||||
// "next": [ "A", "B", "A", "A" ] -> "next": [ "A", "B" ]
|
||||
// Do not allow JustReturn type tasks to be located in a non-last item
|
||||
|
||||
"maxTimes": 10, // Maximum execution times, optional
|
||||
// Infinity by default
|
||||
// Proceeds with `exceedNext` if it exists; otherwise stops.
|
||||
"maxTimes": 10, // Optional, indicates the maximum number of times the task can be executed
|
||||
// default infinite if not filled
|
||||
// When the maximum number of times is reached, if the exceededNext field exists, the task will be executed as exceededNext; otherwise, the task will be stopped.
|
||||
|
||||
"exceededNext": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// Tasks to be executed after reaching `maxTimes`, optional
|
||||
// Stops the task if empty; otherwise, proceeds with the tasks here in the list instead of `next`.
|
||||
// Optional, indicates the task to be executed when the maximum number of executions is reached
|
||||
// If not filled in, it will stop when the maximum number of executions is reached; if filled in, it will be executed here, not in next
|
||||
"onErrorNext": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// Proceeding tasks when there are errors, optional
|
||||
// Optional, indicating the subsequent tasks to be performed in case of execution errors
|
||||
|
||||
"preDelay": 1000, // Pre-delay of action in ms after recognition, optional; 0 by default
|
||||
"postDelay": 1000, // Post-delay of action in ms after recognition, optional; 0 by default
|
||||
"preDelay": 1000, // Optional, indicates how long the action will be executed after it is recognized, in milliseconds; default 0 if not filled in
|
||||
"postDelay": 1000, // Optional, indicates how long the action is delayed after execution before it is recognized next, in milliseconds; default 0 if not filled in
|
||||
|
||||
"roi": [ 0, 0, 1280, 720], // Recognition region with the format of [ x, y, width, height ], optional
|
||||
// Auto-scaling based on 1280 * 720 resolution;[ 0, 0, 1280, 720 ] by default
|
||||
// Reducing the region has the effect of reducing performance consumption and speeding up the recognition.
|
||||
"roi": [ 0, 0, 1280, 720 ], // Optional, indicating the range of recognition, in the format [ x, y, width, height ]
|
||||
// Auto-scaling to 1280 * 720; default when not filled [ 0, 0, 1280, 720 ]
|
||||
// Fill in as much as possible, reducing the recognition range can reduce performance consumption and speed up recognition
|
||||
|
||||
"cache": true, // Whether the task uses cache, optional; `true` by default
|
||||
// After a successful recognition, subsequent recognition will be done only in the region cached, which has a significant performance enhancement.
|
||||
// Only for targets that do not change position. Please set it to `false` for targets with changing position.
|
||||
"cache": true, // Optional, indicates whether the task uses caching or not, default is true;
|
||||
// After the first recognition, only the first recognized position will be recognized forever, enable to save performance significantly
|
||||
// but only for tasks where the location of the target to be recognized will not change at all, set to false if the location of the target to be recognized will change
|
||||
|
||||
"rectMove": [ 0, 0, 0, 0 ], // Optional, target movement after recognition, not recommended Auto-scaling with 1280 * 720 as base
|
||||
// For example, if A is recognized, but the actual location to be clicked is somewhere in the 10 pixel 5 * 2 area below A.
|
||||
// then you can fill in [ 0, 10, 5, 2 ], try to recognize the position to be clicked directly if you can, this option is not recommended
|
||||
// Additional, valid and mandatory when action is Swipe, indicates the end of the slide.
|
||||
|
||||
"rectMove": [0, 0, 0, 0], // Target movements after recognition, optional, not recommended. Auto-scaling based on 1280 * 720 resolution.
|
||||
// E.g. Icon A is recognized but the target is some position beside A. You can set it to click the place beside it.
|
||||
// It is suggested that it should recognize the target to click instead of using this field.
|
||||
|
||||
"reduceOtherTimes": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// Reducing execution counter of other tasks after execution, optional
|
||||
// E.g. Using sanity potion means clicking the blue start button did not take effect so the counter of the starting task should be reduced by 1.
|
||||
// Optional, executes to reduce the execution count of other tasks.
|
||||
// For example, if you take a sanity pill, it means that the last click on the blue start action button did not take effect, so the blue start action is -1
|
||||
|
||||
"specificRect": [ 100, 100, 50, 50],
|
||||
// Available only when `action` is `ClickRect`, indicating the position to click (random position within the region), required.
|
||||
// Auto-scaled based on 1280 * 720 resolution.
|
||||
|
||||
/* Available only when `algorithm` is `MatchTemplate` */
|
||||
"specificRect": [ 100, 100, 50, 50 ],
|
||||
// Valid and mandatory when action is ClickRect, indicates the specified click position (a random point in the range).
|
||||
// Valid and mandatory when action is Swipe, it means the starting point of swipe.
|
||||
// Auto-scaling with 1280 * 720 as base
|
||||
|
||||
"templThreshold": 0.8, // Threshold of image recognition, optional. Image is matched only when the similarity is greater than the threshold.
|
||||
// 0.8 by default. You can check it in the logs.
|
||||
"specialParams": [ int, ... ], // Parameters needed for some special recognizers
|
||||
// extra, optional when action is Swipe, [0] for duration, [1] for whether to enable extra sliding
|
||||
|
||||
"maskRange": [ 1, 255 ], // Grayscale mask range, optional. E.g. fill in the region that does not require recognition with black colour,
|
||||
// and set it to [ 1, 255 ] so that the black region is ignored.
|
||||
/* The following fields are only valid if algorithm is MatchTemplate */
|
||||
|
||||
"template": "xxx.png", // Optional, the name of the image file to be matched
|
||||
// default "TaskName.png"
|
||||
|
||||
/* Available only when `algorithm` is `OcrDetect` */
|
||||
"templThreshold": 0.8, // Optional, threshold value for image template matching score, above which the image is considered recognized.
|
||||
// default 0.8, you can check the actual score according to the log
|
||||
|
||||
"fullMatch": false, // Whether the text recognition is full match, optional. `false` by default.
|
||||
// `false` means substring matches as well. E.g.: `text: [ "开始" ]` matches "开始行动";
|
||||
// `true` means, e.g. it must match "开始" without other characters.
|
||||
"maskRange": [ 1, 255 ], // Optional, the grayscale mask range. For example, the part of the image that does not need to be recognized will be painted black (grayscale value of 0)
|
||||
// Then set "maskRange" to [ 1, 255 ], to instantly ignore the blacked out parts when matching
|
||||
|
||||
"ocrReplace": [ // Text replacement for common wrong recognition of OCR (supporting RegExp)
|
||||
/* The following fields are only valid if algorithm is OcrDetect */
|
||||
|
||||
"text": [ "接管作战", "代理指挥" ], // Required, the text content to be recognized, as long as any match is considered to be recognized
|
||||
|
||||
"ocrReplace": [ // Optional, replacement for commonly misidentified text (regular support)
|
||||
[ "千员", "干员" ],
|
||||
[ ".+击干员", "狙击干员" ]
|
||||
]
|
||||
],
|
||||
|
||||
/* Available only when `algorithm` is `Hash` */
|
||||
// Development in progress, only used in some special cases, not recommended
|
||||
"fullMatch": false, // optional, whether the text recognition needs to match all words (not multiple words), default is false
|
||||
// false, as long as it is a substring: for example, text: [ "start" ], the actual recognition to "start action", also considered successful.
|
||||
// if true, "start" must be recognized, not one more word
|
||||
|
||||
"isAscii": false, // optional, whether the text content to be recognized is ASCII characters
|
||||
// default false if not filled
|
||||
|
||||
"withoutDet": false // Optional, whether to not use the detection model
|
||||
// default false if not filled
|
||||
|
||||
/* The following fields are only valid when the algorithm is Hash */
|
||||
// The algorithm is not mature, and is only used in some special cases, so it is not recommended for now
|
||||
// Todo
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Tips
|
||||
## Special Task Type
|
||||
|
||||
- Put the name of the task itself in `next` for looping, for example:
|
||||
### Template Task(`@` Type Task)
|
||||
|
||||
```jsonc
|
||||
Template task and base task are collectively called **Template task**.
|
||||
|
||||
Allows a task "A" to be used as a template, and then "B@A" to represent the task generated by "A".
|
||||
|
||||
- If task "B@A" is not explicitly defined in `tasks.json`, then add `B@` prefix to the `sub`, `next`, `onErrorNext`, `exceededNext`, `reduceOtherTimes` fields (or `B` if the task name starts with `#`) and the rest of the parameters are the same as for task "A". That is, if task "A" has the following parameters.
|
||||
|
||||
```jsonc
|
||||
"A": {
|
||||
"template": "A.png",
|
||||
...,
|
||||
"next": [ "N1", "N2" ]
|
||||
}
|
||||
```
|
||||
|
||||
is equivalent to defining both
|
||||
|
||||
```jsonc
|
||||
"B@A": {
|
||||
"template": "A.png",
|
||||
...,
|
||||
"next": [ "B@N1", "B@N2" ]
|
||||
}
|
||||
```
|
||||
|
||||
- If task "B@A" is defined in `tasks.json`, then
|
||||
1. if the `algorithm` field of `B@A` is different from that of `A`, the derived class parameters are not inherited (only the parameters defined by `TaskInfo` are inherited)
|
||||
2. for image matching task, `template` is `B@A.png` if not explicitly defined (instead of inheriting the `template` name of "A"), otherwise any derived class parameters are inherited directly from "A" task if not explicitly defined
|
||||
3. for the parameters defined in the `TaskInfo` base class (any type of task parameters, such as `algorithm`, `roi`, `next`, etc.), if not explicitly defined in "B@A", all parameters are inherited directly from the "A" task parameters, except for the five fields mentioned above, such as `sub`, which will be prefixed with "B@" when inherited
|
||||
|
||||
### Base Task
|
||||
|
||||
Base task and template task are collectively called **template task**.
|
||||
|
||||
A task with the field `baseTask` is a base task.
|
||||
|
||||
Any parameter that is not explicitly defined uses the parameter of the corresponding task if `baseTask` is not explicitly defined, except for `template` which remains `"taskName.png"`. (without prefix)
|
||||
|
||||
#### Other related
|
||||
|
||||
- Tasks with the same name defined in `tasks.json` in foreign service inherit directly from `tasks.json` in national service, equivalent to `"A": { "baseTask": "A in national service" }`
|
||||
- If task "B@A" is defined in national service `tasks.json` and "B@A" is defined in foreign service `tasks.json`, then
|
||||
1. if foreign service "B@A" has field `"baseTask": ""`, then it does not inherit from national service "B@A"
|
||||
- If there is a defined task "A", then "B@A" is handled with the logic of template task
|
||||
- If there is no defined task "A", then handle "B@A" with the logic of normal task
|
||||
2. If there is no `baseTask` for foreign "B@A", then inherit the parameters of national "B@A" directly
|
||||
|
||||
### Virtual Task
|
||||
|
||||
Virtual task is also called sharp task (`#` type task).
|
||||
|
||||
A task with `#` in its name is a virtual task. `#` can be followed by `next`, `back`, `self`, `sub`, `on_error_next`, `exceeded_next`, `reduce_other_times`。
|
||||
|
||||
| Virtual Task Type | Meaning | Simple example |
|
||||
|:---------:|:---:|:--------:|
|
||||
| self | Parent Task Name | `"A": {"next": "#self"}` in `"#self"` is interpreted as `"A"`<br>`"B": {"next": "A@B@C#self"}` in `"A@B@C#self"` is interpreted as `"B"`.<sup>1</sup> |
|
||||
| back | # Preceding task name | `"A@B#back"` is interpreted as `"A@B"`<br>`"#back"` will be skipped if it appears directly |
|
||||
| next, sub, etc. | # The field corresponding to the previous task name | Take `next` for example:<br>`"A#next"` is interpreted as `Task.get("A")->next`<br>`"#next"` will be skipped if it appears directly |
|
||||
|
||||
_Note<sup>1</sup>: `"XXX#self"` has the same meaning as `"#self"`._
|
||||
|
||||
#### Simple example
|
||||
|
||||
```json
|
||||
{
|
||||
"Waiting": {
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [ "正在加载" ],
|
||||
"next": [
|
||||
"Succeed", // Matches "加载完成" first
|
||||
"Waiting" // Otherwise matches "正在加载"
|
||||
]
|
||||
"A": { "next": [ "N1", "N2" ] },
|
||||
"C": { "next": [ "B@A#next" ] },
|
||||
|
||||
"Loading": {
|
||||
"next": [ "#self", "#next", "#back" ]
|
||||
},
|
||||
"Succeed": {
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [ "加载完成" ],
|
||||
"next": [
|
||||
"OtherTask"
|
||||
]
|
||||
"B": {
|
||||
"next": [ "Other", "B@Loading" ]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- The `JustReturn` field of `algorithm` is not recommended to set as a loop. Otherwise recognition will be always successful in some cases like adb disconnection.
|
||||
Available.
|
||||
|
||||
- Tasks that are required to be executed N times can be copied N times with different names. For example:
|
||||
```cpp
|
||||
Task.get("C")->next = { "B@N1", "B@N2" };
|
||||
|
||||
```jsonc
|
||||
Task.get("B@Loading")->next = { "B@Loading", "Other", "B" };
|
||||
Task.get("Loading")->next = { "Loading" };
|
||||
Task.get_raw("B@Loading")->next = { "B#self", "B#next", "B#back" };
|
||||
```
|
||||
|
||||
#### Some uses
|
||||
|
||||
- When several tasks have `"next": [ "#back" ]`, `"Task1@Task2@Task3"` represents the sequential execution of `Task3`, `Task2`, `Task1`。
|
||||
|
||||
#### Other related
|
||||
|
||||
```json
|
||||
{
|
||||
"DoIt": {
|
||||
"next": [
|
||||
"DoItAgain"
|
||||
]
|
||||
},
|
||||
"DoItAgain": {
|
||||
"next": [
|
||||
"OtherTask"
|
||||
]
|
||||
}
|
||||
"A": { "next": [ "N0" ] },
|
||||
"B": { "next": [ "A#next" ] },
|
||||
"C@A": { "next": [ "N1" ] }
|
||||
}
|
||||
```
|
||||
|
||||
In this case above, `"C@B" -> next` (i.e. `C@A#next`) is `["N1"]` instead of `["C@N0"]`.
|
||||
|
||||
## Schema Check
|
||||
|
||||
This project provides JSON schema check for `tasks.json`. The schema file can be found at `docs/maa_tasks_schema.json`.
|
||||
This project configures a json schema check for `tasks.json`, the schema file is `docs/maa_tasks_schema.json`.
|
||||
|
||||
### Visual Studio
|
||||
|
||||
Visual Studio has been configured with `MaaCore.vcxporj`. Developers should be able to use it directly after loading the project.
|
||||
It is configured in `MaaCore.vcxporj` and works right out of the box. The hint effect is more obscure and some information is missing.
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
Visual Studio Code has been configured with `.vscode/settings.json`. Developeres can open the **project folder** to use it, with better experience than Visual Studio.
|
||||
It is configured in `.vscode/settings.json`, open that **project folder** with vscode and you are ready to use it. The hint works better.
|
||||
|
||||
@@ -1,157 +1,232 @@
|
||||
# 任務流程協定
|
||||
# 任務流程協議
|
||||
|
||||
`resource/tasks.json` 的使用方法及各欄位說明
|
||||
`resource/tasks.json` 的使用方法及各字段說明
|
||||
|
||||
## 完整欄位一覽
|
||||
## 完整字段一覽
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"TaskName" : { // 任務名
|
||||
|
||||
"algorithm": "MatchTemplate", // 可選項,表示辨識算法的類型
|
||||
// 不填寫時預設為 MatchTemplate
|
||||
// - JustReturn: 不進行辨識,直接執行 action
|
||||
"baseTask": "xxx", // 以xxx任務為範本生成任務,詳細見下方特殊任務類型中的Base Task
|
||||
|
||||
"algorithm": "MatchTemplate", // 可選項,表示識別演算法的類型
|
||||
// 不填寫時默認為 MatchTemplate
|
||||
// - JustReturn: 不進行識別,直接執行 action
|
||||
// - MatchTemplate: 匹配圖片
|
||||
// - OcrDetect: 字元辨識
|
||||
// - Hash: 雜湊計算
|
||||
// - OcrDetect: 文字識別
|
||||
// - Hash: 哈希計算
|
||||
|
||||
"template": "xxx.png", // 僅當 algorithm 為 MatchTemplate 時有效;可選項,要匹配的圖片檔案名
|
||||
// 不填時寫預設 "任務名.png"
|
||||
|
||||
"text": [ "接管作戰", "代理指揮" ], // 僅當 algorithm 為 OcrDetect 時有效;必選項,要辨識的文字內容,只要任一匹配上了即認為辨識到了
|
||||
|
||||
"action": "ClickSelf", // 可選項,表示辨識到後的動作
|
||||
// 不填寫時預設為 DoNothing
|
||||
// - ClickSelf: 點擊辨識到的位置(辨識到的目標範圍內隨機點)
|
||||
// - ClickRand: 點擊整個畫面中隨機位置
|
||||
// - DoNothing: 什麼都不做
|
||||
// - Stop: 停止當前任務
|
||||
// - ClickRect: 點擊指定的區域,對應 specificRect 欄位,不建議使用該選項
|
||||
// - SwipeToTheLeft: 滑動到最左側
|
||||
// - SwipeToTheRight: 滑動到最右側
|
||||
// - SlowlySwipeToTheLeft: 緩慢左滑
|
||||
// - SlowlySwipeToTheRight: 緩慢右滑
|
||||
"action": "ClickSelf", // 可選項,表示識別到後的動作
|
||||
// 不填寫時默認為 DoNothing
|
||||
// - ClickSelf: 點擊識別到的位置(識別到的目標範圍內隨機點)
|
||||
// - ClickRand: 點擊整個畫面中隨機位置
|
||||
// - ClickRect: 點擊指定的區域,對應 specificRect 字段,不建議使用該選項
|
||||
// - DoNothing: 什麼都不做
|
||||
// - Stop: 停止當前任務
|
||||
// - Swipe: 滑動,對應 specificRect 與 rectMove 字段
|
||||
|
||||
"sub": [ "SubTaskName1", "SubTaskName2" ],
|
||||
// 可選項,子任務。會在執行完當前任務後,依次執行每一個子任務
|
||||
// 可以套娃,子任務再套子任務。但要注意不要寫出了無窮迴圈
|
||||
// 可以套娃,子任務再套子任務。但要注意不要寫出了死迴圈
|
||||
|
||||
"subErrorIgnored": true, // 可選項,是否忽略子任務的錯誤。
|
||||
// 不填寫預設 false
|
||||
// 不填寫默認 false
|
||||
// 為 false 時,若某個子任務出錯,則不繼續執行後續任務(相當於本任務出錯了)
|
||||
// 為 true 時,子任務是否出錯沒有影響
|
||||
|
||||
"next": [ "OtherTaskName1", "OtherTaskName2"],
|
||||
"next": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// 可選項,表示執行完當前任務和 sub 任務後,下一個要執行的任務
|
||||
// 會從前往後依次去辨識,去執行第一個匹配上的
|
||||
// 不填寫預設執行完當前任務直接停止
|
||||
// 會從前往後依次去識別,去執行第一個匹配上的
|
||||
// 不填寫默認執行完當前任務直接停止
|
||||
// 對於相同任務,第一次識別後第二次就不再識別:
|
||||
// "next": [ "A", "B", "A", "A" ] -> "next": [ "A", "B" ]
|
||||
// 不允許 JustReturn 型任務位於非最後一項
|
||||
|
||||
"maxTimes": 10, // 可選項,表示該任務最大執行次數
|
||||
// 不填寫時預設無窮大
|
||||
// 達到最大次數後,若存在 exceededNext 欄位,則執行 exceededNext;否則直接任務停止
|
||||
// 不填寫時默認無窮大
|
||||
// 達到最大次數後,若存在 exceededNext 字段,則執行 exceededNext;否則直接任務停止
|
||||
|
||||
"exceededNext": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// 可選項,表示達到了最大執行次數後要執行的任務
|
||||
// 不填寫時,達到了最大執行次數則停止;填寫後就執行這裡的,而不是 next 裡的
|
||||
// 不填寫時,達到了最大執行次數則停止;填寫後就執行這裏的,而不是 next 裏的
|
||||
"onErrorNext": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// 可選項,表示執行出錯時,後續要執行的任務
|
||||
|
||||
"preDelay": 1000, // 可選項,表示辨識到後延遲多久才執行 action,單位毫秒;不填寫時預設 0
|
||||
"postDelay": 1000, // 可選項,表示 action 執行完後延遲多久才去辨識 next, 單位毫秒;不填寫時預設 0
|
||||
"preDelay": 1000, // 可選項,表示識別到後延遲多久才執行 action,單位毫秒;不填寫時默認 0
|
||||
"postDelay": 1000, // 可選項,表示 action 執行完後延遲多久才去識別 next, 單位毫秒;不填寫時默認 0
|
||||
|
||||
"roi": [ 0, 0, 1280, 720], // 可選項,表示辨識的範圍,格式為 [ x, y, width, height ]
|
||||
// 以 1280 * 720 為基準自動縮放;不填寫時預設 [ 0, 0, 1280, 720 ]
|
||||
// 盡量填寫,減小辨識範圍可以減少性能消耗,加快辨識速度
|
||||
"roi": [ 0, 0, 1280, 720 ], // 可選項,表示識別的範圍,格式為 [ x, y, width, height ]
|
||||
// 以 1280 * 720 為基準自動縮放;不填寫時默認 [ 0, 0, 1280, 720 ]
|
||||
// 儘量填寫,減小識別範圍可以減少性能消耗,加快識別速度
|
||||
|
||||
"cache": true, // 可選項,表示該任務是否使用快取,預設為 true;
|
||||
// 第一次辨識到後,以後永遠只在第一次辨識到的位置進行辨識,開啟可大幅節省性能
|
||||
// 但僅適用於待辨識目標位置完全不會變的任務,若待辨識目標位置會變請設為 false
|
||||
"cache": true, // 可選項,表示該任務是否使用緩存,默認為 true;
|
||||
// 第一次識別到後,以後永遠只在第一次識別到的位置進行識別,開啟可大幅節省性能
|
||||
// 但僅適用於待識別目標位置完全不會變的任務,若待識別目標位置會變請設為 false
|
||||
|
||||
"rectMove": [ 0, 0, 0, 0 ], // 可選項,識別後的目標移動,不建議使用該選項。以 1280 * 720 為基準自動縮放
|
||||
// 例如識別到了 A ,但實際要點擊的是 A 下方 10 像素 5 * 2 區域的某個位置,
|
||||
// 則可填寫[ 0, 10, 5, 2 ],可以的話儘量直接識別要點擊的位置,不建議使用該選項
|
||||
// 額外的,當 action 為 Swipe 時有效且必選,表示滑動終點。
|
||||
|
||||
"rectMove": [0, 0, 0, 0], // 可選項,辨識後的目標移動,不建議使用該選項。以 1280 * 720 為基準自動縮放
|
||||
// 例如辨識到了 A 圖示,但實際要點擊的是 A 圖示旁邊的某個位置,則進行移動後再點擊。
|
||||
// 可以的話盡量直接辨識要點擊的位置,不建議使用該選項
|
||||
|
||||
"reduceOtherTimes": [ "OtherTaskName1", "OtherTaskName2" ],
|
||||
// 可選項,執行後減少其他任務的執行計數。
|
||||
// 例如執行了吃理智藥,則說明上一次點擊藍色開始行動按鈕沒生效,所以藍色開始行動要-1
|
||||
|
||||
"specificRect": [ 100, 100, 50, 50],
|
||||
// 僅當 action 為 ClickRect 時有效且必選,表示指定的點擊位置(範圍內隨機一點)。
|
||||
"specificRect": [ 100, 100, 50, 50 ],
|
||||
// 當 action 為 ClickRect 時有效且必選,表示指定的點擊位置(範圍內隨機一點)。
|
||||
// 當 action 為 Swipe 時有效且必選,表示滑動起點。
|
||||
// 以 1280 * 720 為基準自動縮放
|
||||
|
||||
/* 以下欄位僅當 algorithm 為 MatchTemplate 時有效 */
|
||||
|
||||
"templThreshold": 0.8, // 可選項,圖片模板匹配得分的閾值,超過閾值才認為辨識到了。
|
||||
// 預設 0.8, 可根據紀錄查看實際得分是多少
|
||||
"specialParams": [ int, ... ], // 某些特殊識別器需要的參數
|
||||
// 額外的,當 action 為 Swipe 時可選,[0] 表示 duration,[1] 表示 是否啟用額外滑動
|
||||
|
||||
"maskRange": [ 1, 255 ], // 可選項,灰階遮罩範圍。例如將圖片不需要辨識的部分塗成黑色(灰階值為 0)
|
||||
/* 以下字段僅當 algorithm 為 MatchTemplate 時有效 */
|
||||
|
||||
"template": "xxx.png", // 可選項,要匹配的圖片檔案名
|
||||
// 默認 "任務名.png"
|
||||
|
||||
"templThreshold": 0.8, // 可選項,圖片範本匹配得分的閾值,超過閾值才認為識別到了。
|
||||
// 默認 0.8, 可根據日誌查看實際得分是多少
|
||||
|
||||
"maskRange": [ 1, 255 ], // 可選項,灰度掩碼範圍。例如將圖片不需要識別的部分塗成黑色(灰度值為 0)
|
||||
// 然後設置"maskRange"的範圍為 [ 1, 255 ], 匹配的時候即刻忽略塗黑的部分
|
||||
|
||||
/* 以下字段僅當 algorithm 為 OcrDetect 時有效 */
|
||||
|
||||
/* 以下欄位僅當 algorithm 為 OcrDetect 時有效 */
|
||||
"text": [ "接管作戰", "代理指揮" ], // 必選項,要識別的文字內容,只要任一匹配上了即認為識別到了
|
||||
|
||||
"fullMatch": false, // 可選項,文字辨識是否需要全字匹配(不能多字),預設為 false
|
||||
// false 時只要是子串即可:例如 text: [ "開始" ],實際辨識到了 "開始行動",也算辨識成功;
|
||||
// true 時則必須辨識到了 "開始",多一個字都不行
|
||||
|
||||
"ocrReplace": [ // 可選項,針對常見辨識錯的文字進行替換(支持正規表示式)
|
||||
[ "乾員", "幹員" ],
|
||||
"ocrReplace": [ // 可選項,針對常見識別錯的文字進行替換(支持正則)
|
||||
[ "千員", "幹員" ],
|
||||
[ ".+擊幹員", "狙擊幹員" ]
|
||||
]
|
||||
],
|
||||
|
||||
/* 以下欄位僅當 algorithm 為 Hash 時有效 */
|
||||
// 算法不成熟,僅部分特例情況中用到了,暫不推薦使用
|
||||
"fullMatch": false, // 可選項,文字識別是否需要全字匹配(不能多字),默認為 false
|
||||
// false 時只要是子串即可:例如 text: [ "開始" ],實際識別到了 "開始行動",也算識別成功;
|
||||
// true 時則必須識別到了 "開始",多一個字都不行
|
||||
|
||||
"isAscii": false, // 可選項,要識別的文字內容是否為 ASCII 碼字元
|
||||
// 不填寫默認 false
|
||||
|
||||
"withoutDet": false // 可選項,是否不使用檢測模型
|
||||
// 不填寫默認 false
|
||||
|
||||
/* 以下字段僅當 algorithm 為 Hash 時有效 */
|
||||
// 演算法不成熟,僅部分特例情況中用到了,暫不推薦使用
|
||||
// Todo
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 一些小技巧
|
||||
## 特殊任務類型
|
||||
|
||||
- `next` 中再填寫自身的任務名,可形成迴圈。例如
|
||||
### Template Task(`@` 型任務)
|
||||
|
||||
```jsonc
|
||||
Template task 與 base task 合稱**範本任務**。
|
||||
|
||||
允許把某個任務 "A" 當作範本,然後 "B@A" 表示由 "A" 生成的任務。
|
||||
|
||||
- 如果 `tasks.json` 中未顯式定義任務 "B@A",則在 `sub`, `next`, `onErrorNext`, `exceededNext`, `reduceOtherTimes` 字段中增加 `B@` 首碼(如遇任務名開頭為 `#` 則增加 `B` 首碼),其餘參數與 "A" 任務相同。就是說如果任務 "A" 有以下參數:
|
||||
|
||||
```jsonc
|
||||
"A": {
|
||||
"template": "A.png",
|
||||
...,
|
||||
"next": [ "N1", "N2" ]
|
||||
}
|
||||
```
|
||||
|
||||
就相當於同時定義了
|
||||
|
||||
```jsonc
|
||||
"B@A": {
|
||||
"template": "A.png",
|
||||
...,
|
||||
"next": [ "B@N1", "B@N2" ]
|
||||
}
|
||||
```
|
||||
|
||||
- 如果 `tasks.json` 中定義了任務 "B@A",則:
|
||||
1. 如果 "B@A" 與 "A" 的 `algorithm` 字段不同,則派生類參數不繼承(只繼承 `TaskInfo` 定義的參數)
|
||||
2. 如果是圖像匹配任務,`template` 若未顯式定義則為 `B@A.png`(而不是繼承"A"的 `template` 名),其餘情況任何派生類參數若未顯式定義,直接繼承 "A" 任務的參數
|
||||
3. 對於 `TaskInfo` 基類中定義的參數(任何類型任務都有的參數,例如 `algorithm`, `roi`, `next` 等),若沒有在 "B@A" 內顯式定義,則除了上面提到的 `sub` 等五個字段在繼承時會增加 "B@" 首碼外,其餘參數直接繼承 "A" 任務的參數
|
||||
|
||||
### Base Task
|
||||
|
||||
Base task 與 template task 合稱**範本任務**。
|
||||
|
||||
有字段 `baseTask` 的任務即為 base task。
|
||||
|
||||
除了 `template` 未顯式定義時仍為 `"任務名.png"`,其餘任何參數若未顯式定義直接使用 `baseTask` 對應任務的參數。(不加首碼)
|
||||
|
||||
#### 其他相關
|
||||
|
||||
- 外服 `tasks.json` 中定義的同名任務直接繼承國服 `tasks.json` 的參數,相當於 `"A": { "baseTask": "國服的A" }`
|
||||
- 如果國服 `tasks.json` 中定義了任務 "B@A",外服 `tasks.json` 中也定義了 "B@A",那麼
|
||||
1. 如果外服 "B@A" 有字段 `"baseTask": ""`,則不繼承國服 "B@A"
|
||||
- 若有定義任務 "A",則以 template task 的邏輯處理 "B@A"
|
||||
- 若未定義任務 "A",則以普通任務的邏輯處理 "B@A"
|
||||
2. 如果外服 "B@A" 沒有 `baseTask`,則直接繼承國服 "B@A" 參數
|
||||
|
||||
### Virtual Task(虛任務)
|
||||
|
||||
Virtual task 也稱 sharp task(`#` 型任務)。
|
||||
|
||||
任務名帶 `#` 的任務即為 virtual task。 `#` 後可接 `next`, `back`, `self`, `sub`, `on_error_next`, `exceeded_next`, `reduce_other_times`。
|
||||
|
||||
| 虛任務類型 | 含義 | 簡單示例 |
|
||||
|:---------:|:---:|:--------:|
|
||||
| self | 父任務名 | `"A": {"next": "#self"}` 中的 `"#self"` 被解釋為 `"A"`<br>`"B": {"next": "A@B@C#self"}` 中的 `"A@B@C#self"` 被解釋為 `"B"`。<sup>1</sup> |
|
||||
| back | # 前面的任務名 | `"A@B#back"` 被解釋為 `"A@B"`<br>`"#back"` 直接出現則會被跳過 |
|
||||
| next, sub 等 | # 前任務名對應字段 | 以 `next` 為例:<br>`"A#next"` 被解釋為 `Task.get("A")->next`<br>`"#next"` 直接出現則會被跳過 |
|
||||
|
||||
_Note<sup>1</sup>: `"XXX#self"` 與 `"#self"` 含義相同。_
|
||||
|
||||
#### 簡單示例
|
||||
|
||||
```json
|
||||
{
|
||||
"Waiting": {
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [ "正在加載" ],
|
||||
"next": [
|
||||
"Succeed", // 首先辨識 "加載完成",
|
||||
"Waiting" // 如果沒辨識到,再辨識 "正在加載"
|
||||
]
|
||||
"A": { "next": [ "N1", "N2" ] },
|
||||
"C": { "next": [ "B@A#next" ] },
|
||||
|
||||
"Loading": {
|
||||
"next": [ "#self", "#next", "#back" ]
|
||||
},
|
||||
"Succeed": {
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [ "加載完成" ],
|
||||
"next": [
|
||||
"OtherTask"
|
||||
]
|
||||
"B": {
|
||||
"next": [ "Other", "B@Loading" ]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `algorithm` 的 `JustReturn` 不建議形成迴圈,如果出現 adb 斷開等情況,會出現一直當做辨識成功
|
||||
可以得到:
|
||||
|
||||
- 某些任務每次要執行 N 次,可將該任務複製 N 遍,分別取不同的名字,例如
|
||||
```cpp
|
||||
Task.get("C")->next = { "B@N1", "B@N2" };
|
||||
|
||||
```jsonc
|
||||
Task.get("B@Loading")->next = { "B@Loading", "Other", "B" };
|
||||
Task.get("Loading")->next = { "Loading" };
|
||||
Task.get_raw("B@Loading")->next = { "B#self", "B#next", "B#back" };
|
||||
```
|
||||
|
||||
#### 一些用途
|
||||
|
||||
- 當幾個任務有 `"next": [ "#back" ]` 時,`"Task1@Task2@Task3"` 代表依次執行 `Task3`, `Task2`, `Task1`。
|
||||
|
||||
#### 其他相關
|
||||
|
||||
```json
|
||||
{
|
||||
"DoIt": {
|
||||
"next": [
|
||||
"DoItAgain"
|
||||
]
|
||||
},
|
||||
"DoItAgain": {
|
||||
"next": [
|
||||
"OtherTask"
|
||||
]
|
||||
}
|
||||
"A": { "next": [ "N0" ] },
|
||||
"B": { "next": [ "A#next" ] },
|
||||
"C@A": { "next": [ "N1" ] }
|
||||
}
|
||||
```
|
||||
|
||||
以上這種情況, `"C@B" -> next`(即 `C@A#next`)為 `[ "N1" ]` 而不是 `[ "C@N0" ]`.
|
||||
|
||||
## Schema 檢驗
|
||||
|
||||
本項目為 `tasks.json` 配置了 json schema 檢驗,schema 檔案為`docs/maa_tasks_schema.json`。
|
||||
本項目為 `tasks.json` 配置了 json schema 檢驗,schema 檔為`docs/maa_tasks_schema.json`。
|
||||
|
||||
### Visual Studio
|
||||
|
||||
@@ -159,4 +234,5 @@
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
在 `.vscode/settings.json` 中已對其進行配置,用 vscode 打開該**項目資料夾**即可使用。提示效果較好。
|
||||
在 `.vscode/settings.json` 中已對其進行配置,用 vscode 打開該**專案檔夾**即可使用。提示效果較好。
|
||||
|
||||
|
||||
2
tools/CropRoi/start.bat
Normal file
2
tools/CropRoi/start.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
python main.py
|
||||
pause
|
||||
Reference in New Issue
Block a user