Player: Make interaction radius scriptable
This commit is contained in:
parent
c80b2d2dbc
commit
32e6eab069
@ -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<InteractAction> Player::pullInteractActions() {
|
||||
List<InteractAction> 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) {
|
||||
|
@ -147,6 +147,7 @@ public:
|
||||
|
||||
float toolRadius() const;
|
||||
float interactRadius() const override;
|
||||
void setInteractRadius(float interactRadius);
|
||||
List<InteractAction> pullInteractActions();
|
||||
|
||||
uint64_t currency(String const& currencyType) const;
|
||||
|
@ -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) {
|
||||
|
@ -104,6 +104,9 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) {
|
||||
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(); });
|
||||
|
Loading…
Reference in New Issue
Block a user