feat.新增抄作业的接口支持

This commit is contained in:
MistEO
2022-03-28 23:47:24 +08:00
parent e49c3ee367
commit 969b69ec2e
11 changed files with 94 additions and 4 deletions

View File

@@ -102,3 +102,8 @@
},
}
```
## 举例
[Sample](../resource/battle/test.json)
[GA-EX8 突袭作业](../resource/battle/GA-EX8-raid.json)

View File

@@ -143,6 +143,18 @@ TaskId ASSTAPI AsstAppendTask(AsstHandle handle, const char* type, const char* p
}
```
- `Copilot`
自动抄作业
```jsonc
{
"stage_name": string, // 关卡名,需要与作业 JSON 中的 stage_name 字段相同。不支持运行期设置
"filename": string // 作业 JSON 的文件路径,绝对、相对路径均可。不支持运行期设置
}
```
作业 JSON请参考 [战斗流程协议](战斗流程协议.md)
### `AsstSetTaskParams`
#### 接口原型

View File

View File

@@ -19,6 +19,7 @@
#include "InfrastTask.h"
#include "RecruitTask.h"
#include "RoguelikeTask.h"
#include "CopilotTask.h"
#ifdef ASST_DEBUG
#include "DebugTask.h"
#endif
@@ -107,6 +108,9 @@ asst::Assistant::TaskId asst::Assistant::append_task(const std::string& type, co
else if (type == RoguelikeTask::TaskType) {
ptr = std::make_shared<RoguelikeTask>(task_callback, (void*)this);
}
else if (type == CopilotTask::TaskType) {
ptr = std::make_shared<CopilotTask>(task_callback, (void*)this);
}
#ifdef ASST_DEBUG
else if (type == DebugTask::TaskType) {
ptr = std::make_shared<DebugTask>(task_callback, (void*)this);

View File

@@ -0,0 +1,25 @@
#include "CopilotTask.h"
#include "Resource.h"
#include "BattleProcessTask.h"
asst::CopilotTask::CopilotTask(AsstCallback callback, void* callback_arg)
: PackageTask(callback, callback_arg, TaskType),
m_battle_task_ptr(std::make_shared<BattleProcessTask>(callback, callback_arg, TaskType))
{
m_subtasks.emplace_back(m_battle_task_ptr);
}
bool asst::CopilotTask::set_params(const json::value& params)
{
if (!params.contains("filename") || !params.at("filename").is_string()
|| !params.contains("stage_name") || !params.at("stage_name").is_string()) {
return false;
}
std::string filename = params.at("filename").as_string();
std::string stage_name = params.at("stage_name").as_string();
m_battle_task_ptr->set_stage_name(stage_name);
return Resrc.battle().load(filename);
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "PackageTask.h"
#include <memory>
namespace asst
{
class BattleProcessTask;
// 抄作业任务
class CopilotTask final : public PackageTask
{
public:
CopilotTask(AsstCallback callback, void* callback_arg);
virtual ~CopilotTask() = default;
virtual bool set_params(const json::value& params) override;
static constexpr const char* TaskType = "Copilot";
private:
std::shared_ptr<BattleProcessTask> m_battle_task_ptr = nullptr;
};
}

View File

@@ -28,6 +28,7 @@
<ClInclude Include="BattleConfiger.h" />
<ClInclude Include="BattleImageAnalyzer.h" />
<ClInclude Include="BattleProcessTask.h" />
<ClInclude Include="CopilotTask.h" />
<ClInclude Include="DebugTask.h" />
<ClInclude Include="FightTask.h" />
<ClInclude Include="InfrastTask.h" />
@@ -98,6 +99,7 @@
<ClCompile Include="BattleConfiger.cpp" />
<ClCompile Include="BattleImageAnalyzer.cpp" />
<ClCompile Include="BattleProcessTask.cpp" />
<ClCompile Include="CopilotTask.cpp" />
<ClCompile Include="DebugTask.cpp" />
<ClCompile Include="FightTask.cpp" />
<ClCompile Include="InfrastTask.cpp" />

View File

@@ -309,6 +309,9 @@
<ClInclude Include="BattleProcessTask.h">
<Filter>头文件\Task\Sub</Filter>
</ClInclude>
<ClInclude Include="CopilotTask.h">
<Filter>头文件\Task</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Controller.cpp">
@@ -515,6 +518,9 @@
<ClCompile Include="BattleProcessTask.cpp">
<Filter>源文件\Task\Sub</Filter>
</ClCompile>
<ClCompile Include="CopilotTask.cpp">
<Filter>源文件\Task</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\resource\config.json">

View File

@@ -81,7 +81,7 @@ class Asst:
:return: 任务 ID, 可用于 set_task_params 接口
"""
return Asst.__lib.AsstAppendTask(self.__ptr, type_name.encode('utf-8'), json.dumps(params).encode('utf-8'))
return Asst.__lib.AsstAppendTask(self.__ptr, type_name.encode('utf-8'), json.dumps(params, ensure_ascii=False).encode('utf-8'))
def set_task_params(self, task_id: TaskId, params: JSON) -> bool:
"""
@@ -93,7 +93,7 @@ class Asst:
:return: 是否成功
"""
return Asst.__lib.AsstSetTaskParams(self.__ptr, task_id, json.dumps(params).encode('utf-8'))
return Asst.__lib.AsstSetTaskParams(self.__ptr, task_id, json.dumps(params, ensure_ascii=False).encode('utf-8'))
def start(self) -> bool:
"""

View File

@@ -35,6 +35,7 @@ if __name__ == "__main__":
asst.append_task('StartUp')
asst.append_task('Fight', {
'stage': 'LastBattle',
'report_to_penguin': True,
# 'penguin_id': '1234567'
})
asst.append_task('Recruit', {
@@ -55,6 +56,10 @@ if __name__ == "__main__":
'is_black_list': True
})
asst.append_task('Award')
asst.append_task('Copilot', {
'stage_name': '千层蛋糕',
'filename': './GA-EX8-raid.json'
})
asst.start()

View File

@@ -90,11 +90,18 @@ int main(int argc, char** argv)
//}
//)");
AsstAppendTask(ptr, "Debug", R"({})");
//AsstAppendTask(ptr, "Debug", R"({})");
AsstAppendTask(ptr, "Copilot", R"(
{
"stage_name": "千层蛋糕",
"filename": "./GA-EX8-raid.json"
}
)");
AsstStart(ptr);
getchar();
std::ignore = getchar();
AsstStop(ptr);
AsstDestroy(ptr);