From 60f0664ef79d470651d2c7fdb8cfbd9fb94ee1cb Mon Sep 17 00:00:00 2001 From: Hydrogina <2221964239@qq.com> Date: Mon, 26 Sep 2022 13:12:04 +0800 Subject: [PATCH] =?UTF-8?q?style,=20docs:=20=E4=BC=98=E5=8C=96=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8D=EF=BC=8C=E8=A1=A5=E5=85=85=E9=9B=86=E6=88=90?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/3.1-集成文档.md | 5 +++-- docs/en-us/3.1-INTEGRATION.md | 5 +++-- src/MeoAssistant/CreditShoppingTask.cpp | 22 +++++++++---------- src/MeoAssistant/CreditShoppingTask.h | 6 ++--- src/MeoAssistant/MallTask.cpp | 6 ++--- src/MeoAsstGui/Helper/AsstProxy.cs | 6 ++--- .../Resources/Localizations/en-us.xaml | 2 +- .../Resources/Localizations/zh-cn.xaml | 2 +- .../Resources/Localizations/zh-tw.xaml | 2 +- .../UserControl/MallSettingsUserControl.xaml | 4 ++-- .../ViewModels/SettingsViewModel.cs | 10 ++++----- .../ViewModels/TaskQueueViewModel.cs | 2 +- 12 files changed, 37 insertions(+), 35 deletions(-) diff --git a/docs/3.1-集成文档.md b/docs/3.1-集成文档.md index d62aa440bd..b25594ded7 100644 --- a/docs/3.1-集成文档.md +++ b/docs/3.1-集成文档.md @@ -150,7 +150,7 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p - `Mall` 领取信用及商店购物。 - 会先有序的按 `buy_first` 购买一遍,再从左到右并避开 `blacklist` 购买第二遍 + 会先有序的按 `buy_first` 购买一遍,再从左到右并避开 `blacklist` 购买第二遍,在信用溢出时则会无视黑名单从左到右购买第三遍直到不再溢出 ```jsonc // 对应的任务参数 @@ -164,7 +164,8 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p "blacklist": [ // 黑名单列表,可选。不支持运行中设置 string, // 商品名,如 "加急许可"、"家具零件" 等 ... - ] + ], + "force_shopping_if_credit_full" // 是否在信用溢出时无视黑名单,默认为 true } ``` diff --git a/docs/en-us/3.1-INTEGRATION.md b/docs/en-us/3.1-INTEGRATION.md index facb26d220..ab5e0d247b 100644 --- a/docs/en-us/3.1-INTEGRATION.md +++ b/docs/en-us/3.1-INTEGRATION.md @@ -138,7 +138,7 @@ Appends a task. - `Mall` Collecting Credits and auto-purchasing - Will buy items in order following `buy_first` list, and buy other items from left to right ignoring items iin `blacklist`. + Will buy items in order following `buy_first` list, buy other items from left to right ignoring items in `blacklist`, and buy other items from left to right ignoring the `blacklist` while credit overflows. ```jsonc // Corresponding task parameters @@ -152,7 +152,8 @@ Appends a task. "blacklist": [ // Blacklist, optional. Editing in run-time is not supported. string, // Item name, e.g. "加急许可" (Expedited Plan), "家具零件" (Furniture Part), etc. ... - ] + ], + "force_shopping_if_credit_full" // Whether to ignore the Blacklist if credit overflows, by default true } ``` diff --git a/src/MeoAssistant/CreditShoppingTask.cpp b/src/MeoAssistant/CreditShoppingTask.cpp index e6d02f551b..5fef6b141e 100644 --- a/src/MeoAssistant/CreditShoppingTask.cpp +++ b/src/MeoAssistant/CreditShoppingTask.cpp @@ -22,13 +22,13 @@ void asst::CreditShoppingTask::set_white_list(std::vector black_lis m_is_white_list = true; } -asst::CreditShoppingTask& asst::CreditShoppingTask::set_save_credit_enabled(bool save_credit_enabled) noexcept +asst::CreditShoppingTask& asst::CreditShoppingTask::set_force_shopping_if_credit_full(bool force_shopping_if_credit_full) noexcept { - m_save_credit_enabled = save_credit_enabled; + m_force_shopping_if_credit_full = force_shopping_if_credit_full; return *this; } -std::string asst::CreditShoppingTask::credit_ocr() +int asst::CreditShoppingTask::credit_ocr() { cv::Mat credit_image = m_ctrler->get_image(); OcrImageAnalyzer credit_analyzer(credit_image); @@ -37,18 +37,18 @@ std::string asst::CreditShoppingTask::credit_ocr() if (!credit_analyzer.analyze()) { Log.trace("ERROR:!credit_analyzer.analyze():"); - return ""; + return -1; } std::string credit = credit_analyzer.get_result().front().text; if (credit.empty() || !ranges::all_of(credit, [](char c) -> bool { return std::isdigit(c); })) { - return ""; + return -1; } Log.trace("credit:", credit); - return credit; + return std::stoi(credit); } bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool credit_ocr_enabled) @@ -122,8 +122,8 @@ bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool cre sleep(rare_delay); if (credit_ocr_enabled) { - std::string credit = credit_ocr(); - if (credit == "" || std::stoi(credit) <= m_max_credit) {//信用值不再溢出,停止购物 + int credit = credit_ocr(); + if (credit <0 || credit <= m_max_credit) {//信用值不再溢出,停止购物 break; } } @@ -139,11 +139,11 @@ bool asst::CreditShoppingTask::_run() return false; } - if (m_save_credit_enabled && !m_is_white_list) {//识别信用值,防止信用值溢出 + if (m_force_shopping_if_credit_full && !m_is_white_list) {//识别信用值,防止信用值溢出 - std::string credit = credit_ocr(); + int credit = credit_ocr(); - if (credit != "" && std::stoi(credit) > m_max_credit) {//信用值溢出 + if (credit >= 0 && credit > m_max_credit) {//信用值溢出 if (!credit_shopping(false, true)) { return false; } diff --git a/src/MeoAssistant/CreditShoppingTask.h b/src/MeoAssistant/CreditShoppingTask.h index 78c157baf4..a9dcf2c8d3 100644 --- a/src/MeoAssistant/CreditShoppingTask.h +++ b/src/MeoAssistant/CreditShoppingTask.h @@ -17,13 +17,13 @@ namespace asst void set_black_list(std::vector black_list); void set_white_list(std::vector white_list); - CreditShoppingTask& set_save_credit_enabled(bool save_credit_enabled) noexcept; + CreditShoppingTask& set_force_shopping_if_credit_full(bool force_shopping_if_credit_full) noexcept; protected: virtual bool _run() override; - bool m_save_credit_enabled = true; // 设置是否防止信用值溢出 + bool m_force_shopping_if_credit_full = true; // 设置是否防止信用值溢出 int m_max_credit = 300; - std::string credit_ocr(); + int credit_ocr(); bool credit_shopping(bool white_list_enabled, bool credit_ocr_enabled); std::vector m_shopping_list; diff --git a/src/MeoAssistant/MallTask.cpp b/src/MeoAssistant/MallTask.cpp index b60216f0d8..6483a9f194 100644 --- a/src/MeoAssistant/MallTask.cpp +++ b/src/MeoAssistant/MallTask.cpp @@ -21,9 +21,9 @@ asst::MallTask::MallTask(const AsstCallback& callback, void* callback_arg) bool asst::MallTask::set_params(const json::value& params) { bool shopping = params.get("shopping", true); - bool save_credit_enabled = params.get("save_credit_enabled", true); - m_shopping_first_task_ptr->set_save_credit_enabled(false); - m_shopping_task_ptr->set_save_credit_enabled(save_credit_enabled); + bool force_shopping_if_credit_full = params.get("force_shopping_if_credit_full", true); + m_shopping_first_task_ptr->set_force_shopping_if_credit_full(false); + m_shopping_task_ptr->set_force_shopping_if_credit_full(force_shopping_if_credit_full); if (shopping) { if (auto buy_first_opt = params.find("buy_first")) { diff --git a/src/MeoAsstGui/Helper/AsstProxy.cs b/src/MeoAsstGui/Helper/AsstProxy.cs index 6b99c699fd..faafdf8b48 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -1230,15 +1230,15 @@ namespace MeoAsstGui /// 是否购物。 /// 优先购买列表。 /// 黑名单列表。 - /// 是否在信用溢出时无视黑名单 + /// 是否在信用溢出时无视黑名单 /// 是否成功。 - public bool AsstAppendMall(bool with_shopping, string[] first_list, string[] blacklist, bool save_credit_enabled) + public bool AsstAppendMall(bool with_shopping, string[] first_list, string[] blacklist, bool force_shopping_if_credit_full) { var task_params = new JObject(); task_params["shopping"] = with_shopping; task_params["buy_first"] = new JArray { first_list }; task_params["blacklist"] = new JArray { blacklist }; - task_params["save_credit_enabled"] = save_credit_enabled; + task_params["force_shopping_if_credit_full"] = force_shopping_if_credit_full; TaskId id = AsstAppendTaskWithEncoding("Mall", task_params); _latestTaskId[TaskType.Mall] = id; return id != 0; diff --git a/src/MeoAsstGui/Resources/Localizations/en-us.xaml b/src/MeoAsstGui/Resources/Localizations/en-us.xaml index 0568ceb19d..5cceb9e34c 100644 --- a/src/MeoAsstGui/Resources/Localizations/en-us.xaml +++ b/src/MeoAsstGui/Resources/Localizations/en-us.xaml @@ -144,7 +144,7 @@ Whitelist (split by semicolon) Blacklist (split by semicolon) Would you like a drink🍷? doctor - Ignore blacklist if credit overflow + Ignore blacklist if credit overflow Drone Usage diff --git a/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml b/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml index 5720561e1e..74665620b0 100644 --- a/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml +++ b/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml @@ -144,7 +144,7 @@ 优先购买 子串即可 分号分隔 黑名单 子串即可 分号分隔 要来一杯美酒吗🍷?博士 - 信用溢出时无视黑名单 + 信用溢出时无视黑名单 无人机用途 diff --git a/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml b/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml index fb8ae925c2..ebdb2a06cd 100644 --- a/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml +++ b/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml @@ -137,7 +137,7 @@ 優先購買 子串即可 分号分隔 黑名單 子串即可 分号分隔 要來一杯美酒嗎🍷?博士 - 信用溢出時無視黑名單 + 信用溢出時無視黑名單 無人機用途 diff --git a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml index ab947e8e74..ff1f9ac382 100644 --- a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml +++ b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml @@ -27,8 +27,8 @@ HorizontalAlignment="Center" VerticalAlignment="Center" Block.TextAlignment="Center" - Content="{DynamicResource SaveCreditEnabled}" - IsChecked="{Binding CreditSaveCreditEnabled}" /> + Content="{DynamicResource ForceShoppingIfCreditFull}" + IsChecked="{Binding CreditForceShoppingIfCreditFull}" /> /// Gets or sets a value indicating whether save credit is enabled. /// - public bool CreditSaveCreditEnabled + public bool CreditForceShoppingIfCreditFull { get { - return bool.Parse(_creditSaveCreditEnabled); + return bool.Parse(_creditForceShoppingIfCreditFull); } set { - SetAndNotify(ref _creditSaveCreditEnabled, value.ToString()); - ViewStatusStorage.Set("Mall.CreditSaveCreditEnabled", value.ToString()); + SetAndNotify(ref _creditForceShoppingIfCreditFull, value.ToString()); + ViewStatusStorage.Set("Mall.CreditForceShoppingIfCreditFull", value.ToString()); } } diff --git a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs index 27d23bdbae..420e5f8db3 100644 --- a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs +++ b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs @@ -904,7 +904,7 @@ namespace MeoAsstGui black_list[i] = black_list[i].Trim(); } - return asstProxy.AsstAppendMall(settings.CreditShopping, buy_first, black_list, settings.CreditSaveCreditEnabled); + return asstProxy.AsstAppendMall(settings.CreditShopping, buy_first, black_list, settings.CreditForceShoppingIfCreditFull); } private bool appendRecruit()