mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat.新增支持信用商店优先购买选项
This commit is contained in:
11
docs/集成文档.md
11
docs/集成文档.md
@@ -97,17 +97,20 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p
|
||||
不支持设置参数
|
||||
|
||||
- `Mall`
|
||||
领取信用及商店购物
|
||||
领取信用及商店购物。
|
||||
会先有序的按 `buy_first` 购买一遍,再从左到右并避开 `blacklist` 购买第二遍
|
||||
|
||||
```jsonc
|
||||
// 对应的任务参数
|
||||
{
|
||||
"shopping": bool, // 是否购物,可选,默认 false。不支持运行中设置
|
||||
"shopping_list": [ // 购物列表,当 shopping 为 true 时必选。不支持运行中设置
|
||||
"buy_first": [ // 优先购买列表,可选。不支持运行中设置
|
||||
string, // 商品名,如 "招聘许可"、"龙门币" 等
|
||||
],
|
||||
"blacklist": [ // 黑名单列表,可选。不支持运行中设置
|
||||
string, // 商品名,如 "加急许可"、"家具零件" 等
|
||||
...
|
||||
],
|
||||
"is_black_list": bool // 购物列表是否是黑名单模式,可选,默认 false。不支持运行中设置
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -2533,12 +2533,14 @@
|
||||
110
|
||||
]
|
||||
},
|
||||
"CreditShop-NotToBuy": {
|
||||
"CreditShop-ProductName": {
|
||||
"algorithm": "OcrDetect",
|
||||
"Doc": "这里的text,是子串搜索,即商品名中只要含有任一text,就不买",
|
||||
"text": [
|
||||
"碳",
|
||||
"家具"
|
||||
"text": [],
|
||||
"ocrReplace": [
|
||||
[
|
||||
"龙门.+",
|
||||
"龙门币"
|
||||
]
|
||||
],
|
||||
"roi": [
|
||||
0,
|
||||
|
||||
@@ -59,16 +59,17 @@ bool asst::CreditShopImageAnalyzer::commoditys_analyze()
|
||||
|
||||
bool asst::CreditShopImageAnalyzer::whether_to_buy_analyze()
|
||||
{
|
||||
const auto not_to_buy_task_ptr = std::dynamic_pointer_cast<OcrTaskInfo>(
|
||||
Task.get("CreditShop-NotToBuy"));
|
||||
const auto product_name_task_ptr = std::dynamic_pointer_cast<OcrTaskInfo>(
|
||||
Task.get("CreditShop-ProductName"));
|
||||
|
||||
for (const Rect& commodity : m_commoditys) {
|
||||
// 商品名的区域
|
||||
Rect name_roi = not_to_buy_task_ptr->roi;
|
||||
Rect name_roi = product_name_task_ptr->roi;
|
||||
name_roi.x += commodity.x;
|
||||
name_roi.y += commodity.y;
|
||||
|
||||
OcrImageAnalyzer ocr_analyzer(m_image, name_roi);
|
||||
ocr_analyzer.set_replace(product_name_task_ptr->replace_map);
|
||||
ocr_analyzer.set_required(m_shopping_list);
|
||||
if (ocr_analyzer.analyze()) {
|
||||
// 黑名单模式,有识别结果说明这个商品不买,直接跳过
|
||||
@@ -84,8 +85,17 @@ bool asst::CreditShopImageAnalyzer::whether_to_buy_analyze()
|
||||
#ifdef ASST_DEBUG
|
||||
cv::rectangle(m_image_draw, utils::make_rect<cv::Rect>(commodity), cv::Scalar(0, 0, 255), 2);
|
||||
#endif
|
||||
m_need_to_buy.emplace_back(commodity);
|
||||
m_need_to_buy.emplace_back(commodity, ocr_analyzer.get_result().empty() ? std::string() : ocr_analyzer.get_result().front().text);
|
||||
}
|
||||
|
||||
if (m_is_white_list) {
|
||||
std::sort(m_need_to_buy.begin(), m_need_to_buy.end(), [&](
|
||||
const auto& lhs, const auto& rhs) -> bool {
|
||||
return std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), lhs.second)
|
||||
< std::find(m_shopping_list.cbegin(), m_shopping_list.cend(), rhs.second);
|
||||
});
|
||||
}
|
||||
|
||||
return !m_need_to_buy.empty();
|
||||
}
|
||||
|
||||
@@ -95,7 +105,7 @@ bool asst::CreditShopImageAnalyzer::sold_out_analyze()
|
||||
MatchImageAnalyzer sold_out_analyzer(m_image);
|
||||
sold_out_analyzer.set_task_info("CreditShop-SoldOut");
|
||||
|
||||
for (const Rect& commodity : m_need_to_buy) {
|
||||
for (const auto& [commodity, _] : m_need_to_buy) {
|
||||
sold_out_analyzer.set_roi(commodity);
|
||||
if (sold_out_analyzer.analyze()) {
|
||||
#ifdef ASST_DEBUG
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace asst
|
||||
bool sold_out_analyze();
|
||||
|
||||
std::vector<Rect> m_commoditys;
|
||||
std::vector<Rect> m_need_to_buy;
|
||||
std::vector<std::pair<Rect, std::string>> m_need_to_buy;
|
||||
std::vector<Rect> m_result;
|
||||
|
||||
std::vector<std::string> m_shopping_list;
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
asst::MallTask::MallTask(AsstCallback callback, void* callback_arg)
|
||||
: PackageTask(callback, callback_arg, TaskType),
|
||||
m_mall_task_ptr(std::make_shared<ProcessTask>(callback, callback_arg, TaskType)),
|
||||
m_shopping_first_task_ptr(std::make_shared<CreditShoppingTask>(callback, callback_arg, TaskType)),
|
||||
m_shopping_task_ptr(std::make_shared<CreditShoppingTask>(callback, callback_arg, TaskType))
|
||||
{
|
||||
m_mall_task_ptr->set_tasks({ "MallBegin" });
|
||||
m_shopping_task_ptr->set_enable(false);
|
||||
m_shopping_first_task_ptr->set_enable(false).set_retry_times(1);
|
||||
m_shopping_task_ptr->set_enable(false).set_retry_times(1);
|
||||
|
||||
m_subtasks.emplace_back(m_mall_task_ptr);
|
||||
m_subtasks.emplace_back(m_shopping_first_task_ptr);
|
||||
m_subtasks.emplace_back(m_shopping_task_ptr);
|
||||
}
|
||||
|
||||
@@ -20,24 +23,35 @@ bool asst::MallTask::set_params(const json::value& params)
|
||||
bool shopping = params.get("shopping", true);
|
||||
|
||||
if (shopping) {
|
||||
if (params.contains("shopping_list") && params.at("shopping_list").is_array()) {
|
||||
std::vector<std::string> shopping_list;
|
||||
for (auto& name : params.at("shopping_list").as_array()) {
|
||||
shopping_list.emplace_back(name.as_string());
|
||||
if (params.contains("buy_first") && params.at("buy_first").is_array()) {
|
||||
std::vector<std::string> buy_first;
|
||||
for (auto& name : params.at("buy_first").as_array()) {
|
||||
buy_first.emplace_back(name.as_string());
|
||||
}
|
||||
if (params.get("is_black_list", false) == true) {
|
||||
m_shopping_task_ptr->set_black_list(std::move(shopping_list));
|
||||
if (!buy_first.empty()) {
|
||||
m_shopping_first_task_ptr->set_white_list(std::move(buy_first));
|
||||
m_shopping_first_task_ptr->set_enable(true);
|
||||
}
|
||||
else {
|
||||
m_shopping_task_ptr->set_white_list(std::move(shopping_list));
|
||||
m_shopping_first_task_ptr->set_enable(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
m_shopping_first_task_ptr->set_enable(false);
|
||||
}
|
||||
|
||||
if (params.contains("blacklist") && params.at("blacklist").is_array()) {
|
||||
std::vector<std::string> shopping_list;
|
||||
for (auto& name : params.at("blacklist").as_array()) {
|
||||
shopping_list.emplace_back(name.as_string());
|
||||
}
|
||||
m_shopping_task_ptr->set_black_list(std::move(shopping_list));
|
||||
}
|
||||
|
||||
m_shopping_task_ptr->set_enable(true);
|
||||
}
|
||||
else {
|
||||
m_shopping_first_task_ptr->set_enable(false);
|
||||
m_shopping_task_ptr->set_enable(false);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace asst
|
||||
static constexpr const char* TaskType = "Mall";
|
||||
private:
|
||||
std::shared_ptr<ProcessTask> m_mall_task_ptr = nullptr;
|
||||
std::shared_ptr<CreditShoppingTask> m_shopping_first_task_ptr = nullptr;
|
||||
std::shared_ptr<CreditShoppingTask> m_shopping_task_ptr = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -601,12 +601,12 @@ namespace MeoAsstGui
|
||||
return AsstAppendTaskWithEncoding("Visit");
|
||||
}
|
||||
|
||||
public bool AsstAppendMall(bool with_shopping, bool blackMode, string[] shoppingList)
|
||||
public bool AsstAppendMall(bool with_shopping, string[] firstlist, string[] blacklist)
|
||||
{
|
||||
var task_params = new JObject();
|
||||
task_params["shopping"] = with_shopping;
|
||||
task_params["shopping_list"] = new JArray { shoppingList };
|
||||
task_params["is_black_list"] = blackMode;
|
||||
task_params["buy_first"] = new JArray { firstlist };
|
||||
task_params["blacklist"] = new JArray { blacklist };
|
||||
return AsstAppendTaskWithEncoding("Mall", task_params);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
<CheckBox Grid.Row="0" IsChecked="{Binding CreditShopping}" Block.TextAlignment="Center" Margin="10"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Content=" 信用购物 " />
|
||||
<CheckBox Grid.Row="1" IsEnabled="{Binding CreditShopping}" IsChecked="{Binding CreditBlackMode}" Block.TextAlignment="Center" Margin="10"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Content="黑名单模式" />
|
||||
<StackPanel Grid.Row="1" IsEnabled="{Binding CreditShopping}" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center"
|
||||
Text="优先购买
子串即可,空格分隔" Margin="10" />
|
||||
<TextBox Text="{Binding CreditFirstList}" Margin="10" Width="250" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" IsEnabled="{Binding CreditShopping}" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center"
|
||||
Text="黑名单
子串即可,空格分隔" Margin="10" />
|
||||
<TextBox Text="{Binding CreditShoppingList}" Margin="10" Width="250" />
|
||||
<TextBox Text="{Binding CreditBlackList}" Margin="10" Width="250" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -339,37 +339,27 @@ namespace MeoAsstGui
|
||||
}
|
||||
}
|
||||
|
||||
private bool _creditBlackMode = Convert.ToBoolean(ViewStatusStorage.Get("Mall.CreditBlackMode", bool.TrueString));
|
||||
private string _creditFirstList = ViewStatusStorage.Get("Mall.CreditFirstList", "招聘许可 龙门币");
|
||||
|
||||
public bool CreditBlackMode
|
||||
public string CreditFirstList
|
||||
{
|
||||
get { return _creditBlackMode; }
|
||||
get { return _creditFirstList; }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _creditBlackMode, value);
|
||||
ViewStatusStorage.Set("Mall.CreditBlackMode", value.ToString());
|
||||
SetAndNotify(ref _creditFirstList, value);
|
||||
ViewStatusStorage.Set("Mall.CreditFirstList", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static string Utf16ToUtf8(string utf16String)
|
||||
private string _creditBlackList = ViewStatusStorage.Get("Mall.CreditBlackList", "碳 家具");
|
||||
|
||||
public string CreditBlackList
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
private string _creditShoppingList = ViewStatusStorage.Get("Mall.CreditShoppingList", "碳 家具");
|
||||
|
||||
public string CreditShoppingList
|
||||
{
|
||||
get { return _creditShoppingList; }
|
||||
get { return _creditBlackList; }
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _creditShoppingList, value);
|
||||
ViewStatusStorage.Set("Mall.CreditShoppingList", value.ToString());
|
||||
SetAndNotify(ref _creditBlackList, value);
|
||||
ViewStatusStorage.Set("Mall.CreditBlackList", value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,8 +306,9 @@ namespace MeoAsstGui
|
||||
{
|
||||
var settings = _container.Get<SettingsViewModel>();
|
||||
var asstProxy = _container.Get<AsstProxy>();
|
||||
var shopping_list = settings.CreditShoppingList.Split(' ');
|
||||
return asstProxy.AsstAppendMall(settings.CreditShopping, settings.CreditBlackMode, shopping_list);
|
||||
var buy_first = settings.CreditFirstList.Split(' ');
|
||||
var black_list = settings.CreditBlackList.Split(' ');
|
||||
return asstProxy.AsstAppendMall(settings.CreditShopping, buy_first, black_list);
|
||||
}
|
||||
|
||||
private bool appendRecruit()
|
||||
|
||||
@@ -52,8 +52,8 @@ if __name__ == "__main__":
|
||||
asst.append_task('Visit')
|
||||
asst.append_task('Mall', {
|
||||
'shopping': True,
|
||||
'shopping_list': ['家具', '碳'],
|
||||
'is_black_list': True
|
||||
'buy_first': ['招聘许可', '龙门币'],
|
||||
'blacklist': ['家具', '碳'],
|
||||
})
|
||||
asst.append_task('Award')
|
||||
# asst.append_task('Copilot', {
|
||||
|
||||
@@ -48,8 +48,8 @@ def job():
|
||||
asst.append_task('Visit')
|
||||
asst.append_task('Mall', {
|
||||
'shopping': True,
|
||||
'shopping_list': ['家具', '碳'],
|
||||
'is_black_list': True
|
||||
'buy_first': ['招聘许可', '龙门币'],
|
||||
'blacklist': ['家具', '碳'],
|
||||
})
|
||||
asst.append_task('Award')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user