diff --git a/doc/lua/player.md b/doc/lua/player.md index fd8ebd4..f281bad 100644 --- a/doc/lua/player.md +++ b/doc/lua/player.md @@ -527,3 +527,9 @@ Returns uuid, type, and orbits for all system objects in the specified system; #### `List` player.collectables(`String` collectionName) Returns a list of names of the collectables the player has unlocked in the specified collection. + +--- + +#### `List` player.teamMembers() + +Returns an array, each entry being a table with `name`, `uuid`, `entity`, `healthPercentage` and `energyPercentage` diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 8ee6d7a..2f89ff3 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -293,6 +293,10 @@ void Player::setUniverseClient(UniverseClient* client) { m_questManager->setUniverseClient(client); } +UniverseClient* Player::universeClient() const { + return m_client; +} + EntityType Player::entityType() const { return EntityType::Player; } diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp index f6e32e0..1a6a5c2 100644 --- a/source/game/StarPlayer.hpp +++ b/source/game/StarPlayer.hpp @@ -88,6 +88,7 @@ public: void setStatistics(StatisticsPtr statistics); void setUniverseClient(UniverseClient* universeClient); + UniverseClient* universeClient() const; QuestManagerPtr questManager() const; diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index ea902ab..bf14c2c 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -11,6 +11,8 @@ #include "StarStatistics.hpp" #include "StarPlayerUniverseMap.hpp" #include "StarJsonExtra.hpp" +#include "StarUniverseClient.hpp" +#include "StarTeamClient.hpp" namespace Star { @@ -27,6 +29,20 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { } }); + callbacks.registerCallback("teamMembers", [player]() -> Maybe { + if (auto client = player->universeClient()) { + return client->teamClient()->members().transformed([](TeamClient::Member const& member) -> Json { + return JsonObject{ + {"name", member.name}, + {"uuid", member.uuid.hex()}, + {"entity", member.entity}, + {"healthPercentage", member.healthPercentage}, + {"energyPercentage", member.energyPercentage}}; + }); + } + return {}; + }); + callbacks.registerCallback( "humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); }); callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); });