From 88f87da4dfd9d97a0c4b45209a6d2a436e7a7214 Mon Sep 17 00:00:00 2001 From: MistEO Date: Wed, 11 May 2022 23:17:34 +0800 Subject: [PATCH] =?UTF-8?q?feat.=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=904.0=20?= =?UTF-8?q?core=20wpf=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/AbstractImageAnalyzer.cpp | 40 ++++--- src/MeoAssistant/Assistant.cpp | 6 +- src/MeoAsstGui/Helper/AsstProxy.cs | 113 ++++++++++++------ .../ViewModels/TaskQueueViewModel.cs | 8 -- 4 files changed, 102 insertions(+), 65 deletions(-) diff --git a/src/MeoAssistant/AbstractImageAnalyzer.cpp b/src/MeoAssistant/AbstractImageAnalyzer.cpp index e484dbc6db..2ebc71eeb7 100644 --- a/src/MeoAssistant/AbstractImageAnalyzer.cpp +++ b/src/MeoAssistant/AbstractImageAnalyzer.cpp @@ -44,28 +44,30 @@ void asst::AbstractImageAnalyzer::set_roi(const Rect& roi) noexcept asst::Rect asst::AbstractImageAnalyzer::empty_rect_to_full(const Rect& rect, const cv::Mat image) noexcept { + if (image.empty()) { + return rect; + } if (rect.empty()) { return Rect(0, 0, image.cols, image.rows); } - else { - Rect res = rect; - if (image.cols < res.x) { - Log.error("roi is out of range", image.cols, image.rows, res.to_string()); - res.x = image.cols - res.width; - } - if (image.rows < res.y) { - Log.error("roi is out of range", image.cols, image.rows, res.to_string()); - res.y = image.rows - res.height; - } - if (image.cols < res.x + res.width) { - Log.error("roi is out of range", res.to_string()); - res.width = image.cols - res.x; - } - if (image.rows < res.y + res.height) { - Log.error("roi is out of range", res.to_string()); - res.height = image.rows - res.y; - } - return res; + Rect res = rect; + if (image.cols < res.x) { + Log.error("roi is out of range", image.cols, image.rows, res.to_string()); + res.x = image.cols - res.width; } + if (image.rows < res.y) { + Log.error("roi is out of range", image.cols, image.rows, res.to_string()); + res.y = image.rows - res.height; + } + + if (image.cols < res.x + res.width) { + Log.error("roi is out of range", res.to_string()); + res.width = image.cols - res.x; + } + if (image.rows < res.y + res.height) { + Log.error("roi is out of range", res.to_string()); + res.height = image.rows - res.y; + } + return res; } diff --git a/src/MeoAssistant/Assistant.cpp b/src/MeoAssistant/Assistant.cpp index c16757dff0..c8388cde59 100644 --- a/src/MeoAssistant/Assistant.cpp +++ b/src/MeoAssistant/Assistant.cpp @@ -237,7 +237,11 @@ void Assistant::working_proc() bool ret = task_ptr->run(); - m_tasks_list.pop_front(); + lock.lock(); + if (!m_tasks_list.empty()) { + m_tasks_list.pop_front(); + } + lock.unlock(); auto run_msg = AsstMsg::TaskChainCompleted; if (!ret) { diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index 37ff952274..9675974f97 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -11,6 +11,7 @@ using System; using System.Runtime.InteropServices; +using System.Text; using System.Windows; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -145,14 +146,13 @@ namespace MeoAsstGui { string taskChain = details["taskchain"].ToString(); - if (taskChain == "RecruitCalc") + if (taskChain == "Recruit") { if (msg == AsstMsg.TaskChainError) { var recruitModel = _container.Get(); recruitModel.RecruitInfo = "识别错误!"; } - return; } var mainModel = _container.Get(); @@ -347,10 +347,9 @@ namespace MeoAsstGui { string taskChain = details["taskchain"].ToString(); - if (taskChain == "RecruitCalc") + if (taskChain == "Recruit") { procRecruitCalcMsg(details); - return; } string what = details["what"].ToString(); @@ -471,7 +470,7 @@ namespace MeoAsstGui { string id = subTaskDetails["id"].ToString(); settings.PenguinId = id; - AsstSetPenguinId(id); + //AsstSetPenguinId(id); } } break; @@ -557,52 +556,108 @@ namespace MeoAsstGui } } + private bool AsstAppendTaskWithEncoding(string type, JObject task_params = null) + { + task_params = task_params ?? new JObject(); + return AsstAppendTask(_handle, type, JsonConvert.SerializeObject(task_params)) != 0; + } + + public static string Utf16ToUtf8(string utf16String) + { + // Get UTF16 bytes and convert UTF16 bytes to UTF8 bytes + byte[] utf16Bytes = Encoding.Unicode.GetBytes(utf16String); + byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, utf16Bytes); + + // Return UTF8 bytes as ANSI string + return Encoding.Default.GetString(utf8Bytes); + } + public bool AsstAppendFight(string stage, int max_medicine, int max_stone, int max_times) { - return true; + var task_params = new JObject(); + task_params["stage"] = stage; + task_params["medicine"] = max_medicine; + task_params["stone"] = max_stone; + task_params["times"] = max_times; + task_params["report_to_penguin"] = true; + var settings = _container.Get(); + task_params["penguin_id"] = settings.PenguinId; + task_params["server"] = "CN"; + return AsstAppendTaskWithEncoding("Fight", task_params); } public bool AsstAppendAward() { - return false; - //return AsstAppendAward(_handle); + return AsstAppendTaskWithEncoding("Award"); } public bool AsstAppendStartUp() { - AsstAppendTask(_handle, "StartUp", "{}"); - return true; - //return AsstAppendStartUp(_handle); + return AsstAppendTaskWithEncoding("StartUp"); } public bool AsstAppendVisit() { - return false; - //return AsstAppendVisit(_handle); + return AsstAppendTaskWithEncoding("Visit"); } public bool AsstAppendMall(bool with_shopping) { - return false; - //return AsstAppendMall(_handle, with_shopping); + var task_params = new JObject(); + task_params["shopping"] = with_shopping; + task_params["shopping_list"] = new JArray { Utf16ToUtf8("碳"), Utf16ToUtf8("家具") }; + task_params["is_black_list"] = true; + return AsstAppendTaskWithEncoding("Mall", task_params); } public bool AsstAppendRecruit(int max_times, int[] select_level, int required_len, int[] confirm_level, int confirm_len, bool need_refresh, bool use_expedited) { - return false; - //return AsstAppendRecruit(_handle, max_times, select_level, required_len, confirm_level, confirm_len, need_refresh, use_expedited); + var task_params = new JObject(); + task_params["refresh"] = need_refresh; + task_params["select"] = new JArray(select_level); + task_params["confirm"] = new JArray(confirm_level); + task_params["times"] = max_times; + task_params["set_time"] = true; + task_params["expedite"] = use_expedited; + task_params["expedite_times"] = max_times; + return AsstAppendTaskWithEncoding("Recruit", task_params); } public bool AsstAppendInfrast(int work_mode, string[] order, int order_len, string uses_of_drones, double dorm_threshold) { - return false; - //return AsstAppendInfrast(_handle, work_mode, order, order_len, uses_of_drones, dorm_threshold); + var task_params = new JObject(); + //task_params["mode"] = 0; + task_params["facility"] = new JArray(order); + task_params["drones"] = uses_of_drones; + task_params["threshold"] = dorm_threshold; + task_params["replenish"] = true; + return AsstAppendTaskWithEncoding("Infrast", task_params); } public bool AsstAppendRoguelike(int mode) { - return false; - //return AsstAppendRoguelike(_handle, mode); + var task_params = new JObject(); + task_params["mode"] = mode; + task_params["opers"] = new JArray { + new JObject { { "name", Utf16ToUtf8("山") }, { "skill", 2 }, { "skill_usage", 2 } }, + new JObject { { "name", Utf16ToUtf8("棘刺") }, { "skill", 3 }, { "skill_usage", 1 } }, + new JObject { { "name", Utf16ToUtf8("芙蓉") }, { "skill", 1 }, { "skill_usage", 1 } }, + new JObject { { "name", Utf16ToUtf8("梓兰") }, { "skill", 1 }, { "skill_usage", 1 } }, + }; + return AsstAppendTaskWithEncoding("Roguelike", task_params); + } + + public bool AsstStartRecruitCalc(int[] select_level, int required_len, bool set_time) + { + var task_params = new JObject(); + task_params["refresh"] = false; + task_params["select"] = new JArray(select_level); + task_params["confirm"] = new JArray(); + task_params["times"] = 0; + task_params["set_time"] = true; + task_params["expedite"] = false; + task_params["expedite_times"] = 0; + return AsstAppendTaskWithEncoding("Recruit", task_params); } public bool AsstStart() @@ -610,26 +665,10 @@ namespace MeoAsstGui return AsstStart(_handle); } - public bool AsstStartRecruitCalc(int[] select_level, int required_len, bool set_time) - { - return false; - //return AsstStartRecruitCalc(_handle, select_level, required_len, set_time); - } - public bool AsstStop() { return AsstStop(_handle); } - - public void AsstSetPenguinId(string id) - { - //AsstSetPenguinId(_handle, id); - } - - //public void AsstSetParam(string type, string param, string value) - //{ - // AsstSetParam(_ptr, type, param, value); - //} } public enum AsstMsg diff --git a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs index 70a7d9687c..103c7c009c 100644 --- a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs +++ b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs @@ -210,7 +210,6 @@ namespace MeoAsstGui Idle = true; return; } - setPenguinId(); if (Idle) // 一般是点了“停止”按钮了 { @@ -346,13 +345,6 @@ namespace MeoAsstGui return asstProxy.AsstAppendRoguelike(mode); } - private void setPenguinId() - { - var settings = _container.Get(); - var asstProxy = _container.Get(); - asstProxy.AsstSetPenguinId(settings.PenguinId); - } - public void CheckAndShutdown() { if (Shutdown)