feat.完成掉落材料统计及对应的回调消息

This commit is contained in:
MistEO
2021-10-05 17:26:22 +08:00
parent 06f9a534b1
commit aad4ca08cb
12 changed files with 759 additions and 18 deletions

622
resource/item_index.json Normal file
View File

@@ -0,0 +1,622 @@
{
"2001": {
"name_i18n": {
"ko": "기초작전기록",
"ja": "入門作戦記録",
"en": "Drill Battle Record",
"zh": "基础作战记录"
}
},
"2002": {
"name_i18n": {
"ko": "초급작전기록",
"ja": "初級作戦記録",
"en": "Frontline Battle Record",
"zh": "初级作战记录"
}
},
"2003": {
"name_i18n": {
"ko": "중급작전기록",
"ja": "中級作戦記録",
"en": "Tactical Battle Record",
"zh": "中级作战记录"
}
},
"2004": {
"name_i18n": {
"ko": "고급작전기록",
"ja": "上級作戦記録",
"en": "Strategic Battle Record",
"zh": "高级作战记录"
}
},
"3003": {
"name_i18n": {
"ko": "순금",
"ja": "純金",
"en": "Pure Gold",
"zh": "赤金"
}
},
"30011": {
"name_i18n": {
"ko": "원암",
"ja": "源岩鉱",
"en": "Orirock",
"zh": "源岩"
}
},
"30012": {
"name_i18n": {
"ko": "원암 큐브",
"ja": "初級源岩",
"en": "Orirock Cube",
"zh": "固源岩"
}
},
"30013": {
"name_i18n": {
"ko": "원암 큐브 번들",
"ja": "中級源岩",
"en": "Orirock Cluster",
"zh": "固源岩组"
}
},
"30014": {
"name_i18n": {
"ko": "정제 원암",
"ja": "上級源岩",
"en": "Orriock Concentration",
"zh": "提纯源岩"
}
},
"30061": {
"name_i18n": {
"ko": "파손된 장치",
"ja": "破損装置",
"en": "Damaged Device",
"zh": "破损装置"
}
},
"30062": {
"name_i18n": {
"ko": "장치",
"ja": "初級装置",
"en": "Device",
"zh": "装置"
}
},
"30063": {
"name_i18n": {
"ko": "리뉴얼 장치",
"ja": "中級装置",
"en": "Integrated Device",
"zh": "全新装置"
}
},
"30064": {
"name_i18n": {
"ko": "개량 장치",
"ja": "上級装置",
"en": "Optimized Device",
"zh": "改量装置"
}
},
"30031": {
"name_i18n": {
"ko": "에스테르 원료",
"ja": "エステル原料",
"en": "Ester",
"zh": "酯原料"
}
},
"30032": {
"name_i18n": {
"ko": "폴리에스테르",
"ja": "初級エステル",
"en": "Polyester",
"zh": "聚酸酯"
}
},
"30033": {
"name_i18n": {
"ko": "폴리에스테르 번들",
"ja": "中級エステル",
"en": "Polyester Pack",
"zh": "聚酸酯组"
}
},
"30034": {
"name_i18n": {
"ko": "폴리에스테르 팩",
"ja": "上級エステル",
"en": "Polyester Lump",
"zh": "聚酸酯块"
}
},
"30021": {
"name_i18n": {
"ko": "대체당",
"ja": "ブドウ糖",
"en": "Sugar Substitute",
"zh": "代糖"
}
},
"30022": {
"name_i18n": {
"ko": "포도당",
"ja": "初級糖原",
"en": "Sugar",
"zh": "糖"
}
},
"30023": {
"name_i18n": {
"ko": "포도당 번들",
"ja": "中級糖原",
"en": "Sugar Pack",
"zh": "糖组"
}
},
"30024": {
"name_i18n": {
"ko": "포도당 팩",
"ja": "高級糖原",
"en": "Sugar Lump",
"zh": "糖聚块"
}
},
"30041": {
"name_i18n": {
"ko": "이철 조각",
"ja": "異鉄の欠片",
"en": "Oriron Shard",
"zh": "异铁碎片"
}
},
"30042": {
"name_i18n": {
"ko": "이철",
"ja": "初級異鉄",
"en": "Oriron",
"zh": "异铁"
}
},
"30043": {
"name_i18n": {
"ko": "이철 번들",
"ja": "中級異鉄",
"en": "Oriron Cluster",
"zh": "异铁组"
}
},
"30044": {
"name_i18n": {
"ko": "이철 팩",
"ja": "高級異鉄",
"en": "Oriron Block",
"zh": "异铁块"
}
},
"30051": {
"name_i18n": {
"ko": "디케톤",
"ja": "アケトン試剤",
"en": "Diketon",
"zh": "双酮"
}
},
"30052": {
"name_i18n": {
"ko": "아케톤 응집체",
"ja": "初級アケトン",
"en": "Polyketon",
"zh": "酮凝集"
}
},
"30053": {
"name_i18n": {
"ko": "아케톤 응집체 번들",
"ja": "中級アケトン",
"en": "Aketon",
"zh": "酮凝集组"
}
},
"30054": {
"name_i18n": {
"ko": "아케톤 팩",
"ja": "高級アケトン",
"en": "Keton Colloid",
"zh": "酮阵列"
}
},
"30073": {
"name_i18n": {
"ko": "로식 콜",
"ja": "合成コール",
"en": "Loxic Kohl",
"zh": "扭转醇"
}
},
"30074": {
"name_i18n": {
"ko": "화이트 호스 콜",
"ja": "上級合成コール",
"en": "White Horse Kohl",
"zh": "白马醇"
}
},
"30083": {
"name_i18n": {
"ko": "망간 광석",
"ja": "マンガン",
"en": "Manganese Ore",
"zh": "轻锰矿"
}
},
"30084": {
"name_i18n": {
"ko": "망간 중합체",
"ja": "上級マンガン",
"en": "Manganese Trihydrate",
"zh": "三水锰矿"
}
},
"30093": {
"name_i18n": {
"ko": "연마석",
"ja": "砥石",
"en": "Grindstone",
"zh": "研磨石"
}
},
"30094": {
"name_i18n": {
"ko": "고급연마석",
"ja": "上級砥石",
"en": "Grindstone Pentahydrate",
"zh": "五水研磨石"
}
},
"30103": {
"name_i18n": {
"ko": "RMA70-12",
"ja": "RMA70-12",
"en": "RMA70-12",
"zh": "RMA70-12"
}
},
"30104": {
"name_i18n": {
"ko": "RMA70-24",
"ja": "RMA70-24",
"en": "RMA70-24",
"zh": "RMA70-24"
}
},
"3112": {
"name_i18n": {
"ko": "카본",
"ja": "初級炭素材",
"en": "Carbon Stick",
"zh": "碳"
}
},
"3113": {
"name_i18n": {
"ko": "카본 번들",
"ja": "中級炭素材",
"en": "Carbon Brick",
"zh": "碳素"
}
},
"3114": {
"name_i18n": {
"ko": "카본 팩",
"ja": "上級炭素材",
"en": "Carbon Brick",
"zh": "碳素组"
}
},
"3301": {
"name_i18n": {
"ko": "스킬개론 제1권",
"ja": "アーツ学Ⅰ",
"en": "Skill Summary - 1",
"zh": "技巧概要·卷1"
}
},
"3302": {
"name_i18n": {
"ko": "스킬개론 제2권",
"ja": "アーツ学Ⅱ",
"en": "Skill Summary - 2",
"zh": "技巧概要·卷2"
}
},
"3303": {
"name_i18n": {
"ko": "스킬개론 제3권",
"ja": "アーツ学Ⅲ",
"en": "Skill Summary - 3",
"zh": "技巧概要·卷3"
}
},
"31013": {
"name_i18n": {
"ko": "젤",
"ja": "人工ゲル",
"en": "Coagulating Gel",
"zh": "凝胶"
}
},
"31014": {
"name_i18n": {
"ko": "중합젤",
"ja": "融合ゲル",
"en": "Polymerized Gel",
"zh": "聚合凝胶"
}
},
"31023": {
"name_i18n": {
"ko": "열합금",
"ja": "熾合金",
"en": "Incandescent Alloy",
"zh": "炽合金"
}
},
"31024": {
"name_i18n": {
"ko": "열합금 팩",
"ja": "上級熾合金",
"en": "Incandescent Alloy Block",
"zh": "炽合金块"
}
},
"randomMaterial_1": {
"name_i18n": {
"ko": "로도스 아일랜드 보급 물자",
"ja": "補給物資・ロドス",
"en": "Rhodes Island Supplies",
"zh": "罗德岛物资补给"
}
},
"ap_supply_lt_010": {
"name_i18n": {
"ko": "응급 이성 샘플",
"ja": "試供理性回復剤",
"en": "Emergency Sanity Sampler",
"zh": "应急理智小样"
}
},
"randomMaterial_2": {
"name_i18n": {
"ko": "축제 등불",
"ja": "年関ランタン",
"en": "New Year's Lantern",
"zh": "岁过华灯"
}
},
"4005": {
"name_i18n": {
"ko": "자격증명서",
"ja": "一般資格証",
"en": "Commendation Certificate",
"zh": "资质凭证"
}
},
"30115": {
"name_i18n": {
"ko": "중합제",
"ja": "融合剤",
"en": "Polymerization Preparation",
"zh": "聚合剂"
}
},
"30125": {
"name_i18n": {
"ko": "바이폴라 나노플레이크 칩",
"ja": "ナノフレーク",
"en": "Bipolar Nanoflake",
"zh": "双极纳米片"
}
},
"30135": {
"name_i18n": {
"ko": "D32강",
"ja": "D32鋼",
"en": "D32 Steel",
"zh": "D32钢"
}
},
"randomMaterial_3": {
"name_i18n": {
"ko": "32h 전략 보급",
"ja": "32h戦略補給",
"en": "32-hour Strategic Ration",
"zh": "32h战略配给"
}
},
"randomMaterial_4": {
"name_i18n": {
"ko": "感谢庆典物资补给",
"ja": "感谢庆典物资补给",
"en": "感谢庆典物资补给",
"zh": "感谢庆典物资补给"
}
},
"31033": {
"name_i18n": {
"ko": "晶体元件",
"ja": "晶体元件",
"en": "晶体元件",
"zh": "晶体元件"
}
},
"31034": {
"name_i18n": {
"ko": "晶体电路",
"ja": "晶体电路",
"en": "晶体电路",
"zh": "晶体电路"
}
},
"30145": {
"name_i18n": {
"ko": "晶体电子单元",
"ja": "晶体电子单元",
"en": "晶体电子单元",
"zh": "晶体电子单元"
}
},
"3211": {
"name_i18n": {
"ko": "뱅가드 칩",
"ja": "初級先鋒SoC",
"en": "Vanguard Chip",
"zh": "先锋芯片"
}
},
"3221": {
"name_i18n": {
"ko": "가드 칩",
"ja": "初級前衛SoC",
"en": "Guard Chip",
"zh": "近卫芯片"
}
},
"3241": {
"name_i18n": {
"ko": "스나이퍼 칩",
"ja": "初級狙撃SoC",
"en": "Sniper Chip",
"zh": "狙击芯片"
}
},
"3231": {
"name_i18n": {
"ko": "디펜더 칩",
"ja": "初級重装SoC",
"en": "Defender Chip",
"zh": "重装芯片"
}
},
"3261": {
"name_i18n": {
"ko": "메딕 칩",
"ja": "初級医療SoC",
"en": "Medic Chip",
"zh": "医疗芯片"
}
},
"3271": {
"name_i18n": {
"ko": "서포터 칩",
"ja": "初級補助SoC",
"en": "Supporter Chip",
"zh": "辅助芯片"
}
},
"3251": {
"name_i18n": {
"ko": "캐스터 칩",
"ja": "初級術師SoC",
"en": "Caster Chip",
"zh": "术师芯片"
}
},
"3281": {
"name_i18n": {
"ko": "스페셜리스트 칩",
"ja": "初級特殊SoC",
"en": "Specialist Chip",
"zh": "特种芯片"
}
},
"3212": {
"name_i18n": {
"ko": "뱅가드 칩셋",
"ja": "中級先鋒SoC",
"en": "Vanguard Chip Pack",
"zh": "先锋芯片组"
}
},
"3222": {
"name_i18n": {
"ko": "가드 칩셋",
"ja": "中級前衛SoC",
"en": "Guard Chip Pack",
"zh": "近卫芯片组"
}
},
"3242": {
"name_i18n": {
"ko": "스나이퍼 칩셋",
"ja": "中級狙撃SoC",
"en": "Sniper Chip Pack",
"zh": "狙击芯片组"
}
},
"3232": {
"name_i18n": {
"ko": "디펜더 칩셋",
"ja": "中級重装SoC",
"en": "Defender Chip Pack",
"zh": "重装芯片组"
}
},
"3262": {
"name_i18n": {
"ko": "메딕 칩셋",
"ja": "中級医療SoC",
"en": "Medic Chip Pack",
"zh": "医疗芯片组"
}
},
"3272": {
"name_i18n": {
"ko": "서포터 칩셋",
"ja": "中級補助SoC",
"en": "Supporter Chip Pack",
"zh": "辅助芯片组"
}
},
"3252": {
"name_i18n": {
"ko": "캐스터 칩셋",
"ja": "中級術師SoC",
"en": "Caster Chip Pack",
"zh": "术师芯片组"
}
},
"3282": {
"name_i18n": {
"ko": "스페셜리스트 칩셋",
"ja": "中級特殊SoC",
"en": "Specialist Chip Pack",
"zh": "特种芯片组"
}
},
"31043": {
"name_i18n": {
"zh": "半自然溶剂"
}
},
"31044": {
"name_i18n": {
"zh": "精炼溶剂"
}
},
"31053": {
"name_i18n": {
"zh": "化合切削液"
}
},
"31054": {
"name_i18n": {
"zh": "切削原液"
}
}
}

View File

@@ -106,7 +106,8 @@
"行动结束"
],
"preDelay": 5000,
"action": "printWindow",
"action": "stageDrops",
"action_Doc": "为“行动结束”特化的action包含截图、识别关卡掉落等功能",
"next": [
"ClickCorner"
]

View File

@@ -13,6 +13,7 @@
#include "AsstAux.h"
#include "Task.h"
#include "TaskConfiger.h"
#include "ItemConfiger.h"
#include "RecruitConfiger.h"
#include "InfrastConfiger.h"
#include "UserConfiger.h"
@@ -57,6 +58,11 @@ Assistance::Assistance(AsstCallback callback, void* callback_arg)
callback_error("infrast.json");
throw "resource broken";
}
ret = ItemConfiger::get_instance().load(GetResourceDir() + "item_index.json");
if (!ret) {
callback_error("item_index.json");
throw "resource broken";
}
/* 项目使用的图片模板 */
m_identify_ptr = std::make_shared<Identify>();
@@ -589,6 +595,9 @@ void Assistance::task_callback(AsstMsg msg, const json::value& detail, void* cus
case AsstMsg::OpersIdtfResult:
set_opers_idtf_result(more_detail); // 保存到文件
break;
case AsstMsg::StageDrops:
more_detail = p_this->organize_stage_drop(more_detail);
break;
default:
break;
}
@@ -647,6 +656,7 @@ void Assistance::clear_exec_times()
for (auto&& pair : TaskConfiger::get_instance().m_all_tasks_info) {
pair.second->exec_times = 0;
}
ItemConfiger::get_instance().clear_drop_count();
}
void asst::Assistance::set_opers_idtf_result(const json::value& detail)
@@ -690,4 +700,29 @@ std::optional<std::unordered_map<std::string, OperInfrastInfo>> Assistance::get_
return std::nullopt;
}
return opers_info;
}
json::value asst::Assistance::organize_stage_drop(const json::value& rec)
{
json::value dst = rec;
for (json::value& drop : dst["drops"].as_array()) {
std::string id = drop["itemId"].as_string();
int quantity = drop["quantity"].as_integer();
ItemConfiger::get_instance().m_drop_count[id] += quantity;
const std::string& name = ItemConfiger::get_instance().m_item_name[id];
drop["itemName"] = name;
}
std::vector<json::value> statistics_vec;
for (auto&& [id, count] : ItemConfiger::get_instance().m_drop_count) {
json::value info;
info["itemId"] = id;
info["itemName"] = ItemConfiger::get_instance().m_item_name[id];
info["count"] = count;
statistics_vec.emplace_back(std::move(info));
}
dst["statistics"] = json::array(std::move(statistics_vec));
DebugTrace("organize_stage_drop | ", dst.to_string());
return dst;
}

View File

@@ -73,6 +73,7 @@ namespace asst {
static void set_opers_idtf_result(const json::value& detail); // 保存干员识别结果
static std::optional<std::unordered_map<std::string, OperInfrastInfo>>
get_opers_idtf_result(); // 读取干员识别结果
json::value organize_stage_drop(const json::value& rec); // 整理关卡掉落的材料信息
std::shared_ptr<WinMacro> m_controller_ptr = nullptr;
std::shared_ptr<Identify> m_identify_ptr = nullptr;

View File

@@ -21,7 +21,7 @@ namespace asst {
ClickRand = BasicClick | 4, // 点击随机区域
DoNothing = 0x200, // 什么都不做
Stop = 0x400, // 停止当前Task
PrintWindow = 0x800, // 截图
StageDrops = 0x800, // 截图
BasicSwipe = 0x1000,
SwipeToTheLeft = BasicSwipe | 1, // 往左划一下
SwipeToTheRight = BasicSwipe | 2, // 往右划一下

View File

@@ -33,6 +33,7 @@ namespace asst {
TextDetected = 2000, // 识别到文字
ImageFindResult, // 查找图像的结果
ImageMatched, // 图像匹配成功
StageDrops, // 关卡掉落信息
/* Open Recruit Msg */
RecruitTagsDetected = 3000, // 公招识别到了Tags
RecruitSpecialTag, // 公招识别到了特殊的Tag
@@ -58,6 +59,7 @@ namespace asst {
{AsstMsg::TaskStart, "TaskStart"},
{AsstMsg::ImageFindResult, "ImageFindResult"},
{AsstMsg::ImageMatched, "ImageMatched"},
{AsstMsg::StageDrops, "StageDrops"},
{AsstMsg::TaskMatched, "TaskMatched"},
{AsstMsg::ReachedLimit, "ReachedLimit"},
{AsstMsg::ReadyToSleep, "ReadyToSleep"},

View File

@@ -0,0 +1,17 @@
#include "ItemConfiger.h"
#include <json.h>
void asst::ItemConfiger::clear_drop_count()
{
m_drop_count.clear();
}
bool asst::ItemConfiger::parse(const json::value& json)
{
for (const auto& [id, item_json] : json.as_object()) {
std::string name = item_json.at("name_i18n").at("zh").as_string();
m_item_name.emplace(id, std::move(name));
}
return true;
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "AbstractConfiger.h"
#include <unordered_map>
namespace asst {
class ItemConfiger : public AbstractConfiger
{
public:
virtual ~ItemConfiger() = default;
static ItemConfiger& get_instance() {
static ItemConfiger unique_instance;
return unique_instance;
}
// key材料编号Idvalue材料名zhutf8
std::unordered_map<std::string, std::string> m_item_name;
// key材料编号Idvalue数量
std::unordered_map<std::string, int> m_drop_count;
void clear_drop_count();
protected:
ItemConfiger() = default;
ItemConfiger(const ItemConfiger& rhs) = default;
ItemConfiger(ItemConfiger&& rhs) noexcept = default;
ItemConfiger& operator=(const ItemConfiger& rhs) = default;
ItemConfiger& operator=(ItemConfiger&& rhs) noexcept = default;
virtual bool parse(const json::value& json) override;
};
}

View File

@@ -29,6 +29,7 @@
<ClInclude Include="InfrastOfficeTask.h" />
<ClInclude Include="InfrastPowerTask.h" />
<ClInclude Include="InfrastProductionTask.h" />
<ClInclude Include="ItemConfiger.h" />
<ClInclude Include="Logger.hpp" />
<ClInclude Include="OcrAbstractTask.h" />
<ClInclude Include="OpenRecruitTask.h" />
@@ -57,6 +58,7 @@
<ClCompile Include="InfrastOfficeTask.cpp" />
<ClCompile Include="InfrastPowerTask.cpp" />
<ClCompile Include="InfrastProductionTask.cpp" />
<ClCompile Include="ItemConfiger.cpp" />
<ClCompile Include="OcrAbstractTask.cpp" />
<ClCompile Include="OpenRecruitTask.cpp" />
<ClCompile Include="PenguinUploader.cpp" />
@@ -67,6 +69,12 @@
<ClCompile Include="UserConfiger.cpp" />
<ClCompile Include="WinMacro.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\resource\config.json" />
<None Include="..\..\resource\infrast.json" />
<None Include="..\..\resource\recruit.json" />
<None Include="..\..\resource\tasks.json" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>

View File

@@ -129,6 +129,9 @@
<ClInclude Include="PenguinUploader.h">
<Filter>头文件\utils</Filter>
</ClInclude>
<ClInclude Include="ItemConfiger.h">
<Filter>头文件\Configer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WinMacro.cpp">
@@ -200,5 +203,22 @@
<ClCompile Include="PenguinUploader.cpp">
<Filter>源文件\utils</Filter>
</ClCompile>
<ClCompile Include="ItemConfiger.cpp">
<Filter>源文件\Configer</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\resource\config.json">
<Filter>资源文件</Filter>
</None>
<None Include="..\..\resource\infrast.json">
<Filter>资源文件</Filter>
</None>
<None Include="..\..\resource\recruit.json">
<Filter>资源文件</Filter>
</None>
<None Include="..\..\resource\tasks.json">
<Filter>资源文件</Filter>
</None>
</ItemGroup>
</Project>

View File

@@ -91,21 +91,21 @@ bool ProcessTask::run()
m_callback(AsstMsg::ProcessTaskStopAction, json::object{ {"task_chain", m_task_chain} }, m_callback_arg);
need_stop = true;
break;
case ProcessTaskAction::PrintWindow:
if (Configer::get_instance().m_options.print_window
|| Configer::get_instance().m_options.upload_to_penguin)
{
cv::Mat image = m_controller_ptr->get_image(true);
if (Configer::get_instance().m_options.print_window) {
static const std::string dirname = GetCurrentDir() + "screenshot\\";
save_image(image, dirname);
}
if (Configer::get_instance().m_options.upload_to_penguin) {
std::string res = m_identify_ptr->penguin_recognize(image);
PenguinUploader::upload(res);
}
case ProcessTaskAction::StageDrops:
{
cv::Mat image = m_controller_ptr->get_image(true);
std::string res = m_identify_ptr->penguin_recognize(image);
m_callback(AsstMsg::StageDrops, json::parse(res).value(), m_callback_arg);
if (Configer::get_instance().m_options.print_window) {
static const std::string dirname = GetCurrentDir() + "screenshot\\";
save_image(image, dirname);
}
break;
if (Configer::get_instance().m_options.upload_to_penguin) {
PenguinUploader::upload(res);
}
}
break;
default:
break;
}

View File

@@ -127,8 +127,8 @@ bool asst::TaskConfiger::parse(const json::value& json)
area_json[2].as_integer(),
area_json[3].as_integer());
}
else if (action == "printwindow") {
task_info_ptr->action = ProcessTaskAction::PrintWindow;
else if (action == "stagedrops") {
task_info_ptr->action = ProcessTaskAction::StageDrops;
}
else if (action == "swipetotheleft") {
task_info_ptr->action = ProcessTaskAction::SwipeToTheLeft;