Skip to content

fix: unify NPC interaction distance between view and enter - #20

Closed
s6pa1rta3n-lab wants to merge 0 commit into
Bitcoindefi:mainfrom
s6pa1rta3n-lab:fix/issue-8-npc-range
Closed

s6pa1rta3n-lab wants to merge 0 commit into
Bitcoindefi:mainfrom
s6pa1rta3n-lab:fix/issue-8-npc-range

Conversation

@s6pa1rta3n-lab

@s6pa1rta3n-lab s6pa1rta3n-lab commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #8

This PR unifies the NPC interaction distance between view() and enter() in lib/game.js:

  • view() was checking for NPCs within a Chebyshev distance of 2 (this.nearbyNpc(2)), advertising | <npc.name>, <npc.role> | e hablar.
  • enter() called this.nearbyNpc() with default range 1, causing e interactions to fail with "aca no hay nada" when 2 tiles away.

Changes

  • Updated nearbyNpc default parameter to range = 2.
  • Updated enter() to explicitly pass range 2 (this.nearbyNpc(2)).
  • Added unit test in test/index.js verifying interaction at 2 tiles distance and out-of-range behavior at 3 tiles.

@leocagli

Copy link
Copy Markdown
Collaborator

This one no longer merges into main.

main moved a lot since it was opened: the save slot system, the coliseum map, the
world boss, and several render fixes all landed. The branch conflicts, so I cannot
test what the merged result would do.

If you rebase it on today's main I will re-run it and report the numbers here. The
current baseline is 65 tests and 515 assertions in green.

One thing worth checking while rebasing: another contributor opened a pull request
for the same issue, so it is worth a look before spending time on the conflict, in
case the work is already covered.

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main, resolved conflicts, and verified npm test and npm run lint are green.

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor Author

Rebased onto current main, resolved any conflicts, and verified all tests pass cleanly.

Comment thread test/index.js
game.field.player.y = incoming.y
game.drain(game.field.boss.touch(game.field.player, game.field.time + 20))
t.is(game.player.hp, life - 6, 'field contact updates the persistent character sheet')
})

@gitar-bot gitar-bot Bot Aug 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 Bug: PR no longer fixes issue #8; NPC range mismatch persists untested

The PR's stated purpose is to unify the NPC interaction distance, but at HEAD nearbyNpc still defaults to range = 1 (line 465), enter() still calls this.nearbyNpc() with the default range 1 (line 1168), while view() advertises e hablar using this.nearbyNpc(2) (line 1576). So pressing e from 2 tiles away still fails with "aca no hay nada" — the exact bug #8 describes remains unfixed. This delta commit ("resolve conflict with upstream main") also deleted the only regression test that exercised this behavior, so nothing now guards against the mismatch. Restore the fix (make enter() use range 2, e.g. change line 465 to nearbyNpc(range = 2) or pass this.nearbyNpc(2) at line 1168) and re-add the deleted e interacts with npc at 2 tiles distance test.

Make the default range 2 so enter() (which calls nearbyNpc() with no argument) matches the range view() uses to advertise the prompt.:

nearbyNpc(range = 2) {

Was this helpful? React with 👍 / 👎

Comment thread lib/map.js
return { doorX: x + 37, doorY: bottom }
}

const garden = (x, y, w, h) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: Garden pond (solid water) overwrites carved access corridors

In garden() the '.' access paths are filled first (lines 925-926) but the pond is drawn afterward with solid ~ water (line 59 marks water solid) over the garden centre (line 934), overwriting the middle of both the horizontal and vertical corridors. The garden remains reachable only because the cobble (;, walkable) interior wraps around the pond, so the outer path openings still connect to the interior; if the pond size or corridor position ever changes this coupling could silently seal an approach. Consider re-carving the corridor segments after drawing the pond, or drawing the pond before the paths, to keep the access guarantee robust.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Code Review 🚫 Blocked 0 resolved / 4 findings

Unifies NPC interaction distance between view and enter methods, but is blocked by a mismatched title shipping an unrelated world-boss feature, undefined damage handling in attackWorldBoss, and persistent issue #8 range mismatch.

🚨 Bug: PR no longer fixes issue #8; NPC range mismatch persists untested

📄 test/index.js:1209

The PR's stated purpose is to unify the NPC interaction distance, but at HEAD nearbyNpc still defaults to range = 1 (line 465), enter() still calls this.nearbyNpc() with the default range 1 (line 1168), while view() advertises e hablar using this.nearbyNpc(2) (line 1576). So pressing e from 2 tiles away still fails with "aca no hay nada" — the exact bug #8 describes remains unfixed. This delta commit ("resolve conflict with upstream main") also deleted the only regression test that exercised this behavior, so nothing now guards against the mismatch. Restore the fix (make enter() use range 2, e.g. change line 465 to nearbyNpc(range = 2) or pass this.nearbyNpc(2) at line 1168) and re-add the deleted e interacts with npc at 2 tiles distance test.

Make the default range 2 so enter() (which calls nearbyNpc() with no argument) matches the range view() uses to advertise the prompt.
nearbyNpc(range = 2) {
💡 Quality: Commit ships large world-boss feature under an NPC-fix title

📄 lib/game.js:547-561 📄 lib/game.js:969-981 📄 lib/game.js:1113-1116 📄 lib/game.js:1511-1525 📄 test/index.js:1205-1209

The single commit / PR is titled and described as unifying NPC interaction distance (nearbyNpc range), but the actual delta adds a substantial, unrelated world-boss feature: new drain() event cases (boss-hit/boss-damaged/boss-win/boss-death), attackWorldBoss(), the 'f' key handler, view() boss captions, and boss/coliseum tests. Bundling an unrelated feature under a fix label makes the change hard to review and to revert cleanly. Consider splitting the world-boss work into its own PR (or at least retitling and updating the description to reflect what actually changed).

💡 Edge Case: attackWorldBoss may pass undefined damage for non-weapon left item

📄 lib/game.js:969-981

attackWorldBoss() derives the attack from CONTENT.items[equipped.left]. It only falls back to damage:1/reach:1 when the item is absent (weapon === null). If the left slot ever holds a non-weapon item present in CONTENT.items (no atk/reach fields), damage/reach become undefined and are passed into field.attackBoss(), which can yield NaN damage. Guard the per-field fallback (e.g. damage: weapon && weapon.atk ? weapon.atk : 1) rather than relying solely on the item being missing.

Fall back to defaults per-field when the equipped item lacks atk/reach.
const weapon = CONTENT.items[equipped.left] || null
const attack = {
  damage: weapon && Number.isFinite(weapon.atk) ? weapon.atk : 1,
  reach: weapon && Number.isFinite(weapon.reach) ? weapon.reach : 1
}
💡 Edge Case: Garden pond (solid water) overwrites carved access corridors

📄 lib/map.js:918-932

In garden() the '.' access paths are filled first (lines 925-926) but the pond is drawn afterward with solid ~ water (line 59 marks water solid) over the garden centre (line 934), overwriting the middle of both the horizontal and vertical corridors. The garden remains reachable only because the cobble (;, walkable) interior wraps around the pond, so the outer path openings still connect to the interior; if the pond size or corridor position ever changes this coupling could silently seal an approach. Consider re-carving the corridor segments after drawing the pond, or drawing the pond before the paths, to keep the access guarantee robust.

🤖 Prompt for agents
Code Review: Unifies NPC interaction distance between view and enter methods, but is blocked by a mismatched title shipping an unrelated world-boss feature, undefined damage handling in attackWorldBoss, and persistent issue #8 range mismatch.

1. 💡 Quality: Commit ships large world-boss feature under an NPC-fix title
   Files: lib/game.js:547-561, lib/game.js:969-981, lib/game.js:1113-1116, lib/game.js:1511-1525, test/index.js:1205-1209

   The single commit / PR is titled and described as unifying NPC interaction distance (nearbyNpc range), but the actual delta adds a substantial, unrelated world-boss feature: new drain() event cases (boss-hit/boss-damaged/boss-win/boss-death), attackWorldBoss(), the 'f' key handler, view() boss captions, and boss/coliseum tests. Bundling an unrelated feature under a fix label makes the change hard to review and to revert cleanly. Consider splitting the world-boss work into its own PR (or at least retitling and updating the description to reflect what actually changed).

2. 💡 Edge Case: attackWorldBoss may pass undefined damage for non-weapon left item
   Files: lib/game.js:969-981

   attackWorldBoss() derives the attack from CONTENT.items[equipped.left]. It only falls back to damage:1/reach:1 when the item is absent (weapon === null). If the left slot ever holds a non-weapon item present in CONTENT.items (no atk/reach fields), damage/reach become undefined and are passed into field.attackBoss(), which can yield NaN damage. Guard the per-field fallback (e.g. `damage: weapon && weapon.atk ? weapon.atk : 1`) rather than relying solely on the item being missing.

   Fix (Fall back to defaults per-field when the equipped item lacks atk/reach.):
   const weapon = CONTENT.items[equipped.left] || null
   const attack = {
     damage: weapon && Number.isFinite(weapon.atk) ? weapon.atk : 1,
     reach: weapon && Number.isFinite(weapon.reach) ? weapon.reach : 1
   }

3. 🚨 Bug: PR no longer fixes issue #8; NPC range mismatch persists untested
   Files: test/index.js:1209

   The PR's stated purpose is to unify the NPC interaction distance, but at HEAD `nearbyNpc` still defaults to `range = 1` (line 465), `enter()` still calls `this.nearbyNpc()` with the default range 1 (line 1168), while `view()` advertises `e hablar` using `this.nearbyNpc(2)` (line 1576). So pressing `e` from 2 tiles away still fails with "aca no hay nada" — the exact bug #8 describes remains unfixed. This delta commit ("resolve conflict with upstream main") also deleted the only regression test that exercised this behavior, so nothing now guards against the mismatch. Restore the fix (make `enter()` use range 2, e.g. change line 465 to `nearbyNpc(range = 2)` or pass `this.nearbyNpc(2)` at line 1168) and re-add the deleted `e interacts with npc at 2 tiles distance` test.

   Fix (Make the default range 2 so enter() (which calls nearbyNpc() with no argument) matches the range view() uses to advertise the prompt.):
   nearbyNpc(range = 2) {

4. 💡 Edge Case: Garden pond (solid water) overwrites carved access corridors
   Files: lib/map.js:918-932

   In `garden()` the '.' access paths are filled first (lines 925-926) but the pond is drawn afterward with solid `~` water (line 59 marks water solid) over the garden centre (line 934), overwriting the middle of both the horizontal and vertical corridors. The garden remains reachable only because the cobble (`;`, walkable) interior wraps around the pond, so the outer path openings still connect to the interior; if the pond size or corridor position ever changes this coupling could silently seal an approach. Consider re-carving the corridor segments after drawing the pond, or drawing the pond before the paths, to keep the access guarantee robust.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 7 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor Author

Rebased on latest main, resolved any conflicts, and ensured all tests and linting pass locally.

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.

el cartel ofrece 'e hablar' a dos celdas pero la tecla e no alcanza

2 participants