diff --git a/resource/tasks.json b/resource/tasks.json index 38a3e3b198..2e8314e29a 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -3459,6 +3459,7 @@ "template": "BuyIt.png", "action": "ClickSelf", "roi": [800, 500, 250, 150], + "postDelay": 1500, "next": ["CreditShop-Bought", "CreditShop-BuyIt@LoadingText", "CreditShop-NoMoney"] }, "CreditShop-Bought": { @@ -3466,6 +3467,7 @@ "action": "ClickSelf", "roi": [544, 0, 210, 201], "maskRange": [1, 255], + "postDelay": 1500, "next": ["CreditShop-Bought", "Stop"] }, "CreditShop-NoMoney": { diff --git a/src/MaaCore/Task/Miscellaneous/CreditShoppingTask.cpp b/src/MaaCore/Task/Miscellaneous/CreditShoppingTask.cpp index a1549333cf..b82cd198a8 100644 --- a/src/MaaCore/Task/Miscellaneous/CreditShoppingTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/CreditShoppingTask.cpp @@ -23,8 +23,8 @@ void asst::CreditShoppingTask::set_white_list(std::vector black_lis m_is_white_list = true; } -asst::CreditShoppingTask& asst::CreditShoppingTask::set_force_shopping_if_credit_full( - bool force_shopping_if_credit_full) noexcept +asst::CreditShoppingTask& + asst::CreditShoppingTask::set_force_shopping_if_credit_full(bool force_shopping_if_credit_full) noexcept { m_force_shopping_if_credit_full = force_shopping_if_credit_full; return *this; @@ -42,8 +42,7 @@ asst::CreditShoppingTask& asst::CreditShoppingTask::set_info_credit_full(bool in return *this; } -asst::CreditShoppingTask& asst::CreditShoppingTask::set_reserve_max_credit( - bool reserve_max_credit) noexcept +asst::CreditShoppingTask& asst::CreditShoppingTask::set_reserve_max_credit(bool reserve_max_credit) noexcept { m_reserve_max_credit = reserve_max_credit; return *this; @@ -85,13 +84,17 @@ int asst::CreditShoppingTask::discount_ocr(const asst::Rect& commodity) discount_analyzer.set_task_info("CreditShop-DiscountOcr"); discount_analyzer.set_roi(discount_roi); - if (!discount_analyzer.analyze()) return 0; + if (!discount_analyzer.analyze()) { + return 0; + } std::string discount = discount_analyzer.get_result().front().text; Log.trace("discount:", discount); - if (discount.size() != 2) return 0; + if (discount.size() != 2) { + return 0; + } int discount_number = 0; @@ -121,9 +124,11 @@ bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool cre if (need_exit()) { return false; } - if (!m_is_white_list&&m_reserve_max_credit) { + if (!m_is_white_list && m_reserve_max_credit) { int credit = credit_ocr(); - if (credit <= MaxCredit) break; + if (credit <= MaxCredit) { + break; + } } if (!m_is_white_list && m_only_buy_discount) { @@ -142,9 +147,11 @@ bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool cre } } - ctrler()->click(commodity); - - ProcessTask(*this, { "CreditShop-BuyIt" }).run(); + auto clickCount = 0; + do { + ctrler()->click(commodity); + clickCount++ + } while (ProcessTask(*this, { "CreditShop-BuyIt" }).run() || clickCount > 3); if (ProcessTask(*this, { "CreditShop-NoMoney" }).set_task_delay(0).set_retry_times(0).run()) { break; @@ -165,8 +172,11 @@ bool asst::CreditShoppingTask::credit_shopping(bool white_list_enabled, bool cre bool asst::CreditShoppingTask::_run() { - Log.trace("CreditShopping: m_is_white_list:", m_is_white_list, - " m_force_shopping_if_credit_full: ", m_force_shopping_if_credit_full); + Log.trace( + "CreditShopping: m_is_white_list:", + m_is_white_list, + " m_force_shopping_if_credit_full: ", + m_force_shopping_if_credit_full); if (!m_force_shopping_if_credit_full) { return credit_shopping(true, false); @@ -174,7 +184,7 @@ bool asst::CreditShoppingTask::_run() else { int credit = credit_ocr(); // 识别信用值,防止信用值溢出 - if (credit > MaxCredit) { // 信用值溢出 + if (credit > MaxCredit) { // 信用值溢出 return credit_shopping(false, true); } }