mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 10:32:19 +08:00
refactor.完成ProcessTask中运行次数相关的重构,废弃SetParam接口
This commit is contained in:
@@ -26,7 +26,7 @@ extern "C" {
|
||||
|
||||
bool MEOAPI AsstStart(void* p_asst);
|
||||
bool MEOAPI AsstStop(void* p_asst);
|
||||
bool MEOAPI AsstSetParam(void* p_asst, const char* type, const char* param, const char* value);
|
||||
//bool MEOAPI AsstSetParam(void* p_asst, const char* type, const char* param, const char* value);
|
||||
|
||||
MEOAPI_PORT const char* MEO_CALL AsstGetVersion();
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -140,32 +140,27 @@ bool asst::Assistance::catch_fake()
|
||||
|
||||
bool asst::Assistance::append_fight(int mecidine, int stone, int times, bool only_append)
|
||||
{
|
||||
if (mecidine > 0) {
|
||||
set_param("task.action", "MedicineConfirm", "doNothing");
|
||||
set_param("task.maxTimes", "MedicineConfirm", std::to_string(mecidine));
|
||||
}
|
||||
else {
|
||||
set_param("task.action", "MedicineConfirm", "stop");
|
||||
set_param("task.maxTimes", "MedicineConfirm", "0");
|
||||
LogTraceFunction;
|
||||
if (!m_inited) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stone > 0) {
|
||||
set_param("task.action", "StoneConfirm", "doNothing");
|
||||
set_param("task.maxTimes", "StoneConfirm", std::to_string(stone));
|
||||
}
|
||||
else {
|
||||
set_param("task.action", "StoneConfirm", "stop");
|
||||
set_param("task.maxTimes", "StoneConfirm", "0");
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
|
||||
auto task_ptr = std::make_shared<ProcessTask>(task_callback, (void*)this);
|
||||
task_ptr->set_task_chain("Sanity");
|
||||
task_ptr->set_tasks({ "SanityBegin" });
|
||||
task_ptr->set_times_limit("MedicineConfirm", mecidine);
|
||||
task_ptr->set_times_limit("StoneConfirm", stone);
|
||||
task_ptr->set_times_limit("StartButton1", times);
|
||||
|
||||
m_tasks_queue.emplace(task_ptr);
|
||||
|
||||
if (!only_append) {
|
||||
start(false);
|
||||
}
|
||||
|
||||
if (times > 0) {
|
||||
set_param("task.maxTimes", "StartButton1", std::to_string(times));
|
||||
}
|
||||
else {
|
||||
set_param("task.maxTimes", "StartButton1", "0");
|
||||
}
|
||||
|
||||
return append_process_task("SanityBegin", ProcessTaskRetryTimesDefault, "Sanity", only_append);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::Assistance::append_receive_award(bool only_append)
|
||||
@@ -385,14 +380,6 @@ bool Assistance::stop(bool block)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Assistance::set_param(const std::string& type, const std::string& param, const std::string& value)
|
||||
{
|
||||
LogTraceFunction;
|
||||
log.trace("SetParam |", type, param, value);
|
||||
|
||||
return task.set_param(type, param, value);
|
||||
}
|
||||
|
||||
void Assistance::working_proc()
|
||||
{
|
||||
LogTraceFunction;
|
||||
@@ -426,7 +413,7 @@ void Assistance::working_proc()
|
||||
task_callback(AsstMsg::TaskError, task_json, this);
|
||||
}
|
||||
|
||||
clear_cache();
|
||||
//clear_cache();
|
||||
|
||||
auto& delay = resource.cfg().get_options().task_delay;
|
||||
m_condvar.wait_until(lock, start_time + std::chrono::milliseconds(delay),
|
||||
@@ -508,9 +495,7 @@ void asst::Assistance::append_callback(AsstMsg msg, json::value detail)
|
||||
|
||||
void Assistance::clear_cache()
|
||||
{
|
||||
task.clear_exec_times();
|
||||
resource.templ().clear_hists();
|
||||
//resource.item().clear_drop_count();
|
||||
}
|
||||
|
||||
json::value asst::Assistance::organize_stage_drop(const json::value& rec)
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace asst
|
||||
// 停止任务队列并清空
|
||||
bool stop(bool block = true);
|
||||
|
||||
bool set_param(const std::string& type, const std::string& param, const std::string& value);
|
||||
[[deprecated]] bool set_param(const std::string& type, const std::string& param, const std::string& value);
|
||||
|
||||
static constexpr int ProcessTaskRetryTimesDefault = 20;
|
||||
static constexpr int OpenRecruitTaskRetyrTimesDefault = 5;
|
||||
|
||||
@@ -193,14 +193,14 @@ bool AsstStop(void* p_asst)
|
||||
return ((asst::Assistance*)p_asst)->stop();
|
||||
}
|
||||
|
||||
bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value)
|
||||
{
|
||||
if (p_asst == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((asst::Assistance*)p_asst)->set_param(type, param, value);
|
||||
}
|
||||
//bool AsstSetParam(void* p_asst, const char* type, const char* param, const char* value)
|
||||
//{
|
||||
// if (p_asst == nullptr) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return ((asst::Assistance*)p_asst)->set_param(type, param, value);
|
||||
//}
|
||||
|
||||
const char* AsstGetVersion()
|
||||
{
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace asst
|
||||
ProcessTaskAction action = // 要进行的操作
|
||||
ProcessTaskAction::Invalid;
|
||||
std::vector<std::string> next; // 下一个可能的任务(列表)
|
||||
int exec_times = 0; // 任务已执行了多少次
|
||||
[[ deprecated ]] int exec_times = 0; // [已废弃] 任务已执行了多少次
|
||||
int max_times = INT_MAX; // 任务最多执行多少次
|
||||
std::vector<std::string> exceeded_next; // 达到最多次数了之后,下一个可能的任务(列表)
|
||||
std::vector<std::string> reduce_other_times; // 执行了该任务后,需要减少别的任务的执行次数。例如执行了吃理智药,则说明上一次点击蓝色开始行动按钮没生效,所以蓝色开始行动要-1
|
||||
|
||||
@@ -35,6 +35,9 @@ bool ProcessTask::_run()
|
||||
|
||||
auto& task_delay = resource.cfg().get_options().task_delay;
|
||||
while (!m_cur_tasks_name.empty()) {
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
Rect rect;
|
||||
std::shared_ptr<TaskInfo> task_info_ptr;
|
||||
// 如果第一个任务是JustReturn的,那就没必要再截图并计算了
|
||||
@@ -62,17 +65,25 @@ bool ProcessTask::_run()
|
||||
rect.height = res_move.height;
|
||||
}
|
||||
|
||||
int& exec_times = m_exec_times[task_info_ptr->name];
|
||||
|
||||
json::value callback_json = json::object{
|
||||
{ "name", task_info_ptr->name },
|
||||
{ "type", static_cast<int>(task_info_ptr->action) },
|
||||
{ "exec_times", task_info_ptr->exec_times },
|
||||
{ "exec_times", exec_times },
|
||||
{ "max_times", task_info_ptr->max_times },
|
||||
{ "task_type", "ProcessTask" },
|
||||
{ "algorithm", static_cast<int>(task_info_ptr->algorithm) }
|
||||
};
|
||||
m_callback(AsstMsg::TaskMatched, callback_json, m_callback_arg);
|
||||
|
||||
if (task_info_ptr->exec_times >= task_info_ptr->max_times) {
|
||||
int max_times = task_info_ptr->max_times;
|
||||
if (auto iter = m_times_limit.find(task_info_ptr->name);
|
||||
iter != m_times_limit.cend()) {
|
||||
max_times = iter->second;
|
||||
}
|
||||
|
||||
if (exec_times >= max_times) {
|
||||
m_callback(AsstMsg::ReachedLimit, callback_json, m_callback_arg);
|
||||
|
||||
json::value next_json = callback_json;
|
||||
@@ -134,20 +145,20 @@ bool ProcessTask::_run()
|
||||
break;
|
||||
}
|
||||
|
||||
++task_info_ptr->exec_times;
|
||||
++exec_times;
|
||||
|
||||
// 减少其他任务的执行次数
|
||||
// 例如,进入吃理智药的界面了,相当于上一次点蓝色开始行动没生效
|
||||
// 所以要给蓝色开始行动的次数减一
|
||||
for (const std::string& reduce : task_info_ptr->reduce_other_times) {
|
||||
--task.get(reduce)->exec_times;
|
||||
--m_exec_times[reduce];
|
||||
}
|
||||
|
||||
if (need_stop) {
|
||||
return true;
|
||||
}
|
||||
|
||||
callback_json["exec_times"] = task_info_ptr->exec_times;
|
||||
callback_json["exec_times"] = exec_times;
|
||||
m_callback(AsstMsg::TaskCompleted, callback_json, m_callback_arg);
|
||||
|
||||
// 后置固定延时
|
||||
|
||||
@@ -15,10 +15,14 @@ namespace asst
|
||||
|
||||
virtual ~ProcessTask() = default;
|
||||
|
||||
virtual void set_tasks(std::vector<std::string> tasks_name) noexcept
|
||||
void set_tasks(std::vector<std::string> tasks_name) noexcept
|
||||
{
|
||||
m_cur_tasks_name = std::move(tasks_name);
|
||||
}
|
||||
void set_times_limit(std::string name, int limit)
|
||||
{
|
||||
m_times_limit.emplace(std::move(name), limit);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool _run() override;
|
||||
@@ -27,5 +31,7 @@ namespace asst
|
||||
void exec_swipe_task(ProcessTaskAction action);
|
||||
|
||||
std::vector<std::string> m_cur_tasks_name;
|
||||
std::unordered_map<std::string, int> m_times_limit;
|
||||
std::unordered_map<std::string, int> m_exec_times;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,51 +8,6 @@
|
||||
#include "GeneralConfiger.h"
|
||||
#include "TemplResource.h"
|
||||
|
||||
bool asst::TaskData::set_param(const std::string& type, const std::string& param, const std::string& value)
|
||||
{
|
||||
// 暂时只用到了这些,总的参数太多了,后面要用啥再加上
|
||||
if (type == "task.action") {
|
||||
if (auto iter = m_all_tasks_info.find(param);
|
||||
iter == m_all_tasks_info.cend()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
auto& task_info_ptr = iter->second;
|
||||
std::string action = value;
|
||||
std::transform(action.begin(), action.end(), action.begin(), ::tolower);
|
||||
if (action == "clickself") {
|
||||
task_info_ptr->action = ProcessTaskAction::ClickSelf;
|
||||
}
|
||||
else if (action == "clickrand") {
|
||||
task_info_ptr->action = ProcessTaskAction::ClickRand;
|
||||
}
|
||||
else if (action == "donothing" || action.empty()) {
|
||||
task_info_ptr->action = ProcessTaskAction::DoNothing;
|
||||
}
|
||||
else if (action == "stop") {
|
||||
task_info_ptr->action = ProcessTaskAction::Stop;
|
||||
}
|
||||
else if (action == "clickrect") {
|
||||
task_info_ptr->action = ProcessTaskAction::ClickRect;
|
||||
}
|
||||
else {
|
||||
m_last_error = "Task " + param + " 's action error: " + action;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "task.maxTimes") {
|
||||
if (auto iter = m_all_tasks_info.find(param);
|
||||
iter == m_all_tasks_info.cend()) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
iter->second->max_times = std::stoi(value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::shared_ptr<asst::TaskInfo> asst::TaskData::get(const std::string& name) const noexcept
|
||||
{
|
||||
if (auto iter = m_all_tasks_info.find(name);
|
||||
@@ -74,13 +29,6 @@ std::shared_ptr<asst::TaskInfo> asst::TaskData::get(std::string name)
|
||||
return m_all_tasks_info[std::move(name)];
|
||||
}
|
||||
|
||||
void asst::TaskData::clear_exec_times()
|
||||
{
|
||||
for (auto&& [key, task] : m_all_tasks_info) {
|
||||
task->exec_times = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool asst::TaskData::parse(const json::value& json)
|
||||
{
|
||||
for (const auto& [name, task_json] : json.as_object()) {
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace asst
|
||||
return unique_instance;
|
||||
}
|
||||
|
||||
bool set_param(const std::string& type, const std::string& param, const std::string& value);
|
||||
[[deprecated]] bool set_param(const std::string& type, const std::string& param, const std::string& value);
|
||||
|
||||
const std::shared_ptr<TaskInfo> get(const std::string& name) const noexcept;
|
||||
const std::unordered_set<std::string>& get_templ_required() const noexcept;
|
||||
std::shared_ptr<TaskInfo> get(std::string name);
|
||||
void clear_exec_times();
|
||||
[[deprecated]] void clear_exec_times();
|
||||
|
||||
protected:
|
||||
TaskData() = default;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace MeoAsstGui
|
||||
|
||||
[DllImport("MeoAssistance.dll")] private static extern bool AsstStop(IntPtr ptr);
|
||||
|
||||
[DllImport("MeoAssistance.dll")] private static extern bool AsstSetParam(IntPtr p_asst, string type, string param, string value);
|
||||
//[DllImport("MeoAssistance.dll")] private static extern bool AsstSetParam(IntPtr p_asst, string type, string param, string value);
|
||||
|
||||
private CallbackDelegate _callback;
|
||||
|
||||
@@ -327,10 +327,10 @@ namespace MeoAsstGui
|
||||
return AsstStop(_ptr);
|
||||
}
|
||||
|
||||
public void AsstSetParam(string type, string param, string value)
|
||||
{
|
||||
AsstSetParam(_ptr, type, param, value);
|
||||
}
|
||||
//public void AsstSetParam(string type, string param, string value)
|
||||
//{
|
||||
// AsstSetParam(_ptr, type, param, value);
|
||||
//}
|
||||
}
|
||||
|
||||
public enum AsstMsg
|
||||
|
||||
@@ -92,22 +92,6 @@ namespace MeoAsstGui
|
||||
{
|
||||
SetAndNotify(ref _useMedicine, value);
|
||||
ViewStatusStorage.Set("MainFunction.UseMedicine", value.ToString());
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
if (value)
|
||||
{
|
||||
asstProxy.AsstSetParam("task.action", "UseMedicine", "doNothing");
|
||||
int count;
|
||||
if (!int.TryParse(MedicineNumber, out count))
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
asstProxy.AsstSetParam("task.maxTimes", "MedicineConfirm", count.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
asstProxy.AsstSetParam("task.action", "MedicineConfirm", "stop");
|
||||
asstProxy.AsstSetParam("task.maxTimes", "MedicineConfirm", "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,22 +103,6 @@ namespace MeoAsstGui
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _useStone, value);
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
if (value)
|
||||
{
|
||||
asstProxy.AsstSetParam("task.action", "UseStone", "doNothing");
|
||||
int count;
|
||||
if (!int.TryParse(StoneNumber, out count))
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StoneConfirm", count.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
asstProxy.AsstSetParam("task.action", "StoneConfirm", "stop");
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StoneConfirm", "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +114,6 @@ namespace MeoAsstGui
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _stoneNumber, value);
|
||||
if (UseStone)
|
||||
{
|
||||
int.TryParse(value, out var count);
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StoneConfirm", count.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,12 +125,6 @@ namespace MeoAsstGui
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _medicineNumber, value);
|
||||
if (UseMedicine)
|
||||
{
|
||||
int.TryParse(value, out var count);
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
asstProxy.AsstSetParam("task.maxTimes", "MedicineConfirm", count.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,16 +136,6 @@ namespace MeoAsstGui
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _hasTimesLimited, value);
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
if (value)
|
||||
{
|
||||
int.TryParse(MaxTimes, out var count);
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StartButton1", count.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StartButton1", int.MaxValue.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,12 +147,6 @@ namespace MeoAsstGui
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _maxTimes, value);
|
||||
if (HasTimesLimited)
|
||||
{
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
int.TryParse(MaxTimes, out var count);
|
||||
asstProxy.AsstSetParam("task.maxTimes", "StartButton1", count.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set port=5555
|
||||
set port=7555
|
||||
|
||||
adb connect 127.0.0.1:%port%
|
||||
adb -s 127.0.0.1:%port% shell screencap /sdcard/screen.png
|
||||
|
||||
Reference in New Issue
Block a user