Skip to content

feat(shortestpath): avoid pathing next to aggressive NPCs (undead trees)#1809

Open
bgatfa wants to merge 1 commit into
chsami:developmentfrom
bgatfa:feat/pathfinder-avoid-dangerous-npcs
Open

feat(shortestpath): avoid pathing next to aggressive NPCs (undead trees)#1809
bgatfa wants to merge 1 commit into
chsami:developmentfrom
bgatfa:feat/pathfinder-avoid-dangerous-npcs

Conversation

@bgatfa

@bgatfa bgatfa commented Jun 26, 2026

Copy link
Copy Markdown

What

Adds an Avoid dangerous NPCs pathfinder option (default on) that
routes the web walker around tiles adjacent to known aggressive-NPC hazards,
so the player isn't attacked while passing. Seeded with the Draynor Manor
undead trees.

Why

Undead trees (Draynor Manor front yard; also Haunted Woods) attack players
who path onto an adjacent tile — 0–3 damage, aggressive regardless of combat
level. The pathfinder draws the shortest route straight along them, so long
walks past Draynor take repeated hits and can stall the walker next to a tree.

How it works

  • dangerous_tiles.tsv (new resource) lists hazard tiles (x y plane).
  • PathfinderConfig loads them and expands each to its 8-neighbour Chebyshev-1
    ring (the melee-aggro range); isDangerousAdjacentTile(packed) exposes it.
  • CollisionMap adds a g-cost penalty (DANGEROUS_TILE_PENALTY, not a block)
    to stepping into that ring when the option is on, in both the forward
    (getNeighbors) and reverse (getReverseNeighbors) expansions — so the
    bidirectional search costs hazard edges consistently and can't pick a
    hazard-adjacent meeting point. Paths keep ≥2 tiles away when a reasonable
    detour exists; a genuine chokepoint still routes through. Hot-loop cost is a
    boolean + O(1) HashSet lookup; no client-thread access.
  • ShortestPathConfig.avoidDangerousNpcs() toggle, default true
    (sectionSettings positions renumbered to stay unique).

Testing

  • Live A/B (same client, Draynor Manor): option off → path hugs a tree
    at dTree=1; option on → path detours to dTree≥2 with 0/16 combat.
    Since these NPCs only hit at 1 tile, dTree≥2 means the player is physically
    out of range. Re-run after the review fixes — unchanged.
  • Unit tests: shortestpath suite (Tier1 regression, transport, config
    hash) and ClientThreadGuardrailTest pass; no new client-thread violations.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 05660d3f-6fed-4230-82c8-1f30d7ba4a2e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Adds a new avoidDangerousNpcs config option, wires it into PathfinderConfig.refresh(...), and loads dangerous-adjacent tiles from dangerous_tiles.tsv into a packed set. CollisionMap.getNeighbors(...) now checks that set and adds an extra traversal penalty for dangerous adjacent tiles when the neighbor is not a target.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: shortestpath now avoids routing next to aggressive NPCs, seeded with undead trees.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description clearly matches the shortest-path dangerous-NPC routing changes described in the changeset.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/pathfinder/CollisionMap.java`:
- Around line 268-279: The reverse walking expansion in
CollisionMap.getReverseNeighbors is still creating unpenalized Nodes, so it
disagrees with the forward neighbor cost model and can let bidirectional
searches prefer hazard-adjacent routes. Update the reverse walking branch to
apply the same dangerous-NPC penalty logic used in the forward expansion,
reusing the same config.isAvoidDangerousNpcs, config.isDangerousAdjacentTile,
targets.contains, and DANGEROUS_TILE_PENALTY checks so both directions evaluate
the edge consistently.

In
`@runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/ShortestPathConfig.java`:
- Around line 135-146: The config ordering in ShortestPathConfig has a duplicate
position value, making the settings UI order ambiguous. Update the `@ConfigItem`
on avoidDangerousNpcs in the sectionSettings group to use a unique position, and
renumber any following items in that section if needed so each setting has a
distinct order; use the existing useAgilityShortcuts and other nearby config
methods in ShortestPathConfig to locate the affected entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ea23a094-14ec-406c-bfcc-42116aef02bb

📥 Commits

Reviewing files that changed from the base of the PR and between fd57cc1 and 4f776e7.

⛔ Files ignored due to path filters (1)
  • runelite-client/src/main/resources/net/runelite/client/plugins/microbot/shortestpath/dangerous_tiles.tsv is excluded by !**/*.tsv
📒 Files selected for processing (3)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/ShortestPathConfig.java
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/pathfinder/CollisionMap.java
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/pathfinder/PathfinderConfig.java

@bgatfa bgatfa force-pushed the feat/pathfinder-avoid-dangerous-npcs branch from 4f776e7 to 00829cb Compare June 26, 2026 16:09
Aggressive NPCs such as the Draynor Manor undead trees attack any player
who walks onto a tile next to them (0-3 dmg, aggressive at every combat
level). The web walker routes the shortest path straight along the tree
line, so long walks take repeated hits and can stall the walker adjacent
to a tree.

Add an "Avoid dangerous NPCs" pathfinder option (default on):
- New dangerous_tiles.tsv lists hazard tiles (the Draynor undead trees).
- PathfinderConfig expands each hazard tile to its 8-neighbour aggro ring
  and exposes isDangerousAdjacentTile().
- CollisionMap applies a g-cost penalty (not a hard block) to stepping into
  that ring when the option is on, in BOTH the forward (getNeighbors) and
  reverse (getReverseNeighbors) expansions, so the bidirectional search costs
  hazard edges consistently and can't pick a hazard-adjacent meeting. Paths
  keep >=2 tiles from a hazard when a detour exists; a true chokepoint still
  routes through. The check is a boolean + O(1) set lookup; no client-thread
  reads.
- ShortestPathConfig gains the toggle; the sectionSettings positions are
  renumbered to stay unique.
- Rs2Walker's unreachable-recovery fallback now also respects the ring: the
  planner avoids hazard tiles, but the runtime recovery click could otherwise
  park the player next to one and strand it in melee, so the recovery target
  is stepped back along the path to the nearest non-hazard tile.

Data-driven: any hazard can be added by appending tiles to the tsv.
@bgatfa bgatfa force-pushed the feat/pathfinder-avoid-dangerous-npcs branch from 00829cb to a23c705 Compare June 26, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant