Skip to content

Drop pet deliveries to visible adjacent tiles and enrich pet:deliver payload#19

Open
PJensen wants to merge 56 commits intomasterfrom
features/refactor-pet-delivery-system-functionality
Open

Drop pet deliveries to visible adjacent tiles and enrich pet:deliver payload#19
PJensen wants to merge 56 commits intomasterfrom
features/refactor-pet-delivery-system-functionality

Conversation

@PJensen
Copy link
Owner

@PJensen PJensen commented Feb 13, 2026

Motivation

  • Ensure pet-delivered items remain visible on the ground rather than being placed on the player's tile so the player can see dropped loot.
  • Provide a richer pet:deliver event so UI and other systems can distinguish drop vs inventory transfers and know the delivered destination.

Description

  • Updated petFollowSystem to place delivered items on the best free adjacent tile found by findNearestValidTileAround and skip delivery if no adjacent tile is available, instead leaving the item in the pet's inventory.
  • Delivery now sets the item's Position (using world.set/world.add) and emits a richer pet:deliver payload including destination, mode: 'drop', and autoTransferred: false.
  • Updated the world.on('pet:deliver', ...) handler in src/main.js to log mode-aware messages ("gives you" for inventory mode and "drops ... next to you" for drop mode).
  • Added tests in tests/petPlacement.test.mjs covering 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

  • Added unit tests: new cases in tests/petPlacement.test.mjs for crowded-tile delivery and no-adjacent-space behavior were created and committed.
  • Attempted to run deno test --no-check --allow-read tests/petPlacement.test.mjs but the run failed in this environment because deno is not installed (bash: command not found: deno).
  • No runtime failures were observed while applying and reviewing the diffs locally in the repository files.

Codex Task

Copilot AI review requested due to automatic review settings February 13, 2026 01:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 petFollowSystem to 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:deliver event payload with destination, mode: 'drop', and autoTransferred: 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.

Comment on lines +138 to +142

petFollowSystem(world);

assert(!world.has(itemId, Position));
assertEquals(world.get(petId, Inventory).items, [itemId]);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
});
// 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.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// 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).

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +56
try {
world.emit?.('pet:deliver', {
petId: id,
actor: playerId,
itemId,
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants