From 32e6eab0699c0c802435e6fb1a3ad47d2748acee Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Wed, 2 Aug 2023 21:59:07 +1000 Subject: [PATCH] Player: Make interaction radius scriptable --- source/game/StarPlayer.cpp | 12 ++++--- source/game/StarPlayer.hpp | 1 + source/game/StarWorldClient.cpp | 2 +- .../game/scripting/StarPlayerLuaBindings.cpp | 31 ++++++++++--------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/source/game/StarPlayer.cpp b/source/game/StarPlayer.cpp index 70e733e..c9816c1 100644 --- a/source/game/StarPlayer.cpp +++ b/source/game/StarPlayer.cpp @@ -1334,7 +1334,7 @@ InteractiveEntityPtr Player::bestInteractionEntity(bool includeNearby) { return {}; InteractiveEntityPtr interactiveEntity; - if (auto entity = world()->getInteractiveInRange(m_aimPosition, position(), m_interactRadius)) { + if (auto entity = world()->getInteractiveInRange(m_aimPosition, isAdmin() ? m_aimPosition : position(), m_interactRadius)) { interactiveEntity = entity; } else if (includeNearby) { Vec2F interactBias = m_walkIntoInteractBias; @@ -1346,7 +1346,7 @@ InteractiveEntityPtr Player::bestInteractionEntity(bool includeNearby) { interactiveEntity = entity; } - if (interactiveEntity && world()->canReachEntity(position(), interactRadius(), interactiveEntity->entityId())) + if (interactiveEntity && (isAdmin() || world()->canReachEntity(position(), interactRadius(), interactiveEntity->entityId()))) return interactiveEntity; return {}; } @@ -1480,6 +1480,10 @@ float Player::interactRadius() const { return m_interactRadius; } +void Player::setInteractRadius(float interactRadius) { + m_interactRadius = interactRadius; +} + List Player::pullInteractActions() { List results; eraseWhere(m_pendingInteractActions, [&results](auto& promise) { @@ -1822,7 +1826,7 @@ bool Player::inInteractionRange() const { } bool Player::inInteractionRange(Vec2F aimPos) const { - return world()->geometry().diff(aimPos, position()).magnitude() < interactRadius(); + return isAdmin() || world()->geometry().diff(aimPos, position()).magnitude() < interactRadius(); } bool Player::inToolRange() const { @@ -1830,7 +1834,7 @@ bool Player::inToolRange() const { } bool Player::inToolRange(Vec2F const& aimPos) const { - return world()->geometry().diff(aimPos, position()).magnitude() < toolRadius(); + return isAdmin() || world()->geometry().diff(aimPos, position()).magnitude() < toolRadius(); } void Player::getNetStates(bool initial) { diff --git a/source/game/StarPlayer.hpp b/source/game/StarPlayer.hpp index e888015..c70c21e 100644 --- a/source/game/StarPlayer.hpp +++ b/source/game/StarPlayer.hpp @@ -147,6 +147,7 @@ public: float toolRadius() const; float interactRadius() const override; + void setInteractRadius(float interactRadius); List pullInteractActions(); uint64_t currency(String const& currencyType) const; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 5ade948..34214ba 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -2005,7 +2005,7 @@ void WorldClient::setProperty(String const& propertyName, Json const& property) } bool WorldClient::playerCanReachEntity(EntityId entityId, bool preferInteractive) const { - return canReachEntity(m_mainPlayer->position(), m_mainPlayer->interactRadius(), entityId, preferInteractive); + return m_mainPlayer->isAdmin() || canReachEntity(m_mainPlayer->position(), m_mainPlayer->interactRadius(), entityId, preferInteractive); } void WorldClient::disconnectAllWires(Vec2I wireEntityPosition, WireNode const& node) { diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 5980a1d..cede4d0 100644 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -17,27 +17,27 @@ namespace Star { LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { LuaCallbacks callbacks; - callbacks.registerCallback("humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); }); + callbacks.registerCallback( "humanoidIdentity", [player]() { return player->humanoid()->identity().toJson(); }); callbacks.registerCallback("setHumanoidIdentity", [player](Json const& id) { player->setIdentity(HumanoidIdentity(id)); }); - callbacks.registerCallback("bodyDirectives", [player]() { return player->identity().bodyDirectives; }); + callbacks.registerCallback( "bodyDirectives", [player]() { return player->identity().bodyDirectives; }); callbacks.registerCallback("setBodyDirectives", [player](String const& str) { player->setBodyDirectives(str); }); - callbacks.registerCallback("emoteDirectives", [player]() { return player->identity().emoteDirectives; }); + callbacks.registerCallback( "emoteDirectives", [player]() { return player->identity().emoteDirectives; }); callbacks.registerCallback("setEmoteDirectives", [player](String const& str) { player->setEmoteDirectives(str); }); - callbacks.registerCallback("hairGroup", [player]() { return player->identity().hairGroup; }); + callbacks.registerCallback( "hairGroup", [player]() { return player->identity().hairGroup; }); callbacks.registerCallback("setHairGroup", [player](String const& str) { player->setHairGroup(str); }); - callbacks.registerCallback("hairType", [player]() { return player->identity().hairType; }); + callbacks.registerCallback( "hairType", [player]() { return player->identity().hairType; }); callbacks.registerCallback("setHairType", [player](String const& str) { player->setHairType(str); }); - callbacks.registerCallback("hairDirectives", [player]() { return player->identity().hairDirectives; }); + callbacks.registerCallback( "hairDirectives", [player]() { return player->identity().hairDirectives; }); callbacks.registerCallback("setHairDirectives", [player](String const& str) { player->setHairDirectives(str); }); - callbacks.registerCallback("facialHairGroup", [player]() { return player->identity().facialHairGroup; }); + callbacks.registerCallback( "facialHairGroup", [player]() { return player->identity().facialHairGroup; }); callbacks.registerCallback("setFacialHairGroup", [player](String const& str) { player->setFacialHairGroup(str); }); - callbacks.registerCallback("facialHairType", [player]() { return player->identity().facialHairType; }); + callbacks.registerCallback( "facialHairType", [player]() { return player->identity().facialHairType; }); callbacks.registerCallback("setFacialHairType", [player](String const& str) { player->setFacialHairType(str); }); - callbacks.registerCallback("facialHairDirectives", [player]() { return player->identity().facialHairDirectives; }); + callbacks.registerCallback( "facialHairDirectives", [player]() { return player->identity().facialHairDirectives; }); callbacks.registerCallback("setFacialHairDirectives", [player](String const& str) { player->setFacialHairDirectives(str); }); callbacks.registerCallback("hair", [player]() { @@ -85,25 +85,28 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { } }); - callbacks.registerCallback("name", [player]() { return player->name(); }); + callbacks.registerCallback( "name", [player]() { return player->name(); }); callbacks.registerCallback("setName", [player](String const& name) { player->setName(name); }); - callbacks.registerCallback("species", [player]() { return player->species(); }); + callbacks.registerCallback( "species", [player]() { return player->species(); }); callbacks.registerCallback("setSpecies", [player](String const& species) { player->setSpecies(species); }); - callbacks.registerCallback("imagePath", [player]() { return player->identity().imagePath; }); + callbacks.registerCallback( "imagePath", [player]() { return player->identity().imagePath; }); callbacks.registerCallback("setImagePath", [player](Maybe const& imagePath) { player->setImagePath(imagePath); }); - callbacks.registerCallback("gender", [player]() { return GenderNames.getRight(player->gender()); }); + callbacks.registerCallback( "gender", [player]() { return GenderNames.getRight(player->gender()); }); callbacks.registerCallback("setGender", [player](String const& gender) { player->setGender(GenderNames.getLeft(gender)); }); - callbacks.registerCallback("personality", [player]() { return jsonFromPersonality(player->identity().personality); }); + callbacks.registerCallback( "personality", [player]() { return jsonFromPersonality(player->identity().personality); }); callbacks.registerCallback("setPersonality", [player](Json const& personalityConfig) { Personality const& oldPersonality = player->identity().personality; Personality newPersonality = oldPersonality; player->setPersonality(parsePersonality(newPersonality, personalityConfig)); }); + callbacks.registerCallback( "interactRadius", [player]() { return player->interactRadius(); }); + callbacks.registerCallback("setInteractRadius", [player](float radius) { player->setInteractRadius(radius); }); + callbacks.registerCallback("id", [player]() { return player->entityId(); }); callbacks.registerCallback("uniqueId", [player]() { return player->uniqueId(); }); callbacks.registerCallback("isAdmin", [player]() { return player->isAdmin(); });