luna-rs/luna

Allow npc interaction from a distance

Opened this issue · 2 comments

Currently npc click events are not posted to plugins unless the player is within 1 tile of the target. This prevents handling interactions with a bank teller behind the counter.

There should be a mechanism to subscribe to npc click events from a distance, to allow for handling this scenario.

This isn’t just a problem with npcs. Right now, if you try to telegrab an item from far away, the player still walks up to it — which kinda defeats the point.

It also affects combat. Different weapons have different ranges — like halberds, magic, and ranged attacks. Even something like using a bow on long-range changes how far away you can attack from.

Bank tellers is a good example — they need a different interaction range too. I can’t think of more off the top of my head, but I’m sure there are other cases like that.

We should probably build a system where you can define interaction distances based on the context — like the type of entity, the weapon being used, or even specific quests. Most RSPSs just hardcode this stuff with a bunch of if statements within each packet, but that gets really messy and annoying to debug. There has to be a better way to do this.

Ironically I noticed that same issue with telegrabbing and it's fixed on my end, I'll be pushing a patch shortly.

You can currently define interaction distances within interactable events

public interface InteractableEvent {

    /**
     * @return The target of this interactable event.
     */
    Entity target();

    /**
     * The interaction distance.
     */
    default int distance() {
        return 1;
    }
}

but I'd like to also be able to define custom context-based interaction distances within scripts themselves like

npc(id = 1, distance = 10) { // If no distance parameter, fall back to default event distance (1).
  ...
}

That could solve this problem in an easy way. Otherwise the logic will be piled in the event classes which is messy and defeats the purpose of the plugin system