From 92d85f56dfbe508385ef65a0a39dd50df44be524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E4=B8=B6=E6=A2=A6=E4=B8=B6=E4=BB=81?= <74444214+Daydreamer114@users.noreply.github.com> Date: Mon, 30 Jun 2025 01:08:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E8=87=AA=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E6=88=98=E6=B7=BB=E5=8A=A0=20=E6=94=BE=E5=BC=83=E8=A1=8C?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/tasks/tasks.json | 18 ++++++++++++++++++ src/MaaCore/Common/AsstBattleDef.h | 1 + .../Config/Miscellaneous/CopilotConfig.cpp | 7 +++++++ src/MaaCore/Task/BattleHelper.cpp | 13 +++++++++++++ src/MaaCore/Task/BattleHelper.h | 1 + .../Task/Miscellaneous/BattleProcessTask.cpp | 10 ++++++++-- src/MaaWpfGui/Models/Copilot/CopilotModel.cs | 1 + 7 files changed, 49 insertions(+), 2 deletions(-) diff --git a/resource/tasks/tasks.json b/resource/tasks/tasks.json index 72931fd80a..99cf2dc916 100644 --- a/resource/tasks/tasks.json +++ b/resource/tasks/tasks.json @@ -3805,6 +3805,24 @@ "roi": [1165, 20, 65, 65], "maskRange": [100, 255] }, + "BattleGiveUp": { + "algorithm": "JustReturn", + "action": "ClickRect", + "specificRect": [52, 28, 54, 53], + "next": ["BattleGiveUpConfirm"] + }, + "BattleGiveUpConfirm": { + "algorithm": "OcrDetect", + "action": "ClickSelf", + "text": ["放弃", "行动"], + "roi": [813, 538, 294, 74], + "next": ["BattleGiveUpMissionFailed"] + }, + "BattleGiveUpMissionFailed": { + "algorithm": "JustReturn", + "action": "ClickRect", + "specificRect": [0, 0, 1280, 720] + }, "BattleCancelSelection": { "algorithm": "JustReturn", "action": "ClickRect", diff --git a/src/MaaCore/Common/AsstBattleDef.h b/src/MaaCore/Common/AsstBattleDef.h index 9cf878ffcf..b463dd6530 100644 --- a/src/MaaCore/Common/AsstBattleDef.h +++ b/src/MaaCore/Common/AsstBattleDef.h @@ -195,6 +195,7 @@ enum class ActionType BulletTime, // 使用 1/5 的速度 Output, // 仅输出,什么都不操作,界面上也不显示 SkillDaemon, // 什么都不做,有技能开技能,直到战斗结束 + GiveUp, // 放弃行动 /* for TRN */ MoveCamera, // 引航者试炼,移动镜头 diff --git a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp index 74f74e0c92..59cda1717c 100644 --- a/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp +++ b/src/MaaCore/Config/Miscellaneous/CopilotConfig.cpp @@ -169,6 +169,13 @@ std::vector asst::CopilotConfig::parse_actions(co { "摆完挂机", ActionType::SkillDaemon }, { "开摆", ActionType::SkillDaemon }, + { "GiveUp", ActionType::GiveUp }, + { "giveup", ActionType::GiveUp }, + { "GIVEUP", ActionType::GiveUp }, + { "Giveup", ActionType::GiveUp }, + { "放弃", ActionType::GiveUp }, + { "放弃行动", ActionType::GiveUp }, + { "MoveCamera", ActionType::MoveCamera }, { "movecamera", ActionType::MoveCamera }, { "MOVECAMERA", ActionType::MoveCamera }, diff --git a/src/MaaCore/Task/BattleHelper.cpp b/src/MaaCore/Task/BattleHelper.cpp index 12fd74e79e..f2db27d1d2 100644 --- a/src/MaaCore/Task/BattleHelper.cpp +++ b/src/MaaCore/Task/BattleHelper.cpp @@ -956,6 +956,19 @@ bool asst::BattleHelper::move_camera(const std::pair& delta) return update_deployment(true); } +bool asst::BattleHelper::give_up() +{ + LogTraceFunction; + if (!m_in_battle) { + Log.error("Not in battle, cannot give up"); + return false; + } + + ProcessTask(this_task(), { "BattleGiveUp" }).run(); + check_in_battle(); + return true; +} + std::string asst::BattleHelper::analyze_detail_page_oper_name(const cv::Mat& image) { const auto& replace_task = Task.get("CharsNameOcrReplace"); diff --git a/src/MaaCore/Task/BattleHelper.h b/src/MaaCore/Task/BattleHelper.h index 9d552db543..b4b067cdf8 100644 --- a/src/MaaCore/Task/BattleHelper.h +++ b/src/MaaCore/Task/BattleHelper.h @@ -92,6 +92,7 @@ protected: int max_distance = INT_MAX, double radian = 0); bool move_camera(const std::pair& delta); + bool give_up(); std::string analyze_detail_page_oper_name(const cv::Mat& image); std::optional get_oper_rect_on_deployment(const std::string& name) const; diff --git a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp index 130359ae56..dff60d73fb 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleProcessTask.cpp @@ -262,6 +262,11 @@ bool asst::BattleProcessTask::do_action(const battle::copilot::Action& action, s case ActionType::SkillDaemon: ret = wait_until_end(); break; + + case ActionType::GiveUp: + ret = give_up(); + break; + default: ret = do_derived_action(action, index); break; @@ -288,11 +293,12 @@ void asst::BattleProcessTask::notify_action(const battle::copilot::Action& actio { ActionType::Deploy, "Deploy" }, { ActionType::UseSkill, "UseSkill" }, { ActionType::Retreat, "Retreat" }, - { ActionType::SkillDaemon, "SkillDaemon" }, - { ActionType::SwitchSpeed, "SwitchSpeed" }, { ActionType::SkillUsage, "SkillUsage" }, + { ActionType::SwitchSpeed, "SwitchSpeed" }, { ActionType::BulletTime, "BulletTime" }, { ActionType::Output, "Output" }, + { ActionType::SkillDaemon, "SkillDaemon" }, + { ActionType::GiveUp, "GiveUp" }, { ActionType::MoveCamera, "MoveCamera" }, { ActionType::DrawCard, "DrawCard" }, { ActionType::CheckIfStartOver, "CheckIfStartOver" }, diff --git a/src/MaaWpfGui/Models/Copilot/CopilotModel.cs b/src/MaaWpfGui/Models/Copilot/CopilotModel.cs index 7a960bcb11..ece4d06886 100644 --- a/src/MaaWpfGui/Models/Copilot/CopilotModel.cs +++ b/src/MaaWpfGui/Models/Copilot/CopilotModel.cs @@ -157,6 +157,7 @@ public class CopilotModel : CopilotBase /// "Output" - 打印 /// "SkillDaemon" - 摆完挂机 /// "MoveCamera" - 移动镜头 + /// "GiveUp" - 放弃行动 /// /// [JsonProperty("type")]