diff --git a/resource/roguelike/Sami/encounter.json b/resource/roguelike/Sami/encounter.json index d4f9edddce..1106b58aba 100644 --- a/resource/roguelike/Sami/encounter.json +++ b/resource/roguelike/Sami/encounter.json @@ -15,63 +15,86 @@ "name": "随到随取", "option_num": 2, "choose": 2, - "choice_require": [ + "choices": [ { "name": "使用热像仪", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] } ] }, { "name": "定期维护", - "option_num": 3, - "choose": 3, + "option_num": 2, + "choose": 1, "note": "拥有【安玛的爱】时出现第三选项", - "choice_require": [ + "choices": [ { "name": "检查多色测光望远镜的目镜", - "Vision": { - "value": "4", - "type": ">" - } + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "4" + } + ] }, { "name": "不紧不慢地打开一听罐头汤", - "Relic": { - "value": "安玛的爱", - "type": "have" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "安玛的爱" + } + ] } ] }, { "name": "昏黑之室", "option_num": 3, - "choose": 3, - "choice_require": [ - { - "name": "用仪器探测", - "Vision": { - "value": "5", - "type": ">" - } - } - ] + "choose": 3 }, { "name": "疗愈仪式", - "option_num": 3, - "choose": 1, - "choice_require": [ + "option_num": 2, + "choose": 2, + "choices": [ + { + "name": "谨慎尝试", + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "0" + } + ] + }, { "name": "欣然加入", - "Vision": { - "value": "0", - "type": "=" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "0" + } + ] } ] }, @@ -79,47 +102,93 @@ "name": "黑色足迹", "option_num": 2, "choose": 2, - "choice_require": [ + "note": "抗干扰指数为0时出现第三选项,遭遇过【负伤的主树】事件时出现第四选项", + "choices": [ { "name": "逃离", - "LivePoint": { - "value": "3", - "type": ">" - } + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "LivePoint", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "解释情况", + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "0" + } + ] + }, + { + "name": "解释情况", + "option_num": 4, + "choose": 4, + "requirements": [] } - ], - "note": "抗干扰指数为0或遭遇过【负伤的主树】事件时出现第三选项" + ] }, { "name": "不冻河", "option_num": 2, "choose": 2, "note": "拥有【安玛的爱】时出现第三选项", - "choice_require": [ + "choices": [ { "name": "寻找工具", - "Relic": { - "value": "安玛的爱", - "type": "have" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "安玛的爱" + } + ] } ] }, { "name": "野外生存专家", "option_num": 3, - "choose": 1, - "choice_require": [ + "choose": 3, + "choices": [ + { + "name": "意思意思", + "option_num": 3, + "choose": 1, + "requirements": [ + { + "name": "OriginiumIngot", + "type": ">", + "value": "2" + } + ] + }, { "name": "重金酬谢", - "OriginiumIngot": { - "value": "4", - "type": ">" - }, - "Vision": { - "value": "2", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "OriginiumIngot", + "type": ">", + "value": "4" + }, + { + "name": "Vision", + "type": ">", + "value": "2" + } + ] } ] }, @@ -127,13 +196,18 @@ "name": "在地公共信号放大站756号", "option_num": 3, "choose": 1, - "choice_require": [ + "choices": [ { "name": "提供位置,呼叫增援", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] } ] }, @@ -144,9 +218,29 @@ }, { "name": "在地公共移动站N6号", - "option_num": 2, - "choose": 2, - "note": "也可能只有一个" + "option_num": 1, + "choose": 1, + "note": "拥有【安玛的爱】时出现第二选项,遭遇过【特里蒙旅行社特派团】事件且选择【拿走广告】时出现第三选项", + "choices": [ + { + "name": "“敲一敲”都能解决", + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "安玛的爱" + } + ] + }, + { + "name": "寻找工具", + "option_num": 3, + "choose": 3, + "requirements": [] + } + ] }, { "name": "度假胜地", @@ -162,13 +256,18 @@ "name": "不见群山", "option_num": 4, "choose": 3, - "choice_require": [ + "choices": [ { "name": "选择她弃在手边的塔罗牌", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 4, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] } ] }, @@ -176,13 +275,18 @@ "name": "远见所向", "option_num": 4, "choose": 2, - "choice_require": [ + "choices": [ { "name": "我们或许能协作互助", - "Vision": { - "value": "4", - "type": ">" - } + "option_num": 4, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "4" + } + ] } ] }, @@ -210,13 +314,18 @@ "name": "有利可图", "option_num": 3, "choose": 1, - "choice_require": [ + "choices": [ { "name": "分我一点", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] } ] }, @@ -224,17 +333,23 @@ "name": "随行人员", "option_num": 3, "choose": 1, - "choice_require": [ + "choices": [ { "name": "偷听他们聊天", - "LivePoint": { - "value": "3", - "type": ">" - }, - "Vision": { - "value": "1", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "LivePoint", + "type": ">", + "value": "3" + }, + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] } ] }, @@ -242,13 +357,18 @@ "name": "邪恶计划鸭", "option_num": 2, "choose": 2, - "choice_require": [ + "choices": [ { "name": "你在做什么?", - "LivePoint": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "LivePoint", + "type": ">", + "value": "3" + } + ] } ] }, @@ -256,39 +376,68 @@ "name": "百里连营", "option_num": 3, "choose": 2, - "choice_require": [ + "choices": [ { "name": "一边警戒一边前进", - "Vision": { - "value": "1", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] }, { "name": "走近一些", - "LivePoint": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 1, + "requirements": [ + { + "name": "LivePoint", + "type": ">", + "value": "3" + } + ] } ] }, { "name": "请君入戏", "option_num": 3, - "choose": 1 + "choose": 1, + "choices": [ + { + "name": "钱包掉了", + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "OriginiumIngot", + "type": ">", + "value": "12" + } + ] + } + ] }, { "name": "北风女巫", "option_num": 3, "choose": 2, - "choice_require": [ + "choices": [ { "name": "乖乖照做", - "Vision": { - "value": "5", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "5" + } + ] } ] }, @@ -301,13 +450,18 @@ "name": "猜疑链", "option_num": 3, "choose": 1, - "choice_require": [ + "choices": [ { "name": "勘察情况并维持秩序", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] } ] }, @@ -315,13 +469,18 @@ "name": "走过萨米的臂膀", "option_num": 2, "choose": 1, - "choice_require": [ + "choices": [ { "name": "戴上头盔", - "Relic": { - "value": "树痕之盔", - "type": "have" - } + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "树痕之盔" + } + ] } ] }, @@ -335,59 +494,118 @@ "option_num": 2, "choose": 1 }, + { + "name": "重构", + "option_num": 2, + "choose": 1, + "choices": [ + { + "name": "过载使用探测仪器", + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "依靠安玛的遗赠", + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "树痕之盔" + } + ] + } + ] + }, + { + "name": "探索者的一小步", + "option_num": 1, + "choose": 1 + }, { "name": "鲍勃杂货店", "option_num": 3, "choose": 1, - "choice_require": [ + "choices": [ { "name": "选择他脚边的货品", - "Vision": { - "value": "1", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] }, { "name": "选择仓库深处的货品", - "Vision": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "选择仓库深处的货品", + "option_num": 4, + "choose": 4, + "requirements": [ + { + "name": "Relic", + "type": "have", + "value": "四叶草化石" + } + ] } ] }, { "name": "科考站", "option_num": 3, - "choose": 1, - "choice_require": [ - { - "name": "无人机好像有新发现", - "Vision": { - "value": "1", - "type": ">" - } - } - ] + "choose": 1 }, { "name": "北地巫师竞技", "option_num": 2, "choose": 2, - "choice_require": [ + "choices": [ { "name": "接过名册木板,是该选择了!", - "OriginiumIngot": { - "value": "3", - "type": ">" - } + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "OriginiumIngot", + "type": ">", + "value": "3" + } + ] }, { "name": "没来过萨米的人一定没见过!", - "OriginiumIngot": { - "value": "3", - "type": ">" - } + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "OriginiumIngot", + "type": ">", + "value": "3" + } + ] } ] }, @@ -395,41 +613,85 @@ "name": "最好的朋友", "option_num": 2, "choose": 2, - "choice_require": [ + "choices": [ { "name": "仓皇离开", - "Shield": { - "value": "1", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Shield", + "type": ">", + "value": "1" + } + ] }, { "name": "留下", - "LivePointCap": { - "value": "1", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "LivePointCap", + "type": ">", + "value": "1" + } + ] }, { "name": "再喝一口", - "LivePoint": { - "value": "3", - "type": ">" - } + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "LivePoint", + "type": ">", + "value": "3" + } + ] } ] }, { "name": "深渊入口", "option_num": 2, - "choose": 2, - "choice_require": [ + "choose": 1, + "choices": [ + { + "name": "那就试试看", + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] + }, { "name": "再试试看吧", - "Vision": { - "value": "1", - "type": ">" - } + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] + }, + { + "name": "设备坏了,就地点样", + "option_num": 2, + "choose": 1, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "0" + } + ] } ] }, @@ -437,48 +699,114 @@ "name": "低地市集", "option_num": 3, "choose": 3, - "choice_require": [ + "choices": [ { "name": "选择碎草药", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "选择好看的织物", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "选择湿膏药", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "选择好看的木刻", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "选择纯霜露", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "选择琥珀核", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "帮助拿着密文版的萨米人", + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Foldartal", + "type": "not have", + "value": "伤痕 && 空无" + } + ] + }, + { + "name": "循着嚎叫声走去", + "option_num": 4, + "choose": 4, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "5 || 6" + } + ] + }, + { + "name": "循着号角声走去", + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "6" + } + ] } ] }, @@ -486,20 +814,66 @@ "name": "雪与木的笆篱", "option_num": 3, "choose": 3, - "choice_require": [ + "choices": [ { "name": "“活力”", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "“金钱”", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "“树痕”", + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Foldartal", + "type": "not have", + "value": "伤痕 && 空无" + } + ] + }, + { + "name": "“战斗”", + "option_num": 4, + "choose": 4, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "5 || 6" + } + ] + }, + { + "name": "“护卫”", + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "6" + } + ] } ] }, @@ -507,20 +881,66 @@ "name": "安玛塔卢", "option_num": 3, "choose": 3, - "choice_require": [ + "choices": [ { "name": "寻求希望", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] }, { "name": "寻求护佑", - "ChaosLevel": { - "value": "3", - "type": ">" - } + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "ChaosLevel", + "type": ">", + "value": "3" + } + ] + }, + { + "name": "寻求“树痕”的踪迹", + "option_num": 3, + "choose": 2, + "requirements": [ + { + "name": "Foldartal", + "type": "not have", + "value": "伤痕 && 空无" + } + ] + }, + { + "name": "护卫林地", + "option_num": 4, + "choose": 4, + "requirements": [ + { + "name": "Vision", + "type": "=", + "value": "5 || 6" + } + ] + }, + { + "name": "坚守林地", + "option_num": 3, + "choose": 3, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "6" + } + ] } ] }, @@ -533,15 +953,20 @@ "name": "前行的林地", "option_num": 2, "choose": 2, - "choice_require": [ + "choices": [ { "name": "树上就不能走吗?", - "Vision": { - "value": "1", - "type": ">" - } + "option_num": 2, + "choose": 2, + "requirements": [ + { + "name": "Vision", + "type": ">", + "value": "1" + } + ] } ] } ] -} +} \ No newline at end of file diff --git a/resource/tasks.json b/resource/tasks.json index 1625313f60..7a19758736 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -12664,6 +12664,29 @@ "Roguelike@StageEncounterJudgeOption" ] }, + "Roguelike@SpecialValRecognition": { + "algorithm": "OcrDetect", + "action": "DoNothing", + "Doc": "特殊值识别,如抗干扰值,需修改对应主题的roi", + "text": [], + "roi": [ + 615, + 0, + 80, + 45 + ] + }, + "Roguelike@HpRecognition": { + "baseTask": "NumberOcrReplace", + "Doc": "生命值识别,暂时是把整个框进去,估计会把后面的生命值也识别到,后面得改改", + "text": [], + "roi": [ + 190, + 30, + 60, + 30 + ] + }, "Roguelike@StageEncounterJudgeOption": { "algorithm": "JustReturn", "action": "DoNothing", diff --git a/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.cpp b/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.cpp index f4eeac4c6f..6e38bd6174 100644 --- a/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.cpp +++ b/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.cpp @@ -16,7 +16,33 @@ bool asst::RoguelikeStageEncounterConfig::parse(const json::value& json) event.name = event_json.at("name").as_string(); event.option_num = event_json.get("option_num", 0); event.default_choose = event_json.get("choose", 0); + auto choice_require_opt = event_json.find("choice_require"); + if (!choice_require_opt || !choice_require_opt->is_array()) { + continue; + } + for (const auto& requirement_json : choice_require_opt->as_array()) { + ChoiceRequire requirement; + requirement.name = requirement_json.at("name").as_string(); + requirement.choose = requirement_json.get("choose", -1); + if (auto vision_opt = requirement_json.find("Vision")) { + requirement.vision.value = vision_opt->get("value", ""); + requirement.vision.type = parse_comparison_type(vision_opt->get("type", "")); + } + else { + continue; + } + event.choice_require.emplace_back(std::move(requirement)); + } m_events[theme].emplace_back(std::move(event)); } return true; } + +asst::RoguelikeStageEncounterConfig::ComparisonType asst::RoguelikeStageEncounterConfig::parse_comparison_type( + const std::string& type_str) +{ + if (type_str == ">") return ComparisonType::GreaterThan; + if (type_str == "<") return ComparisonType::LessThan; + if (type_str == "=") return ComparisonType::Equal; + return ComparisonType::Unsupported; +} diff --git a/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.h b/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.h index 71c1a5dc5c..b01ae8b8a7 100644 --- a/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.h +++ b/src/MaaCore/Config/Roguelike/RoguelikeStageEncounterConfig.h @@ -8,13 +8,6 @@ namespace asst { - struct RoguelikeEvent - { - std::string name; - int option_num = 0; - int default_choose = 0; - }; - class RoguelikeStageEncounterConfig final : public SingletonHolder, public AbstractConfig { @@ -23,9 +16,39 @@ namespace asst const auto& get_events(const std::string& theme) const noexcept { return m_events.at(theme); } + enum class ComparisonType + { + GreaterThan, + LessThan, + Equal, + None, // 没有配置 + Unsupported, // 配置错误或其他 + }; + + struct Vision + { + std::string value; + ComparisonType type = ComparisonType::None; + }; + struct ChoiceRequire + { + std::string name; + Vision vision; + int choose = -1; + }; + struct RoguelikeEvent + { + std::string name; + int option_num = 0; + int default_choose = 0; + std::vector choice_require; + }; + private: virtual bool parse(const json::value& json) override; + static ComparisonType parse_comparison_type(const std::string& type_str); + std::unordered_map> m_events; }; diff --git a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp index 86f5722b40..1504702179 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.cpp @@ -1,13 +1,11 @@ #include "RoguelikeStageEncounterTaskPlugin.h" #include "Config/Roguelike/RoguelikeStageEncounterConfig.h" -#include "Config/TaskData.h" #include "Controller/Controller.h" #include "Status.h" #include "Task/ProcessTask.h" #include "Utils/ImageIo.hpp" #include "Utils/Logger.hpp" -#include "Vision/OCRer.h" bool asst::RoguelikeStageEncounterTaskPlugin::verify(AsstMsg msg, const json::value& details) const { @@ -39,13 +37,13 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run() LogTraceFunction; auto mode = m_config->get_mode(); - std::vector events = RoguelikeStageEncounter.get_events(m_config->get_theme()); + std::vector events = RoguelikeStageEncounter.get_events(m_config->get_theme()); // 刷源石锭模式和烧水模式 if (mode == RoguelikeMode::Investment || mode == RoguelikeMode::Collectible) { events = RoguelikeStageEncounter.get_events(m_config->get_theme() + "_deposit"); } std::vector event_names; - std::unordered_map event_map; + std::unordered_map event_map; for (const auto& event : events) { event_names.emplace_back(event.name); event_map.emplace(event.name, event); @@ -71,19 +69,123 @@ bool asst::RoguelikeStageEncounterTaskPlugin::_run() } std::string text = resultVec.front().text; - RoguelikeEvent event = event_map.at(text); + Config::RoguelikeEvent event = event_map.at(text); + + int special_val = 0; + // 水月的不好识别,先试试萨米能不能用 + if (m_config->get_theme() == RoguelikeTheme::Sami) { + OCRer analyzer(image); + analyzer.set_task_info(m_config->get_theme() + "@Roguelike@SpecialValRecognition"); + analyzer.set_replace(Task.get("NumberOcrReplace")->replace_map); + analyzer.set_use_char_model(true); + + if (!analyzer.analyze()) { + return false; + } + utils::chars_to_number(analyzer.get_result().front().text, special_val); + } + + // 现在只有抗干扰值判断 + int choose_option = process_task(event, special_val); + Log.info("Event:", event.name, "special_val", special_val, "choose option", choose_option); - Log.info("Event:", event.name, "choose option", event.default_choose); auto info = basic_info_with_what("RoguelikeEvent"); info["details"]["name"] = event.name; info["details"]["default_choose"] = event.default_choose; callback(AsstMsg::SubTaskExtraInfo, info); + + const auto click_option_task_name = [&](int item, int total) { + return m_config->get_theme() + "@Roguelike@OptionChoose" + std::to_string(total) + "-" + std::to_string(item); + }; + for (int j = 0; j < 2; ++j) { - ProcessTask(*this, { m_config->get_theme() + "@Roguelike@OptionChoose" + std::to_string(event.option_num) + "-" + - std::to_string(event.default_choose) }) - .run(); + ProcessTask(*this, { click_option_task_name(choose_option, event.option_num) }).run(); sleep(300); } + // 判断是否点击成功,成功进入对话后左上角的生命值会消失 + image = ctrler()->get_image(); + if (hp(image) <= 0) { + return true; + } + + int max_time = event.option_num; + while (max_time > 0) { + // 从下往上点 + for (int i = max_time; i > 0; --i) { + for (int j = 0; j < 2; ++j) { + ProcessTask(*this, { click_option_task_name(i, max_time) }).run(); + sleep(300); + } + + if (need_exit()) { + return false; + } + + image = ctrler()->get_image(); + if (hp(image) <= 0) { + return true; + } + } + // 没通关结局有些事件会少选项 + --max_time; + } + + return false; +} + +bool asst::RoguelikeStageEncounterTaskPlugin::satisfies_condition(const Config::ChoiceRequire& requirement, + int special_val) +{ + int num = 0; + bool ret = true; + switch (requirement.vision.type) { + case Config::ComparisonType::GreaterThan: + ret &= utils::chars_to_number(requirement.vision.value, num) && special_val > num; + break; + case Config::ComparisonType::LessThan: + ret &= utils::chars_to_number(requirement.vision.value, num) && special_val < num; + break; + case Config::ComparisonType::Equal: + ret &= utils::chars_to_number(requirement.vision.value, num) && special_val == num; + break; + case Config::ComparisonType::None: + break; + default: + Log.warn("unsupported vision type"); + return false; + } + /* + switch (requirement.hp.type) { + // ... + } + */ + if (!ret) { + return false; + } return true; } + +int asst::RoguelikeStageEncounterTaskPlugin::process_task(const Config::RoguelikeEvent& event, const int special_val) +{ + for (const auto& requirement : event.choice_require) { + if (requirement.choose == -1) continue; + if (satisfies_condition(requirement, special_val)) { + return requirement.choose; + } + } + return event.default_choose; +} + +int asst::RoguelikeStageEncounterTaskPlugin::hp(const cv::Mat& image) +{ + int hp_val; + asst::OCRer analyzer(image); + analyzer.set_task_info("Roguelike@HpRecognition"); + + auto res_vec_opt = analyzer.analyze(); + if (!res_vec_opt) { + return -1; + } + return utils::chars_to_number(res_vec_opt->front().text, hp_val) ? hp_val : 0; +} diff --git a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.h b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.h index 7793e51bf3..89f9bbb982 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.h +++ b/src/MaaCore/Task/Roguelike/RoguelikeStageEncounterTaskPlugin.h @@ -1,5 +1,8 @@ #pragma once #include "AbstractRoguelikeTaskPlugin.h" +#include "Config/Roguelike/RoguelikeStageEncounterConfig.h" +#include "Config/TaskData.h" +#include "Vision/OCRer.h" namespace asst { @@ -7,6 +10,7 @@ namespace asst { public: using AbstractRoguelikeTaskPlugin::AbstractRoguelikeTaskPlugin; + using Config = RoguelikeStageEncounterConfig; virtual ~RoguelikeStageEncounterTaskPlugin() override = default; public: @@ -14,5 +18,8 @@ namespace asst protected: virtual bool _run() override; + static bool satisfies_condition(const Config::ChoiceRequire& requirement, int special_val); + static int process_task(const Config::RoguelikeEvent& event, const int special_val); + static int hp(const cv::Mat& image); }; }