From af8e2ec3568cf21ac3a885c399b7ea246064f5e2 Mon Sep 17 00:00:00 2001 From: Dongw Date: Sun, 8 Oct 2023 12:50:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20`Combat`=20Custom?= =?UTF-8?q?=20Action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resource/image/Combat/StopCombat.png | Bin 0 -> 915 bytes source/cli/CMakeLists.txt | 2 +- source/cli/Combat.cpp | 289 ++++++++++++++++++++ source/cli/Combat.h | 59 ++++ source/cli/RegisterCustomAciton.h | 9 + source/cli/RegisterCustomAction.cpp | 72 +++++ source/cli/main.cpp | 2 + source/cli/main.h | 2 + 8 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 assets/resource/image/Combat/StopCombat.png create mode 100644 source/cli/Combat.cpp create mode 100644 source/cli/Combat.h create mode 100644 source/cli/RegisterCustomAciton.h create mode 100644 source/cli/RegisterCustomAction.cpp diff --git a/assets/resource/image/Combat/StopCombat.png b/assets/resource/image/Combat/StopCombat.png new file mode 100644 index 0000000000000000000000000000000000000000..cc823d99797b73d890acc032aba0b331b3500cc4 GIT binary patch literal 915 zcmeAS@N?(olHy`uVBq!ia0vp^DnP8k!2~2F7o6Y1z`z{k>Eaj?!MXR~*}S_h5^N8? zThDWK;>+cDb)=|Pw2k|LyHkTrgG@_9kXWo`(na5gN&?(LoV6zvuH z3%Vl{VvIW+ZcSG6s`;eIy3^`X&Fx>686Oj}7x@`*McLe#wL-Y3>4sEKD|YO`*Z!z)QnES9vwi=L*t6;TW#w$_y3MYtr)9;(M#n08bgXTB z5@!0p?E8Z!QwsGsHhewy<=55j)!HowFB;ZwuHNwdbIryB|C<=*$4CEvuvSy$$Tf#g z@6zwS=dae;xkd0z-O8_S4UM% zzH68)DfsUF(Fp?4%$}1>KZLk~C4QN_f3Whjgiunpg6Af-d8;^-*BWHR&VMFrQ!44~ zl*6mydF?>3XyOu4wzaP>?`dAHmke^U%1Nn;RZ2Zu4lO9HomKwfN-7WMM$-u@k<9*~ zEfd2ewyg92%r|dWkD}r>wn-}44_0;=T;giJ_BHd~!QknJAm>d=;k5}Bbc;&7u*>eO zb;T>Aww4=G9+TEIF4sEbq0JL@eR(Cjf9$a#=h&0p(Y(gf1QWLjgZ*|dr~C{s5`I^M zJ)N{|xBb628=oBg`rui3R6dKuj=x8zO22zwFCI};8GN?P37i^^@9y9K@889fnvd_a zeE2u}^6PN@b?XG!+>igc%g_E)zg>NKPw`~VyqM_!AKpUJ!;>FxmRI}doqM+SwZ4z~ z`@Q?V1zPR>;^fe>e8$J?_TAB&f6lFL?|+s)F)aMdm$}!k&5H)5yMqxp@aALc4h&pC i$<4=XH5i)yGYB1N{PZLHoeeOvF?hQAxvX unix(1146, 1228); + std::uniform_int_distribution uniy(606, 670); + int32_t x = unix(rng); + int32_t y = uniy(rng); + + MaaSyncContextTouchDown(sync_context, 0, x, y, 0); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + MaaSyncContextTouchUp(sync_context, 0); + return true; +} + +MaaBool combat_basic_ATK_charge(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, + MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatBasicATKCharge", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_evade(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatEvade", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_ultimate(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatUltimate", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_ultimate_charge_base(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, + MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + std::random_device rd; + std::mt19937 rng(rd()); + std::uniform_int_distribution unix(1145, 1227); + std::uniform_int_distribution uniy(424, 498); + int32_t x = unix(rng); + int32_t y = uniy(rng); + + MaaSyncContextTouchDown(sync_context, 0, x, y, 0); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + MaaSyncContextTouchUp(sync_context, 0); + return true; +} + +MaaBool combat_ultimate_charge(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatUltimateCharge", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_weapon_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatWeaponSkill", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_ELF_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatELFSkill", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_extra_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatExtraSkill", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_QTE1(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatQTE1", MaaTaskParam_Empty); + return true; +} + +MaaBool combat_QTE2(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg) +{ + task_name; // silence unreferenced warning + custom_action_param; // silence unreferenced warning + cur_box; // silence unreferenced warning + cur_rec_detail; // silence unreferenced warning + arg; // silence unreferenced warning + + MaaSyncContextRunTask(sync_context, "CombatQTE2", MaaTaskParam_Empty); + return true; +} \ No newline at end of file diff --git a/source/cli/Combat.h b/source/cli/Combat.h new file mode 100644 index 0000000..2a3ddda --- /dev/null +++ b/source/cli/Combat.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include + +#include "MaaFramework/Task/MaaSyncContext.h" + +MaaBool combat_forward(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_backward(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_left(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_right(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_left_forward(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_right_forward(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_left_backward(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_right_backward(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); + +MaaBool combat_basic_ATK(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_basic_ATK_charge_base(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, + MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_basic_ATK_charge(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_evade(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_ultimate(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_ultimate_charge_base(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, + MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_ultimate_charge(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_weapon_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_ELF_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_extra_skill(MaaSyncContextHandle sync_context, MaaStringView task_name, + MaaStringView custom_action_param, MaaRectHandle cur_box, MaaStringView cur_rec_detail, + MaaTransparentArg arg); +MaaBool combat_QTE1(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); +MaaBool combat_QTE2(MaaSyncContextHandle sync_context, MaaStringView task_name, MaaStringView custom_action_param, + MaaRectHandle cur_box, MaaStringView cur_rec_detail, MaaTransparentArg arg); \ No newline at end of file diff --git a/source/cli/RegisterCustomAciton.h b/source/cli/RegisterCustomAciton.h new file mode 100644 index 0000000..cdaf348 --- /dev/null +++ b/source/cli/RegisterCustomAciton.h @@ -0,0 +1,9 @@ +#pragma once + +#include "MaaFramework/Instance/MaaInstance.h" +#include "MaaFramework/Task/MaaCustomAction.h" +#include "Combat.h" + +void custom_action_init(); + +void register_custom_action(MaaInstanceHandle maa_handle); \ No newline at end of file diff --git a/source/cli/RegisterCustomAction.cpp b/source/cli/RegisterCustomAction.cpp new file mode 100644 index 0000000..bc0d934 --- /dev/null +++ b/source/cli/RegisterCustomAction.cpp @@ -0,0 +1,72 @@ +#include "RegisterCustomAciton.h" + +MaaCustomActionAPI action_combat_forward; +MaaCustomActionAPI action_combat_backward; +MaaCustomActionAPI action_combat_left; +MaaCustomActionAPI action_combat_right; +MaaCustomActionAPI action_combat_left_forward; +MaaCustomActionAPI action_combat_right_forward; +MaaCustomActionAPI action_combat_left_backward; +MaaCustomActionAPI action_combat_right_backward; +MaaCustomActionAPI action_combat_basic_ATK; +MaaCustomActionAPI action_combat_basic_ATK_charge_base; +MaaCustomActionAPI action_combat_basic_ATK_charge; +MaaCustomActionAPI action_combat_evade; +MaaCustomActionAPI action_combat_ultimate; +MaaCustomActionAPI action_combat_ultimate_charge_base; +MaaCustomActionAPI action_combat_ultimate_charge; +MaaCustomActionAPI action_combat_weapon_skill; +MaaCustomActionAPI action_combat_ELF_skill; +MaaCustomActionAPI action_combat_extra_skill; +MaaCustomActionAPI action_combat_QTE1; +MaaCustomActionAPI action_combat_QTE2; + +void custom_action_init() +{ + action_combat_forward.run = combat_forward; + action_combat_backward.run = combat_backward; + action_combat_left.run = combat_left; + action_combat_right.run = combat_right; + action_combat_left_forward.run = combat_left_forward; + action_combat_right_forward.run = combat_right_forward; + action_combat_left_backward.run = combat_left_backward; + action_combat_right_backward.run = combat_right_backward; + action_combat_basic_ATK.run = combat_basic_ATK; + action_combat_basic_ATK_charge_base.run = combat_basic_ATK_charge_base; + action_combat_basic_ATK_charge.run = combat_basic_ATK_charge; + action_combat_evade.run = combat_evade; + action_combat_ultimate.run = combat_ultimate; + action_combat_ultimate_charge_base.run = combat_ultimate_charge_base; + action_combat_ultimate_charge.run = combat_ultimate_charge; + action_combat_weapon_skill.run = combat_weapon_skill; + action_combat_ELF_skill.run = combat_ELF_skill; + action_combat_extra_skill.run = combat_extra_skill; + action_combat_QTE1.run = combat_QTE1; + action_combat_QTE2.run = combat_QTE2; +} + +void register_custom_action(MaaInstanceHandle maa_handle) +{ + custom_action_init(); + + MaaRegisterCustomAction(maa_handle, "Forward", &action_combat_forward, nullptr); + MaaRegisterCustomAction(maa_handle, "Backward", &action_combat_backward, nullptr); + MaaRegisterCustomAction(maa_handle, "Left", &action_combat_left, nullptr); + MaaRegisterCustomAction(maa_handle, "Right", &action_combat_right, nullptr); + MaaRegisterCustomAction(maa_handle, "LeftForward", &action_combat_left_forward, nullptr); + MaaRegisterCustomAction(maa_handle, "RightForward", &action_combat_right_forward, nullptr); + MaaRegisterCustomAction(maa_handle, "LeftBackward", &action_combat_left_backward, nullptr); + MaaRegisterCustomAction(maa_handle, "RightBackward", &action_combat_right_backward, nullptr); + MaaRegisterCustomAction(maa_handle, "BasicATK", &action_combat_basic_ATK, nullptr); + MaaRegisterCustomAction(maa_handle, "BasicATKChargeBase", &action_combat_basic_ATK_charge_base, nullptr); + MaaRegisterCustomAction(maa_handle, "BasicATKCharge", &action_combat_basic_ATK_charge, nullptr); + MaaRegisterCustomAction(maa_handle, "Evade", &action_combat_evade, nullptr); + MaaRegisterCustomAction(maa_handle, "Ultimate", &action_combat_ultimate, nullptr); + MaaRegisterCustomAction(maa_handle, "UltimateChargeBase", &action_combat_ultimate_charge_base, nullptr); + MaaRegisterCustomAction(maa_handle, "UltimateCharge", &action_combat_ultimate_charge, nullptr); + MaaRegisterCustomAction(maa_handle, "WeaponSkill", &action_combat_weapon_skill, nullptr); + MaaRegisterCustomAction(maa_handle, "ELFSkill", &action_combat_ELF_skill, nullptr); + MaaRegisterCustomAction(maa_handle, "ExtraSkill", &action_combat_extra_skill, nullptr); + MaaRegisterCustomAction(maa_handle, "QTE1", &action_combat_QTE1, nullptr); + MaaRegisterCustomAction(maa_handle, "QTE2", &action_combat_QTE2, nullptr); +} \ No newline at end of file diff --git a/source/cli/main.cpp b/source/cli/main.cpp index eb69dc9..96424ae 100644 --- a/source/cli/main.cpp +++ b/source/cli/main.cpp @@ -91,6 +91,8 @@ int main(int argc, char** argv) return -1; } + register_custom_action(maa_handle); + MaaTaskId task_id = 0; for (const auto& task : tasks) { if (!task.enabled) diff --git a/source/cli/main.h b/source/cli/main.h index 1d1a2cd..3a200ff 100644 --- a/source/cli/main.h +++ b/source/cli/main.h @@ -9,6 +9,8 @@ #include "MaaToolKit/MaaToolKitAPI.h" #include "meojson/json.hpp" +#include "RegisterCustomAciton.h" + struct Task { std::string name;