mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
style, docs: 优化参数名,补充集成文档
This commit is contained in:
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -22,13 +22,13 @@ void asst::CreditShoppingTask::set_white_list(std::vector<std::string> 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;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace asst
|
||||
void set_black_list(std::vector<std::string> black_list);
|
||||
void set_white_list(std::vector<std::string> 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<std::string> m_shopping_list;
|
||||
|
||||
@@ -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<json::array>("buy_first")) {
|
||||
|
||||
@@ -1230,15 +1230,15 @@ namespace MeoAsstGui
|
||||
/// <param name="with_shopping">是否购物。</param>
|
||||
/// <param name="first_list">优先购买列表。</param>
|
||||
/// <param name="blacklist">黑名单列表。</param>
|
||||
/// <param name="save_credit_enabled">是否在信用溢出时无视黑名单</param>
|
||||
/// <param name="force_shopping_if_credit_full">是否在信用溢出时无视黑名单</param>
|
||||
/// <returns>是否成功。</returns>
|
||||
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;
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
<system:String x:Key="HighPriority">Whitelist (split by semicolon)</system:String>
|
||||
<system:String x:Key="Blacklist">Blacklist (split by semicolon)</system:String>
|
||||
<system:String x:Key="Drink">Would you like a drink🍷? doctor</system:String>
|
||||
<system:String x:Key="SaveCreditEnabled">Ignore blacklist if credit overflow</system:String>
|
||||
<system:String x:Key="ForceShoppingIfCreditFull">Ignore blacklist if credit overflow</system:String>
|
||||
|
||||
<system:String x:Key="DroneUsage">Drone Usage</system:String>
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@
|
||||
<system:String x:Key="HighPriority">优先购买 子串即可 分号分隔</system:String>
|
||||
<system:String x:Key="Blacklist">黑名单 子串即可 分号分隔</system:String>
|
||||
<system:String x:Key="Drink">要来一杯美酒吗🍷?博士</system:String>
|
||||
<system:String x:Key="SaveCreditEnabled">信用溢出时无视黑名单</system:String>
|
||||
<system:String x:Key="ForceShoppingIfCreditFull">信用溢出时无视黑名单</system:String>
|
||||
|
||||
<system:String x:Key="DroneUsage">无人机用途</system:String>
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
<system:String x:Key="HighPriority">優先購買 子串即可 分号分隔</system:String>
|
||||
<system:String x:Key="Blacklist">黑名單 子串即可 分号分隔</system:String>
|
||||
<system:String x:Key="Drink">要來一杯美酒嗎🍷?博士</system:String>
|
||||
<system:String x:Key="SaveCreditEnabled">信用溢出時無視黑名單</system:String>
|
||||
<system:String x:Key="ForceShoppingIfCreditFull">信用溢出時無視黑名單</system:String>
|
||||
|
||||
<system:String x:Key="DroneUsage">無人機用途</system:String>
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Block.TextAlignment="Center"
|
||||
Content="{DynamicResource SaveCreditEnabled}"
|
||||
IsChecked="{Binding CreditSaveCreditEnabled}" />
|
||||
Content="{DynamicResource ForceShoppingIfCreditFull}"
|
||||
IsChecked="{Binding CreditForceShoppingIfCreditFull}" />
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
@@ -948,22 +948,22 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private string _creditSaveCreditEnabled = ViewStatusStorage.Get("Mall.CreditSaveCreditEnabled", true.ToString());
|
||||
private string _creditForceShoppingIfCreditFull = ViewStatusStorage.Get("Mall.CreditForceShoppingIfCreditFull", true.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether save credit is enabled.
|
||||
/// </summary>
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user