Player: Make interaction radius scriptable

This commit is contained in:
Kae 2023-08-02 21:59:07 +10:00
parent c80b2d2dbc
commit 32e6eab069
4 changed files with 27 additions and 19 deletions

View File

@ -1334,7 +1334,7 @@ InteractiveEntityPtr Player::bestInteractionEntity(bool includeNearby) {
return {}; return {};
InteractiveEntityPtr interactiveEntity; 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; interactiveEntity = entity;
} else if (includeNearby) { } else if (includeNearby) {
Vec2F interactBias = m_walkIntoInteractBias; Vec2F interactBias = m_walkIntoInteractBias;
@ -1346,7 +1346,7 @@ InteractiveEntityPtr Player::bestInteractionEntity(bool includeNearby) {
interactiveEntity = entity; interactiveEntity = entity;
} }
if (interactiveEntity && world()->canReachEntity(position(), interactRadius(), interactiveEntity->entityId())) if (interactiveEntity && (isAdmin() || world()->canReachEntity(position(), interactRadius(), interactiveEntity->entityId())))
return interactiveEntity; return interactiveEntity;
return {}; return {};
} }
@ -1480,6 +1480,10 @@ float Player::interactRadius() const {
return m_interactRadius; return m_interactRadius;
} }
void Player::setInteractRadius(float interactRadius) {
m_interactRadius = interactRadius;
}
List<InteractAction> Player::pullInteractActions() { List<InteractAction> Player::pullInteractActions() {
List<InteractAction> results; List<InteractAction> results;
eraseWhere(m_pendingInteractActions, [&results](auto& promise) { eraseWhere(m_pendingInteractActions, [&results](auto& promise) {
@ -1822,7 +1826,7 @@ bool Player::inInteractionRange() const {
} }
bool Player::inInteractionRange(Vec2F aimPos) 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 { bool Player::inToolRange() const {
@ -1830,7 +1834,7 @@ bool Player::inToolRange() const {
} }
bool Player::inToolRange(Vec2F const& aimPos) 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) { void Player::getNetStates(bool initial) {

View File

@ -147,6 +147,7 @@ public:
float toolRadius() const; float toolRadius() const;
float interactRadius() const override; float interactRadius() const override;
void setInteractRadius(float interactRadius);
List<InteractAction> pullInteractActions(); List<InteractAction> pullInteractActions();
uint64_t currency(String const& currencyType) const; uint64_t currency(String const& currencyType) const;

View File

@ -2005,7 +2005,7 @@ void WorldClient::setProperty(String const& propertyName, Json const& property)
} }
bool WorldClient::playerCanReachEntity(EntityId entityId, bool preferInteractive) const { 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) { void WorldClient::disconnectAllWires(Vec2I wireEntityPosition, WireNode const& node) {

View File

@ -17,27 +17,27 @@ namespace Star {
LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
LuaCallbacks callbacks; 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("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("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("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("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("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("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("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("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("setFacialHairDirectives", [player](String const& str) { player->setFacialHairDirectives(str); });
callbacks.registerCallback("hair", [player]() { 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("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("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<String> const& imagePath) { player->setImagePath(imagePath); }); callbacks.registerCallback("setImagePath", [player](Maybe<String> 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("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) { callbacks.registerCallback("setPersonality", [player](Json const& personalityConfig) {
Personality const& oldPersonality = player->identity().personality; Personality const& oldPersonality = player->identity().personality;
Personality newPersonality = oldPersonality; Personality newPersonality = oldPersonality;
player->setPersonality(parsePersonality(newPersonality, personalityConfig)); 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("id", [player]() { return player->entityId(); });
callbacks.registerCallback("uniqueId", [player]() { return player->uniqueId(); }); callbacks.registerCallback("uniqueId", [player]() { return player->uniqueId(); });
callbacks.registerCallback("isAdmin", [player]() { return player->isAdmin(); }); callbacks.registerCallback("isAdmin", [player]() { return player->isAdmin(); });