diff --git a/build/.cmake/api/v1/reply/codemodel-v2-ffaaca604fe32ea15b03.json b/build/.cmake/api/v1/reply/codemodel-v2-417377ecfa385c483b0f.json similarity index 95% rename from build/.cmake/api/v1/reply/codemodel-v2-ffaaca604fe32ea15b03.json rename to build/.cmake/api/v1/reply/codemodel-v2-417377ecfa385c483b0f.json index 99b32db..c3d8c71 100644 --- a/build/.cmake/api/v1/reply/codemodel-v2-ffaaca604fe32ea15b03.json +++ b/build/.cmake/api/v1/reply/codemodel-v2-417377ecfa385c483b0f.json @@ -45,7 +45,7 @@ { "directoryIndex" : 0, "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", - "jsonFile" : "target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json", + "jsonFile" : "target-ALL_BUILD-Debug-86a97d3bececc473eb01.json", "name" : "ALL_BUILD", "projectIndex" : 0 }, @@ -116,7 +116,7 @@ { "directoryIndex" : 0, "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", - "jsonFile" : "target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json", + "jsonFile" : "target-ALL_BUILD-Release-86a97d3bececc473eb01.json", "name" : "ALL_BUILD", "projectIndex" : 0 }, @@ -187,7 +187,7 @@ { "directoryIndex" : 0, "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", - "jsonFile" : "target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json", + "jsonFile" : "target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json", "name" : "ALL_BUILD", "projectIndex" : 0 }, @@ -258,7 +258,7 @@ { "directoryIndex" : 0, "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", - "jsonFile" : "target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json", + "jsonFile" : "target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json", "name" : "ALL_BUILD", "projectIndex" : 0 }, diff --git a/build/.cmake/api/v1/reply/index-2024-05-13T15-48-51-0001.json b/build/.cmake/api/v1/reply/index-2024-05-14T18-01-02-0979.json similarity index 95% rename from build/.cmake/api/v1/reply/index-2024-05-13T15-48-51-0001.json rename to build/.cmake/api/v1/reply/index-2024-05-14T18-01-02-0979.json index 1c1020c..39a8a3e 100644 --- a/build/.cmake/api/v1/reply/index-2024-05-13T15-48-51-0001.json +++ b/build/.cmake/api/v1/reply/index-2024-05-14T18-01-02-0979.json @@ -27,7 +27,7 @@ "objects" : [ { - "jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json", + "jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json", "kind" : "codemodel", "version" : { @@ -100,7 +100,7 @@ } }, { - "jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json", + "jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json", "kind" : "codemodel", "version" : { diff --git a/build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json b/build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-86a97d3bececc473eb01.json similarity index 100% rename from build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json rename to build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-86a97d3bececc473eb01.json index bb652c9..7407065 100644 --- a/build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json +++ b/build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-86a97d3bececc473eb01.json @@ -16,14 +16,14 @@ }, "dependencies" : [ - { - "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" - }, { "id" : "GenerateHeaders::@6890427a1f51a3e7e1df" }, { "id" : "ISXMr::@6890427a1f51a3e7e1df" + }, + { + "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" } ], "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", diff --git a/build/.cmake/api/v1/reply/target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json b/build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json similarity index 100% rename from build/.cmake/api/v1/reply/target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json rename to build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json index bb652c9..7407065 100644 --- a/build/.cmake/api/v1/reply/target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json +++ b/build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json @@ -16,14 +16,14 @@ }, "dependencies" : [ - { - "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" - }, { "id" : "GenerateHeaders::@6890427a1f51a3e7e1df" }, { "id" : "ISXMr::@6890427a1f51a3e7e1df" + }, + { + "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" } ], "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", diff --git a/build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json b/build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json similarity index 100% rename from build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json rename to build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json index bb652c9..7407065 100644 --- a/build/.cmake/api/v1/reply/target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json +++ b/build/.cmake/api/v1/reply/target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json @@ -16,14 +16,14 @@ }, "dependencies" : [ - { - "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" - }, { "id" : "GenerateHeaders::@6890427a1f51a3e7e1df" }, { "id" : "ISXMr::@6890427a1f51a3e7e1df" + }, + { + "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" } ], "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", diff --git a/build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json b/build/.cmake/api/v1/reply/target-ALL_BUILD-Release-86a97d3bececc473eb01.json similarity index 100% rename from build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json rename to build/.cmake/api/v1/reply/target-ALL_BUILD-Release-86a97d3bececc473eb01.json index bb652c9..7407065 100644 --- a/build/.cmake/api/v1/reply/target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json +++ b/build/.cmake/api/v1/reply/target-ALL_BUILD-Release-86a97d3bececc473eb01.json @@ -16,14 +16,14 @@ }, "dependencies" : [ - { - "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" - }, { "id" : "GenerateHeaders::@6890427a1f51a3e7e1df" }, { "id" : "ISXMr::@6890427a1f51a3e7e1df" + }, + { + "id" : "ZERO_CHECK::@6890427a1f51a3e7e1df" } ], "id" : "ALL_BUILD::@6890427a1f51a3e7e1df", diff --git a/build/ISXMr.dir/Release/Ability.obj b/build/ISXMr.dir/Release/Ability.obj index 23610f3..69c74ef 100644 Binary files a/build/ISXMr.dir/Release/Ability.obj and b/build/ISXMr.dir/Release/Ability.obj differ diff --git a/build/ISXMr.dir/Release/ActorTLO.obj b/build/ISXMr.dir/Release/ActorTLO.obj index 58160f8..a35f3df 100644 Binary files a/build/ISXMr.dir/Release/ActorTLO.obj and b/build/ISXMr.dir/Release/ActorTLO.obj differ diff --git a/build/ISXMr.dir/Release/BotTask.obj b/build/ISXMr.dir/Release/BotTask.obj index 9cc4aa5..edbe61f 100644 Binary files a/build/ISXMr.dir/Release/BotTask.obj and b/build/ISXMr.dir/Release/BotTask.obj differ diff --git a/build/ISXMr.dir/Release/Commands.obj b/build/ISXMr.dir/Release/Commands.obj index 6c4b79b..3eb2ea3 100644 Binary files a/build/ISXMr.dir/Release/Commands.obj and b/build/ISXMr.dir/Release/Commands.obj differ diff --git a/build/ISXMr.dir/Release/ExportAbilitiesTask.obj b/build/ISXMr.dir/Release/ExportAbilitiesTask.obj index 8518b6f..461e7a7 100644 Binary files a/build/ISXMr.dir/Release/ExportAbilitiesTask.obj and b/build/ISXMr.dir/Release/ExportAbilitiesTask.obj differ diff --git a/build/ISXMr.dir/Release/ISXMr.obj b/build/ISXMr.dir/Release/ISXMr.obj index b00a4b7..0d153de 100644 Binary files a/build/ISXMr.dir/Release/ISXMr.obj and b/build/ISXMr.dir/Release/ISXMr.obj differ diff --git a/build/ISXMr.dir/Release/ISXMr.tlog/CL.command.1.tlog b/build/ISXMr.dir/Release/ISXMr.tlog/CL.command.1.tlog index 43cfc6e..ecbb2d1 100644 Binary files a/build/ISXMr.dir/Release/ISXMr.tlog/CL.command.1.tlog and b/build/ISXMr.dir/Release/ISXMr.tlog/CL.command.1.tlog differ diff --git a/build/ISXMr.dir/Release/ISXMr.tlog/CL.read.1.tlog b/build/ISXMr.dir/Release/ISXMr.tlog/CL.read.1.tlog index aff1ff5..7b8db04 100644 Binary files a/build/ISXMr.dir/Release/ISXMr.tlog/CL.read.1.tlog and b/build/ISXMr.dir/Release/ISXMr.tlog/CL.read.1.tlog differ diff --git a/build/ISXMr.dir/Release/ISXMr.tlog/CL.write.1.tlog b/build/ISXMr.dir/Release/ISXMr.tlog/CL.write.1.tlog index 709e454..af1aeac 100644 Binary files a/build/ISXMr.dir/Release/ISXMr.tlog/CL.write.1.tlog and b/build/ISXMr.dir/Release/ISXMr.tlog/CL.write.1.tlog differ diff --git a/build/ISXMr.dir/Release/MrBotApi.obj b/build/ISXMr.dir/Release/MrBotApi.obj index 34d3084..ab914eb 100644 Binary files a/build/ISXMr.dir/Release/MrBotApi.obj and b/build/ISXMr.dir/Release/MrBotApi.obj differ diff --git a/build/ISXMr.dir/Release/MrBotApiType.obj b/build/ISXMr.dir/Release/MrBotApiType.obj index 7c23a9f..80ede28 100644 Binary files a/build/ISXMr.dir/Release/MrBotApiType.obj and b/build/ISXMr.dir/Release/MrBotApiType.obj differ diff --git a/src/DataTypes/MrBotApiType.cpp b/src/DataTypes/MrBotApiType.cpp index 0a19bbd..d8a3f22 100644 --- a/src/DataTypes/MrBotApiType.cpp +++ b/src/DataTypes/MrBotApiType.cpp @@ -39,6 +39,17 @@ bool MrBotApiType::ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int bufle return false; } +unsigned long MrBotApiType::GetActorIdByName(const std::string &actorName, bool exactMatch) +{ + const auto actor = ExtensionTLOs::Actor().GetActorByName(actorName, exactMatch); + if (actor.has_value()) + { + return actor->Id(); + } + + return -1; +} + // Members bool MrBotApiType::Version(const std::vector &args, LSOBJECT &dest) { @@ -56,16 +67,14 @@ bool MrBotApiType::ClickActorByName(const std::vector &args) return false; } - const std::string &name = args[0]; - log << "MrBotApiType::ClickActorByName " << name << std::endl; - const auto actor = ExtensionTLOs::Actor().GetActorByName(name); - if (!actor.has_value()) + const auto actorId = GetActorIdByName(args[0]); + if (actorId == -1) { - logw << "MrBotApiType::ClickActorByName: Actor not found: " << name << std::endl; + logw << "MrBotApiType::ClickActorByName: Actor not found: " << args[0] << std::endl; return false; } - // actor->DoubleClick(); - return true; + + return ClickActorById({std::to_string(actorId)}); } bool MrBotApiType::ClickActorById(const std::vector &args) @@ -88,4 +97,29 @@ bool MrBotApiType::ClickActorById(const std::vector &args) log << "MrBotApiType::ClickActorById: Actor found: " << actor->Name() << std::endl; actor->DoubleClick(); + return true; +} + +bool MrBotApiType::ApplyVerb(const std::vector &args) +{ + if (args.size() != 2) + { + logw << "MrBotApiType::ApplyVerb: Expected 2 arguments, got " << args.size() << std::endl; + return false; + } + + const auto actorId = GetActorIdByName(args[0]); + if (actorId == -1) + { + logw << "MrBotApiType::ApplyVerb: Actor not found: " << args[0] << std::endl; + return false; + } + + const auto verb = args[1]; + + const auto command = "eq2execute apply_verb " + std::to_string(actorId) + " \"" + verb + "\""; + log << "MrBotApiType::ApplyVerb: " << command << std::endl; + const auto response = pISInterface->ExecuteCommand(command.c_str()); + + return response == 0; } diff --git a/src/DataTypes/MrBotApiType.h b/src/DataTypes/MrBotApiType.h index 68bb979..434d0ac 100644 --- a/src/DataTypes/MrBotApiType.h +++ b/src/DataTypes/MrBotApiType.h @@ -2,6 +2,7 @@ #include #include +#include #include "../isxeq2/ExtensionTLOs.h" #define ADD_MEMBER_TO_MAP(EnumType, memberName, expectedArgc) \ @@ -43,7 +44,8 @@ public: enum class MrBotApiTypeMethods { ClickActorByName, - ClickActorById + ClickActorById, + ApplyVerb }; MrBotApiType() : LSTypeDefinition(const_cast("mrbotapi")) @@ -51,6 +53,7 @@ public: ADD_MEMBER_TO_MAP(MrBotApiTypeMembers, Version, 0); ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorByName, 1); ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorById, 1); + ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ApplyVerb, 2); } virtual bool GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER pMember, int argc, char *argv[], LSOBJECT &Dest); @@ -86,11 +89,14 @@ public: } private: + // Helpers + unsigned long GetActorIdByName(const std::string &actorName, bool exactMatch = false); // Members bool Version(const std::vector &args, LSOBJECT &dest); // Methods bool ClickActorByName(const std::vector &args); bool ClickActorById(const std::vector &args); + bool ApplyVerb(const std::vector &args); static unique_ptr pMrBotApi; using MethodFunc = std::function; diff --git a/src/isxeq2/ActorTLO.cpp b/src/isxeq2/ActorTLO.cpp index c337f62..9d5fd8d 100644 --- a/src/isxeq2/ActorTLO.cpp +++ b/src/isxeq2/ActorTLO.cpp @@ -24,17 +24,18 @@ optional ActorTLO::GetActorById(unsigned long id) const // return Actor(make_shared(actor)); } -optional ActorTLO::GetActorByName(const std::string &name) const +optional ActorTLO::GetActorByName(const std::string &name, const bool exactMatch) const { - return nullopt; - // log << "ActorTLO::GetActorByName: " << name << std::endl; - // return nullopt; - // const auto actor = this->lsObject->GetMember("Actor", "Name =- " + name); - // if (!actor.has_value()) - // { - // logw << "ActorTLO::GetActorByName: Actor not found: " << name << std::endl; - // return nullopt; - // } + stringstream query; + query << "Actor[query, Name " << (exactMatch ? "==" : "=-") << " \"" << name << "\"]"; + const string command = query.str(); + log << "ActorTLO::GetActorByName: " << command << std::endl; - // return Actor(make_shared(actor)); + const auto actor = LSObject::FromDataParse(command); + if (actor.has_value()) + { + return Actor(actor.value()); + } + + return nullopt; } diff --git a/src/isxeq2/ActorTLO.h b/src/isxeq2/ActorTLO.h index df6b627..9f4b747 100644 --- a/src/isxeq2/ActorTLO.h +++ b/src/isxeq2/ActorTLO.h @@ -9,7 +9,7 @@ public: } optional GetActorById(unsigned long id) const; - optional GetActorByName(const std::string &name) const; + optional GetActorByName(const std::string &name, const bool exactMatch = false) const; optional GetActorByQuery(const std::string &query) const; private: