Drop pet deliveries to visible adjacent tiles and enrich pet:deliver payload#19
Drop pet deliveries to visible adjacent tiles and enrich pet:deliver payload#19
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Features/cc dungeon generator
…and-tests Add findNearestValidTileAround helper and use it for pet spawn/teleport; add tests
There was a problem hiding this comment.
Pull request overview
This PR changes pet item delivery so that items are placed onto an adjacent walkable tile (instead of the player’s tile) and expands the pet:deliver event payload to include delivery metadata for UI/logging.
Changes:
- Update
petFollowSystemto drop delivered items on the nearest valid adjacent tile (excluding the player tile) and skip delivery when no adjacent tile is available. - Enrich the
pet:deliverevent payload withdestination,mode: 'drop', andautoTransferred: false. - Add unit tests for crowded-adjacent-tile drops and the no-adjacent-space edge case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/rules/systems/petFollowSystem.js |
Chooses an adjacent drop tile via findNearestValidTileAround, places items via world.set/world.add, and emits richer pet:deliver payloads. |
src/main.js |
Updates pet:deliver logging to be delivery-mode aware (inventory vs default/drop). |
tests/petPlacement.test.mjs |
Adds tests validating adjacent-tile drops + enriched payload and skipped delivery when fully surrounded. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| petFollowSystem(world); | ||
|
|
||
| assert(!world.has(itemId, Position)); | ||
| assertEquals(world.get(petId, Inventory).items, [itemId]); |
There was a problem hiding this comment.
This test covers the skipped-delivery behavior via inventory/Position assertions, but it doesn’t assert that no pet:deliver event is emitted when no adjacent tile exists. Since the PR also changes the event contract, consider registering a listener here and asserting the event count remains 0 to prevent regressions where an event is fired despite the item staying in the pet inventory.
| petFollowSystem(world); | |
| assert(!world.has(itemId, Position)); | |
| assertEquals(world.get(petId, Inventory).items, [itemId]); | |
| const petDeliverEvents = []; | |
| if (typeof world.on === "function") { | |
| world.on("pet:deliver", (event) => { | |
| petDeliverEvents.push(event); | |
| }); | |
| } | |
| petFollowSystem(world); | |
| assert(!world.has(itemId, Position)); | |
| assertEquals(world.get(petId, Inventory).items, [itemId]); | |
| assertEquals(petDeliverEvents.length, 0); |
| }); | ||
| // Pet deliver: log when the pet drops an item at the player's feet | ||
| world.on('pet:deliver', ({ petId, actor, itemId, itemName, count }) => { | ||
| // Pet deliver: log when the pet drops an item beside the player. |
There was a problem hiding this comment.
The comment says this handler logs when the pet “drops” an item, but the updated logic also handles mode === 'inventory' ("gives you"). Update the comment to reflect that pet:deliver can represent multiple delivery modes so it stays accurate as the payload evolves.
| // Pet deliver: log when the pet drops an item beside the player. | |
| // Pet deliver: log when the pet delivers an item (into your inventory or onto the ground next to you). |
| try { | ||
| world.emit?.('pet:deliver', { | ||
| petId: id, | ||
| actor: playerId, | ||
| itemId, |
There was a problem hiding this comment.
pet:deliver is emitted while the item is still present in petInv.items (the inventory is only cleared after the loop). Event consumers that inspect the pet inventory may see inconsistent state and treat the item as not yet delivered. Consider copying + clearing the inventory before emitting, or removing each delivered itemId from petInv.items prior to world.emit so the event represents a completed transfer.
Motivation
pet:deliverevent so UI and other systems can distinguish drop vs inventory transfers and know the delivered destination.Description
petFollowSystemto place delivered items on the best free adjacent tile found byfindNearestValidTileAroundand skip delivery if no adjacent tile is available, instead leaving the item in the pet's inventory.Position(usingworld.set/world.add) and emits a richerpet:deliverpayload includingdestination,mode: 'drop', andautoTransferred: false.world.on('pet:deliver', ...)handler insrc/main.jsto log mode-aware messages ("gives you"for inventory mode and"drops ... next to you"for drop mode).tests/petPlacement.test.mjscovering crowded-tile delivery (ensures item lands on the only free adjacent tile and event payload is enriched) and the edge case where no adjacent tile exists (ensures delivery is skipped and item remains in pet inventory).Testing
tests/petPlacement.test.mjsfor crowded-tile delivery and no-adjacent-space behavior were created and committed.deno test --no-check --allow-read tests/petPlacement.test.mjsbut the run failed in this environment becausedenois not installed (bash: command not found: deno).Codex Task