From 97266bfa459e42d486599af07edfee5d52b3b42e Mon Sep 17 00:00:00 2001 From: MistEO Date: Tue, 10 Jan 2023 23:25:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=95=E8=88=AA=E8=80=85=E8=AF=95=E7=82=BC?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C"MoveCamera"=20/=20"=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E9=95=9C=E5=A4=B4"=20=E6=96=B0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/tasks.json | 3 +- src/MaaCore/Common/AsstBattleDef.h | 6 ++- .../Config/Miscellaneous/CopilotConfig.cpp | 10 ++++ src/MaaCore/Task/BattleHelper.cpp | 47 +++++++++++++++++++ src/MaaCore/Task/BattleHelper.h | 2 +- .../Task/Miscellaneous/BattleProcessTask.cpp | 19 ++++++-- 6 files changed, 80 insertions(+), 7 deletions(-) diff --git a/resource/tasks.json b/resource/tasks.json index 2807d9a6d9..55bc9003ef 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -5883,7 +5883,8 @@ "algorithm": "OcrDetect", "text": [ "开始行动", - "开始突袭" + "开始突袭", + "开始试炼" ], "cache": false, "roi": [ diff --git a/src/MaaCore/Common/AsstBattleDef.h b/src/MaaCore/Common/AsstBattleDef.h index 5c214162c9..74703ddfb5 100644 --- a/src/MaaCore/Common/AsstBattleDef.h +++ b/src/MaaCore/Common/AsstBattleDef.h @@ -144,6 +144,9 @@ namespace asst::battle Output, // 仅输出,什么都不操作,界面上也不显示 SkillDaemon, // 什么都不做,有技能开技能,直到战斗结束 + /* for TRN */ + MoveCamera, // 引航者试炼,移动镜头 + /* for SSS */ DrawCard, // “调配干员” CheckIfStartOver, // 检查如果没有某干员则退出重开 @@ -166,6 +169,7 @@ namespace asst::battle std::string doc; std::string doc_color; RoleCounts role_counts; + std::pair distance; }; struct BasicInfo @@ -184,7 +188,7 @@ namespace asst::battle OperUsageGroups groups; std::vector actions; }; - } + } // namespace copilot namespace sss // 保全派驻 { diff --git a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp index 775708f523..382e0a7fa6 100644 --- a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp +++ b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp @@ -135,6 +135,12 @@ std::vector asst::CopilotConfig::parse_actions(co { "摆完挂机", ActionType::SkillDaemon }, { "开摆", ActionType::SkillDaemon }, + { "MoveCamera", ActionType::MoveCamera }, + { "movecamera", ActionType::MoveCamera }, + { "MOVECAMERA", ActionType::MoveCamera }, + { "Movecamera", ActionType::MoveCamera }, + { "移动镜头", ActionType::MoveCamera }, + { "DrawCard", ActionType::DrawCard }, { "drawcard", ActionType::DrawCard }, { "DRAWCARD", ActionType::DrawCard }, @@ -183,6 +189,10 @@ std::vector asst::CopilotConfig::parse_actions(co action.role_counts = parse_role_counts(*tool_men); } } + else if (action.type == ActionType::MoveCamera) { + auto dist_arr = action_info.at("distance").as_array(); + action.distance = std::make_pair(dist_arr[0].as_double(), dist_arr[1].as_double()); + } actions_list.emplace_back(std::move(action)); } diff --git a/src/MaaCore/Task/BattleHelper.cpp b/src/MaaCore/Task/BattleHelper.cpp index f86133acbd..432c4cca79 100644 --- a/src/MaaCore/Task/BattleHelper.cpp +++ b/src/MaaCore/Task/BattleHelper.cpp @@ -596,6 +596,53 @@ bool asst::BattleHelper::cancel_oper_selection() return ProcessTask(this_task(), { "BattleCancelSelection" }).run(); } +bool asst::BattleHelper::move_camera(const std::pair& move_loc, bool clear_skills) +{ + LogTraceFunction; + Log.info("move", move_loc.first, move_loc.second); + + auto move_tiles = [&](std::unordered_map& tile_info) { + auto raw_tile_info = tile_info; + for (auto& [loc, tile] : tile_info) { + int view_loc_x = loc.x - static_cast(move_loc.first); + int view_loc_y = loc.y - static_cast(move_loc.second); + auto iter = raw_tile_info.find(Point(view_loc_x, view_loc_y)); + if (iter == raw_tile_info.end()) { + continue; + } + tile.pos.x = iter->second.pos.x; + // y 的移动会导致高台和平地的坐标不对,先不管了 + // tile.pos.y = iter->second.pos.y; + + if (double view_loc_x_dec = std::fabs(loc.x - move_loc.first - view_loc_x); view_loc_x_dec > DoubleDiff) { + auto left_iter = raw_tile_info.find(Point(view_loc_x - 1, view_loc_y)); + if (left_iter != raw_tile_info.end()) { + tile.pos.x -= static_cast((tile.pos.x - left_iter->second.pos.x) * view_loc_x_dec); + } + } + // if (double view_loc_y_dec = std::fabs(loc.y - move_loc.second - view_loc_y); view_loc_y_dec > DoubleDiff) + // { + // auto top_iter = raw_tile_info.find(Point(view_loc_x, view_loc_y - 1)); + // if (top_iter != raw_tile_info.end()) { + // tile.pos.y -= static_cast((tile.pos.y - top_iter->second.pos.y) * view_loc_y_dec); + // } + // } + } + }; + + move_tiles(m_side_tile_info); + move_tiles(m_normal_tile_info); + + if (clear_skills) { + m_kills = 0; + m_total_kills = 0; + } + + save_map(m_inst_helper.ctrler()->get_image()); + + return true; +} + bool asst::BattleHelper::is_name_invalid(const std::string& name) { return BattleData.get_location_type(name) == battle::LocationType::Invalid; diff --git a/src/MaaCore/Task/BattleHelper.h b/src/MaaCore/Task/BattleHelper.h index b65a18c74e..232f5eb04f 100644 --- a/src/MaaCore/Task/BattleHelper.h +++ b/src/MaaCore/Task/BattleHelper.h @@ -63,9 +63,9 @@ namespace asst bool click_retreat(); // 这个是不带识别的,直接点 bool click_skill(bool keep_waiting = true); // 这个是带识别的,转好了才点 bool cancel_oper_selection(); + bool move_camera(const std::pair& move_loc, bool clear_skills = false); bool is_name_invalid(const std::string& name); - std::optional get_oper_rect_on_deployment(const std::string& name) const; std::string m_stage_name; diff --git a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp index 5ba077d465..5bdb97d867 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp @@ -197,6 +197,10 @@ bool asst::BattleProcessTask::do_action(size_t action_index) ret = true; break; + case ActionType::MoveCamera: + ret = move_camera(action.distance, true); + break; + case ActionType::SkillDaemon: ret = wait_until_end(); break; @@ -223,10 +227,17 @@ const std::string& asst::BattleProcessTask::get_name_from_group(const std::strin void asst::BattleProcessTask::notify_action(const battle::copilot::Action& action) { const static std::unordered_map ActionNames = { - { ActionType::Deploy, "Deploy" }, { ActionType::UseSkill, "UseSkill" }, - { ActionType::Retreat, "Retreat" }, { ActionType::SkillDaemon, "SkillDaemon" }, - { ActionType::SwitchSpeed, "SwitchSpeed" }, { ActionType::SkillUsage, "SkillUsage" }, - { ActionType::BulletTime, "BulletTime" }, { ActionType::Output, "Output" }, + { ActionType::Deploy, "Deploy" }, + { ActionType::UseSkill, "UseSkill" }, + { ActionType::Retreat, "Retreat" }, + { ActionType::SkillDaemon, "SkillDaemon" }, + { ActionType::SwitchSpeed, "SwitchSpeed" }, + { ActionType::SkillUsage, "SkillUsage" }, + { ActionType::BulletTime, "BulletTime" }, + { ActionType::Output, "Output" }, + { ActionType::MoveCamera, "MoveCamera" }, + { ActionType::DrawCard, "DrawCard" }, + { ActionType::CheckIfStartOver, "CheckIfStartOver" }, }; json::value info = basic_info_with_what("CopilotAction");