mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
update configer
This commit is contained in:
@@ -197,7 +197,7 @@
|
||||
</ImportGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties _1_1_4resource_4config_1json__JsonSchema="https://beaujs.com/schema.json" />
|
||||
<UserProperties _1_1_4resource_4config_1json__JsonSchema="" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -40,10 +40,12 @@ namespace asst {
|
||||
struct TaskInfo {
|
||||
std::string filename;
|
||||
double threshold = 0;
|
||||
double cache_threshold = 0;
|
||||
TaskType type;
|
||||
std::vector<std::string> next;
|
||||
int exec_times = 0;
|
||||
int max_times = INT_MAX;
|
||||
std::vector<std::string> exceeded_next;
|
||||
asst::Rect specific_area;
|
||||
int pre_delay = 0;
|
||||
int rear_delay = 0;
|
||||
@@ -70,6 +72,9 @@ namespace asst {
|
||||
static std::optional<std::string> getParam(const std::string& type, const std::string& param);
|
||||
|
||||
static void clearExecTimes();
|
||||
|
||||
constexpr static double DefaultThreshold = 0.98;
|
||||
constexpr static double DefaultCacheThreshold = 0.9998;
|
||||
private:
|
||||
Configer() = default;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ std::optional<std::string> Assistance::setSimulator(const std::string& simulator
|
||||
else {
|
||||
ret = create_handles(simulator_name);
|
||||
}
|
||||
if (ret && m_pWindow->showWindow() && m_pWindow->resizeWindow() ) {
|
||||
if (ret && m_pWindow->showWindow() && m_pWindow->resizeWindow()) {
|
||||
m_inited = true;
|
||||
return cor_name;
|
||||
}
|
||||
@@ -121,12 +121,13 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
std::string matched_task;
|
||||
Rect matched_rect;
|
||||
for (auto&& task_name : pThis->m_next_tasks) {
|
||||
double threshold = Configer::m_tasks[task_name].threshold;
|
||||
auto&& task = Configer::m_tasks[task_name];
|
||||
double threshold = task.threshold;
|
||||
auto&& [algorithm, value, rect] = pThis->m_pIder->findImage(curImg, task_name, threshold);
|
||||
DebugTrace(task_name, "Type:", algorithm, "Value:", value);
|
||||
if (algorithm == 0 ||
|
||||
(algorithm == 1 && value >= threshold)
|
||||
|| (algorithm == 2 && value >= 0.9998)) {
|
||||
|| (algorithm == 2 && value >= task.cache_threshold)) {
|
||||
matched_task = task_name;
|
||||
matched_rect = rect;
|
||||
break;
|
||||
@@ -134,47 +135,49 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
}
|
||||
|
||||
if (!matched_task.empty()) {
|
||||
auto && task = Configer::m_tasks[matched_task];
|
||||
DebugTraceInfo("Matched:", matched_task, "Type:", static_cast<int>(task.type));
|
||||
auto&& task = Configer::m_tasks[matched_task];
|
||||
DebugTraceInfo("***Matched***", matched_task, "Type:", static_cast<int>(task.type));
|
||||
if (task.pre_delay > 0) {
|
||||
DebugTrace("PreDelay", task.pre_delay);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(task.pre_delay));
|
||||
}
|
||||
switch (task.type) {
|
||||
case TaskType::ClickRect:
|
||||
matched_rect = task.specific_area;
|
||||
case TaskType::ClickSelf:
|
||||
if (task.max_times != INT_MAX) {
|
||||
DebugTrace("CurTimes:", task.exec_times, "MaxTimes:", task.max_times);
|
||||
}
|
||||
if (task.exec_times >= task.max_times) {
|
||||
DebugTraceInfo("Reached limit, Stop.");
|
||||
|
||||
if (task.max_times != INT_MAX) {
|
||||
DebugTrace("CurTimes:", task.exec_times, "MaxTimes:", task.max_times);
|
||||
}
|
||||
if (task.exec_times < task.max_times) {
|
||||
switch (task.type) {
|
||||
case TaskType::ClickRect:
|
||||
matched_rect = task.specific_area;
|
||||
case TaskType::ClickSelf:
|
||||
pThis->m_pCtrl->clickRange(matched_rect);
|
||||
break;
|
||||
case TaskType::ClickRand:
|
||||
pThis->m_pCtrl->clickRange(pThis->m_pCtrl->getWindowRect());
|
||||
break;
|
||||
case TaskType::DoNothing:
|
||||
break;
|
||||
case TaskType::Stop:
|
||||
DebugTrace("TaskType is Stop");
|
||||
pThis->stop(false);
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
DebugTraceError("Unknown option type:", static_cast<int>(task.type));
|
||||
break;
|
||||
}
|
||||
pThis->m_pCtrl->clickRange(matched_rect);
|
||||
++task.exec_times;
|
||||
break;
|
||||
case TaskType::ClickRand:
|
||||
pThis->m_pCtrl->clickRange(pThis->m_pCtrl->getWindowRect());
|
||||
break;
|
||||
case TaskType::DoNothing:
|
||||
break;
|
||||
case TaskType::Stop:
|
||||
DebugTrace("TaskType is Stop");
|
||||
pThis->stop(false);
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
DebugTraceError("Unknown option type:", static_cast<int>(task.type));
|
||||
break;
|
||||
if (task.rear_delay > 0) {
|
||||
DebugTrace("RearDelay", task.rear_delay);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(task.rear_delay));
|
||||
}
|
||||
pThis->m_next_tasks = Configer::m_tasks[matched_task].next;
|
||||
}
|
||||
if (task.rear_delay > 0) {
|
||||
DebugTrace("RearDelay", task.rear_delay);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(task.rear_delay));
|
||||
else {
|
||||
DebugTraceInfo("Reached limit");
|
||||
pThis->m_next_tasks = Configer::m_tasks[matched_task].exceeded_next;
|
||||
}
|
||||
|
||||
pThis->m_next_tasks = Configer::m_tasks[matched_task].next;
|
||||
std::string nexts_str;
|
||||
for (auto&& name : pThis->m_next_tasks) {
|
||||
nexts_str += name + ",";
|
||||
|
||||
@@ -47,7 +47,18 @@ bool Configer::reload()
|
||||
for (auto&& [name, task_json] : tasks_obj) {
|
||||
TaskInfo task_info;
|
||||
task_info.filename = task_json["filename"].as_string();
|
||||
task_info.threshold = task_json["threshold"].as_double();
|
||||
if (task_json.exist("threshold")) {
|
||||
task_info.threshold = task_json["threshold"].as_double();
|
||||
}
|
||||
else {
|
||||
task_info.threshold = DefaultThreshold;
|
||||
}
|
||||
if (task_json.exist("cache_threshold")) {
|
||||
task_info.cache_threshold = task_json["cache_threshold"].as_double();
|
||||
}
|
||||
else {
|
||||
task_info.cache_threshold = DefaultCacheThreshold;
|
||||
}
|
||||
std::string type = task_json["type"].as_string();
|
||||
std::transform(type.begin(), type.end(), type.begin(), std::tolower);
|
||||
if (type == "clickself") {
|
||||
@@ -78,6 +89,15 @@ bool Configer::reload()
|
||||
if (task_json.exist("maxTimes")) {
|
||||
task_info.max_times = task_json["maxTimes"].as_integer();
|
||||
}
|
||||
if (task_json.exist("exceededNext")) {
|
||||
auto next_arr = task_json["exceededNext"].as_array();
|
||||
for (auto&& name : next_arr) {
|
||||
task_info.exceeded_next.emplace_back(name.as_string());
|
||||
}
|
||||
}
|
||||
else {
|
||||
task_info.exceeded_next.emplace_back("Stop");
|
||||
}
|
||||
if (task_json.exist("preDelay")) {
|
||||
task_info.pre_delay = task_json["preDelay"].as_integer();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
DebugTraceInfo("Start");
|
||||
asst.start("SanityBegin");
|
||||
asst.start("VisitBegin");
|
||||
|
||||
getchar();
|
||||
|
||||
|
||||
BIN
resource/CreditStore.png
Normal file
BIN
resource/CreditStore.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
BIN
resource/Mall.png
Normal file
BIN
resource/Mall.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.0 KiB |
BIN
resource/PopupCancel.png
Normal file
BIN
resource/PopupCancel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
BIN
resource/PopupConfirm.png
Normal file
BIN
resource/PopupConfirm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -242,9 +242,7 @@
|
||||
]
|
||||
},
|
||||
"StartButton2": {
|
||||
"id": 2,
|
||||
"filename": "StartButton2.png",
|
||||
"threshold": 0.99,
|
||||
"type": "clickSelf",
|
||||
"rearDelay": 10000,
|
||||
"next": [
|
||||
@@ -253,7 +251,6 @@
|
||||
},
|
||||
"PRTS": {
|
||||
"filename": "PRTS.png",
|
||||
"threshold": 0.98,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"PRTS",
|
||||
@@ -279,7 +276,6 @@
|
||||
},
|
||||
"Loading": {
|
||||
"filename": "Loading.png",
|
||||
"threshold": 0.99,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"StartButton1"
|
||||
@@ -287,7 +283,6 @@
|
||||
},
|
||||
"UseMedicine": {
|
||||
"filename": "UseMedicine.png",
|
||||
"threshold": 0.99,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"MedicineConfirm"
|
||||
@@ -295,7 +290,6 @@
|
||||
},
|
||||
"MedicineConfirm": {
|
||||
"filename": "MedicineConfirm.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"StartButton1"
|
||||
@@ -303,7 +297,6 @@
|
||||
},
|
||||
"UseStone": {
|
||||
"filename": "UseStone.png",
|
||||
"threshold": 0.99,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"StoneConfirm"
|
||||
@@ -311,7 +304,6 @@
|
||||
},
|
||||
"StoneConfirm": {
|
||||
"filename": "MedicineConfirm.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"maxTimes": 0,
|
||||
"next": [
|
||||
@@ -320,7 +312,6 @@
|
||||
},
|
||||
"PrtsErrorConfirm": {
|
||||
"filename": "PrtsErrorConfirm.png",
|
||||
"threshold": 0.98,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"AbandonAction"
|
||||
@@ -328,7 +319,6 @@
|
||||
},
|
||||
"AbandonAction": {
|
||||
"filename": "AbandonAction.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"Random"
|
||||
@@ -349,7 +339,6 @@
|
||||
},
|
||||
"ReturnToFriends": {
|
||||
"filename": "Return.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"Friends",
|
||||
@@ -358,7 +347,6 @@
|
||||
},
|
||||
"Friends": {
|
||||
"filename": "Friends.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"FriendsList"
|
||||
@@ -366,7 +354,6 @@
|
||||
},
|
||||
"FriendsList": {
|
||||
"filename": "FriendsList.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"StartToVisit"
|
||||
@@ -374,7 +361,6 @@
|
||||
},
|
||||
"StartToVisit": {
|
||||
"filename": "StartToVisit.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"VisitNext"
|
||||
@@ -384,12 +370,47 @@
|
||||
"filename": "VisitNext.png",
|
||||
"threshold": 0.99,
|
||||
"type": "clickSelf",
|
||||
"maxTimes": 20,
|
||||
"maxTimes": 21,
|
||||
"exceededNext": [
|
||||
"ReturnToMall"
|
||||
],
|
||||
"next": [
|
||||
"VisitNext",
|
||||
"VisitNextBlack"
|
||||
]
|
||||
},
|
||||
"ReturnToMall": {
|
||||
"filename": "Return.png",
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"Mall",
|
||||
"ReturnToMall",
|
||||
"ReturnToMallConfirm"
|
||||
]
|
||||
},
|
||||
"ReturnToMallConfirm": {
|
||||
"filename": "PopupConfirm.png",
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"ReturnToMall"
|
||||
]
|
||||
},
|
||||
"Mall": {
|
||||
"filename": "Mall.png",
|
||||
"threshold": 0.94,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"CreditStore"
|
||||
]
|
||||
},
|
||||
"CreditStore": {
|
||||
"filename": "CreditStore.png",
|
||||
"threshold": 0.91,
|
||||
"type": "clickSelf",
|
||||
"next": [
|
||||
"Stop"
|
||||
]
|
||||
},
|
||||
"VisitLimited": {
|
||||
"filename": "VisitLimited.png",
|
||||
"threshold": 0.65,
|
||||
@@ -398,7 +419,14 @@
|
||||
},
|
||||
"VisitNextBlack": {
|
||||
"filename": "VisitNextBlack.png",
|
||||
"threshold": 0.98,
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"ReturnToMall"
|
||||
]
|
||||
},
|
||||
"Stop": {
|
||||
"filename": "",
|
||||
"threshold": 0,
|
||||
"type": "stop",
|
||||
"next": []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user