From fd8ebb02c002d405ee9035768d08c11aae4fbc2a Mon Sep 17 00:00:00 2001 From: Hydrogina <2221964239@qq.com> Date: Sun, 25 Sep 2022 19:04:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=89=E9=A1=B9=20?= =?UTF-8?q?=E4=BF=A1=E7=94=A8=E6=BA=A2=E5=87=BA=E6=97=B6=E6=97=A0=E8=A7=86?= =?UTF-8?q?=E9=BB=91=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MeoAssistant/CreditShoppingTask.cpp | 10 ++++++++-- src/MeoAssistant/CreditShoppingTask.h | 5 ++++- src/MeoAssistant/MallTask.cpp | 3 +++ src/MeoAsstGui/Helper/AsstProxy.cs | 4 +++- .../Resources/Localizations/en-us.xaml | 1 + .../Resources/Localizations/zh-cn.xaml | 1 + .../Resources/Localizations/zh-tw.xaml | 1 + .../UserControl/MallSettingsUserControl.xaml | 9 ++++++++- .../ViewModels/SettingsViewModel.cs | 19 +++++++++++++++++++ .../ViewModels/TaskQueueViewModel.cs | 2 +- 10 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/MeoAssistant/CreditShoppingTask.cpp b/src/MeoAssistant/CreditShoppingTask.cpp index 9d16d68139..e6d02f551b 100644 --- a/src/MeoAssistant/CreditShoppingTask.cpp +++ b/src/MeoAssistant/CreditShoppingTask.cpp @@ -22,6 +22,12 @@ 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 +{ + m_save_credit_enabled = save_credit_enabled; + return *this; +} + std::string asst::CreditShoppingTask::credit_ocr() { cv::Mat credit_image = m_ctrler->get_image(); @@ -117,7 +123,7 @@ bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool cre if (credit_ocr_enabled) { std::string credit = credit_ocr(); - if (credit == "" || std::stoi(credit) <= 300) {//信用值不再溢出,停止购物 + if (credit == "" || std::stoi(credit) <= m_max_credit) {//信用值不再溢出,停止购物 break; } } @@ -137,7 +143,7 @@ bool asst::CreditShoppingTask::_run() std::string credit = credit_ocr(); - if (credit != "" && std::stoi(credit) > 300) {//信用值溢出 + if (credit != "" && std::stoi(credit) > m_max_credit) {//信用值溢出 if (!credit_shopping(false, true)) { return false; } diff --git a/src/MeoAssistant/CreditShoppingTask.h b/src/MeoAssistant/CreditShoppingTask.h index 6f37679e65..78c157baf4 100644 --- a/src/MeoAssistant/CreditShoppingTask.h +++ b/src/MeoAssistant/CreditShoppingTask.h @@ -17,11 +17,14 @@ 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; + protected: virtual bool _run() override; bool m_save_credit_enabled = true; // 设置是否防止信用值溢出 + int m_max_credit = 300; std::string credit_ocr(); - bool credit_shopping(bool white_list_enabled, bool credit_ocr_enabled); + bool credit_shopping(bool white_list_enabled, bool credit_ocr_enabled); std::vector m_shopping_list; bool m_is_white_list = false; diff --git a/src/MeoAssistant/MallTask.cpp b/src/MeoAssistant/MallTask.cpp index 36f9549213..b60216f0d8 100644 --- a/src/MeoAssistant/MallTask.cpp +++ b/src/MeoAssistant/MallTask.cpp @@ -21,6 +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); 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 194abfd0d4..6b99c699fd 100644 --- a/src/MeoAsstGui/Helper/AsstProxy.cs +++ b/src/MeoAsstGui/Helper/AsstProxy.cs @@ -1230,13 +1230,15 @@ namespace MeoAsstGui /// 是否购物。 /// 优先购买列表。 /// 黑名单列表。 + /// 是否在信用溢出时无视黑名单 /// 是否成功。 - public bool AsstAppendMall(bool with_shopping, string[] first_list, string[] blacklist) + public bool AsstAppendMall(bool with_shopping, string[] first_list, string[] blacklist, bool save_credit_enabled) { 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; 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 63cc84c774..0568ceb19d 100644 --- a/src/MeoAsstGui/Resources/Localizations/en-us.xaml +++ b/src/MeoAsstGui/Resources/Localizations/en-us.xaml @@ -144,6 +144,7 @@ Whitelist (split by semicolon) Blacklist (split by semicolon) Would you like a drink🍷? doctor + 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 0b500a0e3a..5720561e1e 100644 --- a/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml +++ b/src/MeoAsstGui/Resources/Localizations/zh-cn.xaml @@ -144,6 +144,7 @@ 优先购买 子串即可 分号分隔 黑名单 子串即可 分号分隔 要来一杯美酒吗🍷?博士 + 信用溢出时无视黑名单 无人机用途 diff --git a/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml b/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml index 7e29462cab..fb8ae925c2 100644 --- a/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml +++ b/src/MeoAsstGui/Resources/Localizations/zh-tw.xaml @@ -137,6 +137,7 @@ 優先購買 子串即可 分号分隔 黑名單 子串即可 分号分隔 要來一杯美酒嗎🍷?博士 + 信用溢出時無視黑名單 無人機用途 diff --git a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml index 091e0843d7..ab947e8e74 100644 --- a/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml +++ b/src/MeoAsstGui/UserControl/MallSettingsUserControl.xaml @@ -16,12 +16,19 @@ + + /// Gets or sets a value indicating whether save credit is enabled. + /// + public bool CreditSaveCreditEnabled + { + get + { + return bool.Parse(_creditSaveCreditEnabled); + } + + set + { + SetAndNotify(ref _creditSaveCreditEnabled, value.ToString()); + ViewStatusStorage.Set("Mall.CreditSaveCreditEnabled", value.ToString()); + } + } + /* 定时设置 */ private bool _timer1 = ViewStatusStorage.Get("Timer.Timer1", bool.FalseString) == bool.TrueString; diff --git a/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs b/src/MeoAsstGui/ViewModels/TaskQueueViewModel.cs index 80e1f75e8d..27d23bdbae 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); + return asstProxy.AsstAppendMall(settings.CreditShopping, buy_first, black_list, settings.CreditSaveCreditEnabled); } private bool appendRecruit()