mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 02:10:21 +08:00
add: 增加了任务完成关闭游戏的功能
This commit is contained in:
@@ -44,7 +44,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"BlueStacks": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -61,7 +62,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"MuMuEmulator": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -78,7 +80,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"LDPlayer": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -95,7 +98,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] shell screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"Nox": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -112,7 +116,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"XYAZ": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -129,7 +134,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] shell screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"WSA": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -147,7 +153,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] shell \"screencap -d [DisplayId] | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] shell screencap -d [DisplayId] -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
},
|
||||
"Compatible": {
|
||||
"devices": "[Adb] devices",
|
||||
@@ -164,7 +171,8 @@
|
||||
"screencapRawWithGzip": "[Adb] -s [AdbSerial] exec-out \"screencap | gzip -1\"",
|
||||
"screencapEncode": "[Adb] -s [AdbSerial] exec-out screencap -p",
|
||||
"release": "[Adb] kill-server",
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]"
|
||||
"start": "[Adb] -s [AdbSerial] shell am start -n [Intent]",
|
||||
"stop": "[Adb] -s [AdbSerial] shell \"am force-stop `dumpsys activity activities 2>/dev/null | grep Activities= 2>/dev/null | grep -m 1 -i -o -E [^\\ ]*arknights[^/]*`\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "FightTask.h"
|
||||
#include "StartUpTask.h"
|
||||
#include "CloseDownTask.h"
|
||||
#include "AwardTask.h"
|
||||
#include "VisitTask.h"
|
||||
#include "MallTask.h"
|
||||
@@ -89,6 +90,7 @@ else if (type == TASK::TaskType) { ptr = std::make_shared<TASK>(task_callback, s
|
||||
if (false) {}
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(FightTask)
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(StartUpTask)
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(CloseDownTask)
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(AwardTask)
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(VisitTask)
|
||||
ASST_ASSISTANT_APPEND_TASK_FROM_STRING_IF_BRANCH(MallTask)
|
||||
|
||||
12
src/MeoAssistant/CloseDownTask.cpp
Normal file
12
src/MeoAssistant/CloseDownTask.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "CloseDownTask.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "ProcessTask.h"
|
||||
|
||||
asst::CloseDownTask::CloseDownTask(AsstCallback callback, void* callback_arg)
|
||||
: PackageTask(std::move(callback), callback_arg, TaskType),
|
||||
m_stop_game_task_ptr(std::make_shared<StopGameTaskPlugin>(m_callback, m_callback_arg, TaskType))
|
||||
{
|
||||
m_subtasks.emplace_back(m_stop_game_task_ptr);
|
||||
}
|
||||
19
src/MeoAssistant/CloseDownTask.h
Normal file
19
src/MeoAssistant/CloseDownTask.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "PackageTask.h"
|
||||
#include "StopGameTaskPlugin.h"
|
||||
|
||||
namespace asst
|
||||
{
|
||||
class ProcessTask;
|
||||
|
||||
class CloseDownTask final : public PackageTask
|
||||
{
|
||||
public:
|
||||
CloseDownTask(AsstCallback callback, void* callback_arg);
|
||||
virtual ~CloseDownTask() = default;
|
||||
|
||||
static constexpr const char* TaskType = "CloseDown";
|
||||
private:
|
||||
std::shared_ptr<StopGameTaskPlugin> m_stop_game_task_ptr = nullptr;
|
||||
};
|
||||
}
|
||||
@@ -785,6 +785,16 @@ std::optional<int> asst::Controller::start_game(const std::string& client_type,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<int> asst::Controller::stop_game(bool block)
|
||||
{
|
||||
std::string cur_cmd = m_adb.stop;
|
||||
int id = push_cmd(cur_cmd);
|
||||
if (block) {
|
||||
wait(id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
int asst::Controller::click(const Point& p, bool block)
|
||||
{
|
||||
int x = static_cast<int>(p.x * m_control_scale);
|
||||
@@ -1112,6 +1122,7 @@ bool asst::Controller::connect(const std::string& adb_path, const std::string& a
|
||||
m_adb.screencap_encode = cmd_replace(adb_cfg.screencap_encode);
|
||||
m_adb.release = cmd_replace(adb_cfg.release);
|
||||
m_adb.start = cmd_replace(adb_cfg.start);
|
||||
m_adb.stop = cmd_replace(adb_cfg.stop);
|
||||
|
||||
if (m_support_socket && !m_server_started) {
|
||||
std::string bind_address;
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace asst
|
||||
/* 开启游戏、点击和滑动都是异步执行,返回该任务的id */
|
||||
|
||||
std::optional<int> start_game(const std::string& client_type, bool block = true);
|
||||
std::optional<int> stop_game(bool block = true);
|
||||
|
||||
int click(const Point& p, bool block = true);
|
||||
int click(const Rect& rect, bool block = true);
|
||||
@@ -126,6 +127,7 @@ namespace asst
|
||||
std::string release;
|
||||
|
||||
std::string start;
|
||||
std::string stop;
|
||||
|
||||
/* propertities */
|
||||
enum class ScreencapEndOfLine
|
||||
|
||||
@@ -44,6 +44,7 @@ bool asst::GeneralConfiger::parse(const json::value& json)
|
||||
adb.screencap_encode = cfg_json.at("screencapEncode").as_string();
|
||||
adb.release = cfg_json.at("release").as_string();
|
||||
adb.start = cfg_json.at("start").as_string();
|
||||
adb.stop = cfg_json.at("stop").as_string();
|
||||
//adb.pullscreen = cfg_json.at("pullscreen").as_string();
|
||||
|
||||
m_adb_cfg[name] = std::move(adb);
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace asst
|
||||
std::string screencap_encode;
|
||||
std::string release;
|
||||
std::string start;
|
||||
std::string stop;
|
||||
};
|
||||
|
||||
class GeneralConfiger : public AbstractConfiger
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<ClInclude Include="AsstMsg.h" />
|
||||
<ClInclude Include="AutoRecruitTask.h" />
|
||||
<ClInclude Include="AwardTask.h" />
|
||||
<ClInclude Include="CloseDownTask.h" />
|
||||
<ClInclude Include="CopilotConfiger.h" />
|
||||
<ClInclude Include="BattleFormationTask.h" />
|
||||
<ClInclude Include="BattleImageAnalyzer.h" />
|
||||
@@ -91,6 +92,7 @@
|
||||
<ClInclude Include="StageDropsTaskPlugin.h" />
|
||||
<ClInclude Include="StartGameTaskPlugin.h" />
|
||||
<ClInclude Include="StartUpTask.h" />
|
||||
<ClInclude Include="StopGameTaskPlugin.h" />
|
||||
<ClInclude Include="TaskData.h" />
|
||||
<ClInclude Include="MatchImageAnalyzer.h" />
|
||||
<ClInclude Include="TemplResource.h" />
|
||||
@@ -107,6 +109,7 @@
|
||||
<ClCompile Include="AbstractTaskPlugin.cpp" />
|
||||
<ClCompile Include="AutoRecruitTask.cpp" />
|
||||
<ClCompile Include="AwardTask.cpp" />
|
||||
<ClCompile Include="CloseDownTask.cpp" />
|
||||
<ClCompile Include="CopilotConfiger.cpp" />
|
||||
<ClCompile Include="BattleFormationTask.cpp" />
|
||||
<ClCompile Include="BattleImageAnalyzer.cpp" />
|
||||
@@ -174,6 +177,7 @@
|
||||
<ClCompile Include="StageDropsTaskPlugin.cpp" />
|
||||
<ClCompile Include="StartGameTaskPlugin.cpp" />
|
||||
<ClCompile Include="StartUpTask.cpp" />
|
||||
<ClCompile Include="StopGameTaskPlugin.cpp" />
|
||||
<ClCompile Include="TaskData.cpp" />
|
||||
<ClCompile Include="MatchImageAnalyzer.cpp" />
|
||||
<ClCompile Include="TemplResource.cpp" />
|
||||
|
||||
@@ -339,6 +339,12 @@
|
||||
<ClInclude Include="DepotTask.h">
|
||||
<Filter>头文件\Task</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StopGameTaskPlugin.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CloseDownTask.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Controller.cpp">
|
||||
@@ -581,6 +587,12 @@
|
||||
<ClCompile Include="DepotTask.cpp">
|
||||
<Filter>源文件\Task</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StopGameTaskPlugin.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CloseDownTask.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\resource\config.json">
|
||||
|
||||
10
src/MeoAssistant/StopGameTaskPlugin.cpp
Normal file
10
src/MeoAssistant/StopGameTaskPlugin.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "StopGameTaskPlugin.h"
|
||||
|
||||
#include "Controller.h"
|
||||
|
||||
using namespace asst;
|
||||
|
||||
bool StopGameTaskPlugin::_run()
|
||||
{
|
||||
return m_ctrler->stop_game().has_value();
|
||||
}
|
||||
23
src/MeoAssistant/StopGameTaskPlugin.h
Normal file
23
src/MeoAssistant/StopGameTaskPlugin.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "AbstractTaskPlugin.h"
|
||||
#include "AsstTypes.h"
|
||||
|
||||
namespace asst
|
||||
{
|
||||
|
||||
class StopGameTaskPlugin : public AbstractTaskPlugin
|
||||
{
|
||||
public:
|
||||
using AbstractTaskPlugin::AbstractTaskPlugin;
|
||||
virtual ~StopGameTaskPlugin() noexcept override = default;
|
||||
|
||||
virtual bool verify(AsstMsg msg, const json::value& details) const override
|
||||
{
|
||||
std::ignore = msg; std::ignore = details; return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool _run() override;
|
||||
};
|
||||
}
|
||||
@@ -815,6 +815,7 @@ namespace MeoAsstGui
|
||||
private enum TaskType
|
||||
{
|
||||
StartUp,
|
||||
CloseDown,
|
||||
Fight,
|
||||
Recruit,
|
||||
Infrast,
|
||||
@@ -879,6 +880,13 @@ namespace MeoAsstGui
|
||||
return id != 0;
|
||||
}
|
||||
|
||||
public bool AsstStartCloseDown()
|
||||
{
|
||||
TaskId id = AsstAppendTaskWithEncoding("CloseDown");
|
||||
_latestTaskId[TaskType.CloseDown] = id;
|
||||
return id != 0 && AsstStart();
|
||||
}
|
||||
|
||||
public bool AsstAppendVisit()
|
||||
{
|
||||
TaskId id = AsstAppendTaskWithEncoding("Visit");
|
||||
|
||||
@@ -109,6 +109,7 @@ namespace MeoAsstGui
|
||||
ActionAfterCompletedList = new List<GenericCombData<ActionType>>
|
||||
{
|
||||
new GenericCombData<ActionType>{ Display="无动作",Value=ActionType.DoNothing },
|
||||
new GenericCombData<ActionType>{ Display="退出 明日方舟",Value=ActionType.StopGame },
|
||||
new GenericCombData<ActionType>{ Display="退出 MAA",Value=ActionType.ExitSelf },
|
||||
new GenericCombData<ActionType>{ Display="关闭模拟器",Value=ActionType.ExitEmulator },
|
||||
new GenericCombData<ActionType>{ Display="退出并关闭模拟器",Value=ActionType.ExitEmulatorAndSelf },
|
||||
@@ -349,6 +350,11 @@ namespace MeoAsstGui
|
||||
return;
|
||||
}
|
||||
|
||||
if (ActionAfterCompleted == ActionType.StopGame)
|
||||
{
|
||||
ret &= asstProxy.AsstStartCloseDown();
|
||||
}
|
||||
|
||||
ret &= asstProxy.AsstStart();
|
||||
|
||||
if (ret)
|
||||
@@ -608,6 +614,7 @@ namespace MeoAsstGui
|
||||
public enum ActionType
|
||||
{
|
||||
DoNothing,
|
||||
StopGame,
|
||||
ExitSelf,
|
||||
ExitEmulator,
|
||||
ExitEmulatorAndSelf,
|
||||
|
||||
Reference in New Issue
Block a user