BlueGit

timfa questward

Require adjacent tiles for block and NPC interactions.

Standing on a gather node, station, or similar tile no longer starts the action; the client paths to a neighbouring tile first. Item pickup still requires standing on the ground item.

timfa Tim Falken · pushed by timfa

Authored 2026-09-01 · 2 months ago

Hash
69b7bf1ba2bd8d1ada5583eedd6f6b43051eada1
Parent
2f957a2a
16 files changed +224 −88
client/src/play/main.js +30 −29
@@ -3,6 +3,7 @@ import { COMBAT_RANGE_TILES } from "/shared/spells/constants.js";
3 3 import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock } from "/shared/definitions/tiles.js";
4 4 import { OVERWORLD_ID } from "/shared/world/dimensions.js";
5 5 import { findPathToNearestGoal } from "/shared/navigation/bfs.js";
6 import { isAdjacentTile } from "/shared/navigation/adjacency.js";
6 7 import { GameSocket, defaultSocketUrl } from "../net/socket.js";
7 8 import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";
8 9 import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour, playImagesFromCatalog } from "../render/sprites.js";
@@ -360,7 +361,7 @@ function clearAllPendingActions ()
360 361 function approachAdjacentTile (tileX, tileY)
361 362 {
362 363 const local = view.entities.get(view.localEntityId);
363 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
364 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
364 365 {
365 366 approachMove = null;
366 367 return true;
@@ -430,7 +431,7 @@ function requestOpenBank (tileX, tileY, { getCheques = false } = {})
430 431 clearAllPendingActions();
431 432 pendingInteract = { kind: "bank", tileX, tileY, getCheques: !!getCheques };
432 433 const local = view?.entities.get(view.localEntityId);
433 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
434 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
434 435 { flushPendingInteract(); }
435 436 else
436 437 { approachAdjacentTile(tileX, tileY); }
@@ -441,7 +442,7 @@ function requestEnterDoorway (tileX, tileY)
441 442 clearAllPendingActions();
442 443 pendingInteract = { kind: "doorway", tileX, tileY };
443 444 const local = view?.entities.get(view.localEntityId);
444 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
445 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
445 446 { flushPendingInteract(); }
446 447 else
447 448 { approachAdjacentTile(tileX, tileY); }
@@ -452,7 +453,7 @@ function requestOpenMarket (tileX, tileY)
452 453 clearAllPendingActions();
453 454 pendingInteract = { kind: "market", tileX, tileY };
454 455 const local = view?.entities.get(view.localEntityId);
455 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
456 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
456 457 { flushPendingInteract(); }
457 458 else
458 459 { approachAdjacentTile(tileX, tileY); }
@@ -463,7 +464,7 @@ function requestOpenBounty (tileX, tileY)
463 464 clearAllPendingActions();
464 465 pendingInteract = { kind: "bounty", tileX, tileY };
465 466 const local = view?.entities.get(view.localEntityId);
466 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
467 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
467 468 { flushPendingInteract(); }
468 469 else
469 470 { approachAdjacentTile(tileX, tileY); }
@@ -474,7 +475,7 @@ function requestOpenBarber (tileX, tileY)
474 475 clearAllPendingActions();
475 476 pendingInteract = { kind: "barber", tileX, tileY };
476 477 const local = view?.entities.get(view.localEntityId);
477 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
478 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
478 479 { flushPendingInteract(); }
479 480 else
480 481 { approachAdjacentTile(tileX, tileY); }
@@ -485,7 +486,7 @@ function requestOpenCauldron (tileX, tileY)
485 486 clearAllPendingActions();
486 487 pendingInteract = { kind: "cauldron", tileX, tileY };
487 488 const local = view?.entities.get(view.localEntityId);
488 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
489 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
489 490 { flushPendingInteract(); }
490 491 else
491 492 { approachAdjacentTile(tileX, tileY); }
@@ -501,7 +502,7 @@ function requestOpenCraftStation (stationId, tileX, tileY)
501 502 clearAllPendingActions();
502 503 pendingInteract = { kind: "station", stationId, tileX, tileY };
503 504 const local = view?.entities.get(view.localEntityId);
504 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
505 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
505 506 { flushPendingInteract(); }
506 507 else
507 508 { approachAdjacentTile(tileX, tileY); }
@@ -519,7 +520,7 @@ function requestStartFire (ground)
519 520 tileY: ground.tileY
520 521 };
521 522 const local = view?.entities.get(view.localEntityId);
522 if (local && chebyshev(local.tileX, local.tileY, ground.tileX, ground.tileY) <= 1)
523 if (local && isAdjacentTile(local.tileX, local.tileY, ground.tileX, ground.tileY))
523 524 { flushPendingInteract(); }
524 525 else
525 526 { approachAdjacentTile(ground.tileX, ground.tileY); }
@@ -530,7 +531,7 @@ function requestFish (tileX, tileY)
530 531 clearAllPendingActions();
531 532 pendingInteract = { kind: "fish", tileX, tileY };
532 533 const local = view?.entities.get(view.localEntityId);
533 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
534 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
534 535 { flushPendingInteract(); }
535 536 else
536 537 { approachAdjacentTile(tileX, tileY); }
@@ -541,7 +542,7 @@ function requestMine (tileX, tileY)
541 542 clearAllPendingActions();
542 543 pendingInteract = { kind: "mine", tileX, tileY };
543 544 const local = view?.entities.get(view.localEntityId);
544 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
545 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
545 546 { flushPendingInteract(); }
546 547 else
547 548 { approachAdjacentTile(tileX, tileY); }
@@ -552,7 +553,7 @@ function requestChop (tileX, tileY)
552 553 clearAllPendingActions();
553 554 pendingInteract = { kind: "chop", tileX, tileY };
554 555 const local = view?.entities.get(view.localEntityId);
555 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
556 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
556 557 { flushPendingInteract(); }
557 558 else
558 559 { approachAdjacentTile(tileX, tileY); }
@@ -563,7 +564,7 @@ function requestPick (tileX, tileY)
563 564 clearAllPendingActions();
564 565 pendingInteract = { kind: "pick", tileX, tileY };
565 566 const local = view?.entities.get(view.localEntityId);
566 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
567 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
567 568 { flushPendingInteract(); }
568 569 else
569 570 { approachAdjacentTile(tileX, tileY); }
@@ -677,11 +678,11 @@ function closeOpenUiIfTooFar ()
677 678 {
678 679 const target = view.entities.get(uiFocus.entityId);
679 680 tooFar = !target
680 || chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1;
681 || !isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY);
681 682 }
682 683 else if (uiFocus.tileX != null && uiFocus.tileY != null)
683 684 {
684 tooFar = chebyshev(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY) > 1;
685 tooFar = !isAdjacentTile(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY);
685 686 }
686 687 if (!tooFar)
687 688 { return; }
@@ -737,7 +738,7 @@ function flushPendingInteract ()
737 738
738 739 if (pendingInteract.kind === "bank")
739 740 {
740 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
741 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
741 742 { return; }
742 743 setUiFocus({
743 744 kind: "bank",
@@ -754,7 +755,7 @@ function flushPendingInteract ()
754 755
755 756 if (pendingInteract.kind === "doorway")
756 757 {
757 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
758 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
758 759 { return; }
759 760 socket.send({
760 761 type: MessageType.enterDoorway,
@@ -767,7 +768,7 @@ function flushPendingInteract ()
767 768
768 769 if (pendingInteract.kind === "market")
769 770 {
770 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
771 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
771 772 { return; }
772 773 setUiFocus({
773 774 kind: "market",
@@ -781,7 +782,7 @@ function flushPendingInteract ()
781 782
782 783 if (pendingInteract.kind === "bounty")
783 784 {
784 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
785 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
785 786 { return; }
786 787 setUiFocus({
787 788 kind: "bounty",
@@ -795,7 +796,7 @@ function flushPendingInteract ()
795 796
796 797 if (pendingInteract.kind === "barber")
797 798 {
798 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
799 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
799 800 { return; }
800 801 setUiFocus({
801 802 kind: "barber",
@@ -809,7 +810,7 @@ function flushPendingInteract ()
809 810
810 811 if (pendingInteract.kind === "cauldron")
811 812 {
812 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
813 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
813 814 { return; }
814 815 setUiFocus({
815 816 kind: "cauldron",
@@ -823,7 +824,7 @@ function flushPendingInteract ()
823 824
824 825 if (pendingInteract.kind === "station")
825 826 {
826 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
827 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
827 828 { return; }
828 829 setUiFocus({
829 830 kind: "station",
@@ -840,7 +841,7 @@ function flushPendingInteract ()
840 841
841 842 if (pendingInteract.kind === "mine")
842 843 {
843 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
844 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
844 845 { return; }
845 846 socket.send({
846 847 type: MessageType.mine,
@@ -853,7 +854,7 @@ function flushPendingInteract ()
853 854
854 855 if (pendingInteract.kind === "start-fire")
855 856 {
856 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
857 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
857 858 { return; }
858 859 socket.send({
859 860 type: MessageType.startFire,
@@ -865,7 +866,7 @@ function flushPendingInteract ()
865 866
866 867 if (pendingInteract.kind === "fish")
867 868 {
868 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
869 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
869 870 { return; }
870 871 socket.send({
871 872 type: MessageType.startFish,
@@ -878,7 +879,7 @@ function flushPendingInteract ()
878 879
879 880 if (pendingInteract.kind === "chop")
880 881 {
881 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
882 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
882 883 { return; }
883 884 socket.send({
884 885 type: MessageType.chop,
@@ -891,7 +892,7 @@ function flushPendingInteract ()
891 892
892 893 if (pendingInteract.kind === "pick")
893 894 {
894 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
895 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
895 896 { return; }
896 897 socket.send({
897 898 type: MessageType.pick,
@@ -910,7 +911,7 @@ function flushPendingInteract ()
910 911 clearPendingInteract();
911 912 return;
912 913 }
913 if (chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1)
914 if (!isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY))
914 915 {
915 916 // Target may have moved — keep chasing.
916 917 approachAdjacentTile(target.tileX, target.tileY);
@@ -938,7 +939,7 @@ function flushPendingInteract ()
938 939 clearPendingInteract();
939 940 return;
940 941 }
941 if (chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1)
942 if (!isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY))
942 943 {
943 944 approachAdjacentTile(target.tileX, target.tileY);
944 945 return;
@@ -3,6 +3,7 @@ import { COMBAT_RANGE_TILES } from "/shared/spells/constants.js";
3import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock } from "/shared/definitions/tiles.js";
3import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock } from "/shared/definitions/tiles.js";
4import { OVERWORLD_ID } from "/shared/world/dimensions.js";
4import { OVERWORLD_ID } from "/shared/world/dimensions.js";
5import { findPathToNearestGoal } from "/shared/navigation/bfs.js";
5import { findPathToNearestGoal } from "/shared/navigation/bfs.js";
6import { isAdjacentTile } from "/shared/navigation/adjacency.js";
6import { GameSocket, defaultSocketUrl } from "../net/socket.js";
7import { GameSocket, defaultSocketUrl } from "../net/socket.js";
7import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";
8import { fetchAuthStatus, formatAccountLabel, loginUrl, logoutUrl } from "../net/auth.js";
8import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour, playImagesFromCatalog } from "../render/sprites.js";
9import { loadSpriteCatalog, preloadCatalogImages, applySpriteSheets, useNearestNeighbour, playImagesFromCatalog } from "../render/sprites.js";
@@ -360,7 +361,7 @@ function clearAllPendingActions ()
360function approachAdjacentTile (tileX, tileY)
361function approachAdjacentTile (tileX, tileY)
361{
362{
362 const local = view.entities.get(view.localEntityId);
363 const local = view.entities.get(view.localEntityId);
363 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
364 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
364 {
365 {
365 approachMove = null;
366 approachMove = null;
366 return true;
367 return true;
@@ -430,7 +431,7 @@ function requestOpenBank (tileX, tileY, { getCheques = false } = {})
430 clearAllPendingActions();
431 clearAllPendingActions();
431 pendingInteract = { kind: "bank", tileX, tileY, getCheques: !!getCheques };
432 pendingInteract = { kind: "bank", tileX, tileY, getCheques: !!getCheques };
432 const local = view?.entities.get(view.localEntityId);
433 const local = view?.entities.get(view.localEntityId);
433 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
434 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
434 { flushPendingInteract(); }
435 { flushPendingInteract(); }
435 else
436 else
436 { approachAdjacentTile(tileX, tileY); }
437 { approachAdjacentTile(tileX, tileY); }
@@ -441,7 +442,7 @@ function requestEnterDoorway (tileX, tileY)
441 clearAllPendingActions();
442 clearAllPendingActions();
442 pendingInteract = { kind: "doorway", tileX, tileY };
443 pendingInteract = { kind: "doorway", tileX, tileY };
443 const local = view?.entities.get(view.localEntityId);
444 const local = view?.entities.get(view.localEntityId);
444 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
445 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
445 { flushPendingInteract(); }
446 { flushPendingInteract(); }
446 else
447 else
447 { approachAdjacentTile(tileX, tileY); }
448 { approachAdjacentTile(tileX, tileY); }
@@ -452,7 +453,7 @@ function requestOpenMarket (tileX, tileY)
452 clearAllPendingActions();
453 clearAllPendingActions();
453 pendingInteract = { kind: "market", tileX, tileY };
454 pendingInteract = { kind: "market", tileX, tileY };
454 const local = view?.entities.get(view.localEntityId);
455 const local = view?.entities.get(view.localEntityId);
455 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
456 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
456 { flushPendingInteract(); }
457 { flushPendingInteract(); }
457 else
458 else
458 { approachAdjacentTile(tileX, tileY); }
459 { approachAdjacentTile(tileX, tileY); }
@@ -463,7 +464,7 @@ function requestOpenBounty (tileX, tileY)
463 clearAllPendingActions();
464 clearAllPendingActions();
464 pendingInteract = { kind: "bounty", tileX, tileY };
465 pendingInteract = { kind: "bounty", tileX, tileY };
465 const local = view?.entities.get(view.localEntityId);
466 const local = view?.entities.get(view.localEntityId);
466 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
467 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
467 { flushPendingInteract(); }
468 { flushPendingInteract(); }
468 else
469 else
469 { approachAdjacentTile(tileX, tileY); }
470 { approachAdjacentTile(tileX, tileY); }
@@ -474,7 +475,7 @@ function requestOpenBarber (tileX, tileY)
474 clearAllPendingActions();
475 clearAllPendingActions();
475 pendingInteract = { kind: "barber", tileX, tileY };
476 pendingInteract = { kind: "barber", tileX, tileY };
476 const local = view?.entities.get(view.localEntityId);
477 const local = view?.entities.get(view.localEntityId);
477 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
478 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
478 { flushPendingInteract(); }
479 { flushPendingInteract(); }
479 else
480 else
480 { approachAdjacentTile(tileX, tileY); }
481 { approachAdjacentTile(tileX, tileY); }
@@ -485,7 +486,7 @@ function requestOpenCauldron (tileX, tileY)
485 clearAllPendingActions();
486 clearAllPendingActions();
486 pendingInteract = { kind: "cauldron", tileX, tileY };
487 pendingInteract = { kind: "cauldron", tileX, tileY };
487 const local = view?.entities.get(view.localEntityId);
488 const local = view?.entities.get(view.localEntityId);
488 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
489 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
489 { flushPendingInteract(); }
490 { flushPendingInteract(); }
490 else
491 else
491 { approachAdjacentTile(tileX, tileY); }
492 { approachAdjacentTile(tileX, tileY); }
@@ -501,7 +502,7 @@ function requestOpenCraftStation (stationId, tileX, tileY)
501 clearAllPendingActions();
502 clearAllPendingActions();
502 pendingInteract = { kind: "station", stationId, tileX, tileY };
503 pendingInteract = { kind: "station", stationId, tileX, tileY };
503 const local = view?.entities.get(view.localEntityId);
504 const local = view?.entities.get(view.localEntityId);
504 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
505 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
505 { flushPendingInteract(); }
506 { flushPendingInteract(); }
506 else
507 else
507 { approachAdjacentTile(tileX, tileY); }
508 { approachAdjacentTile(tileX, tileY); }
@@ -519,7 +520,7 @@ function requestStartFire (ground)
519 tileY: ground.tileY
520 tileY: ground.tileY
520 };
521 };
521 const local = view?.entities.get(view.localEntityId);
522 const local = view?.entities.get(view.localEntityId);
522 if (local && chebyshev(local.tileX, local.tileY, ground.tileX, ground.tileY) <= 1)
523 if (local && isAdjacentTile(local.tileX, local.tileY, ground.tileX, ground.tileY))
523 { flushPendingInteract(); }
524 { flushPendingInteract(); }
524 else
525 else
525 { approachAdjacentTile(ground.tileX, ground.tileY); }
526 { approachAdjacentTile(ground.tileX, ground.tileY); }
@@ -530,7 +531,7 @@ function requestFish (tileX, tileY)
530 clearAllPendingActions();
531 clearAllPendingActions();
531 pendingInteract = { kind: "fish", tileX, tileY };
532 pendingInteract = { kind: "fish", tileX, tileY };
532 const local = view?.entities.get(view.localEntityId);
533 const local = view?.entities.get(view.localEntityId);
533 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
534 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
534 { flushPendingInteract(); }
535 { flushPendingInteract(); }
535 else
536 else
536 { approachAdjacentTile(tileX, tileY); }
537 { approachAdjacentTile(tileX, tileY); }
@@ -541,7 +542,7 @@ function requestMine (tileX, tileY)
541 clearAllPendingActions();
542 clearAllPendingActions();
542 pendingInteract = { kind: "mine", tileX, tileY };
543 pendingInteract = { kind: "mine", tileX, tileY };
543 const local = view?.entities.get(view.localEntityId);
544 const local = view?.entities.get(view.localEntityId);
544 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
545 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
545 { flushPendingInteract(); }
546 { flushPendingInteract(); }
546 else
547 else
547 { approachAdjacentTile(tileX, tileY); }
548 { approachAdjacentTile(tileX, tileY); }
@@ -552,7 +553,7 @@ function requestChop (tileX, tileY)
552 clearAllPendingActions();
553 clearAllPendingActions();
553 pendingInteract = { kind: "chop", tileX, tileY };
554 pendingInteract = { kind: "chop", tileX, tileY };
554 const local = view?.entities.get(view.localEntityId);
555 const local = view?.entities.get(view.localEntityId);
555 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
556 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
556 { flushPendingInteract(); }
557 { flushPendingInteract(); }
557 else
558 else
558 { approachAdjacentTile(tileX, tileY); }
559 { approachAdjacentTile(tileX, tileY); }
@@ -563,7 +564,7 @@ function requestPick (tileX, tileY)
563 clearAllPendingActions();
564 clearAllPendingActions();
564 pendingInteract = { kind: "pick", tileX, tileY };
565 pendingInteract = { kind: "pick", tileX, tileY };
565 const local = view?.entities.get(view.localEntityId);
566 const local = view?.entities.get(view.localEntityId);
566 if (local && chebyshev(local.tileX, local.tileY, tileX, tileY) <= 1)
567 if (local && isAdjacentTile(local.tileX, local.tileY, tileX, tileY))
567 { flushPendingInteract(); }
568 { flushPendingInteract(); }
568 else
569 else
569 { approachAdjacentTile(tileX, tileY); }
570 { approachAdjacentTile(tileX, tileY); }
@@ -677,11 +678,11 @@ function closeOpenUiIfTooFar ()
677 {
678 {
678 const target = view.entities.get(uiFocus.entityId);
679 const target = view.entities.get(uiFocus.entityId);
679 tooFar = !target
680 tooFar = !target
680 || chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1;
681 || !isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY);
681 }
682 }
682 else if (uiFocus.tileX != null && uiFocus.tileY != null)
683 else if (uiFocus.tileX != null && uiFocus.tileY != null)
683 {
684 {
684 tooFar = chebyshev(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY) > 1;
685 tooFar = !isAdjacentTile(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY);
685 }
686 }
686 if (!tooFar)
687 if (!tooFar)
687 { return; }
688 { return; }
@@ -737,7 +738,7 @@ function flushPendingInteract ()
737
738
738 if (pendingInteract.kind === "bank")
739 if (pendingInteract.kind === "bank")
739 {
740 {
740 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
741 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
741 { return; }
742 { return; }
742 setUiFocus({
743 setUiFocus({
743 kind: "bank",
744 kind: "bank",
@@ -754,7 +755,7 @@ function flushPendingInteract ()
754
755
755 if (pendingInteract.kind === "doorway")
756 if (pendingInteract.kind === "doorway")
756 {
757 {
757 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
758 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
758 { return; }
759 { return; }
759 socket.send({
760 socket.send({
760 type: MessageType.enterDoorway,
761 type: MessageType.enterDoorway,
@@ -767,7 +768,7 @@ function flushPendingInteract ()
767
768
768 if (pendingInteract.kind === "market")
769 if (pendingInteract.kind === "market")
769 {
770 {
770 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
771 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
771 { return; }
772 { return; }
772 setUiFocus({
773 setUiFocus({
773 kind: "market",
774 kind: "market",
@@ -781,7 +782,7 @@ function flushPendingInteract ()
781
782
782 if (pendingInteract.kind === "bounty")
783 if (pendingInteract.kind === "bounty")
783 {
784 {
784 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
785 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
785 { return; }
786 { return; }
786 setUiFocus({
787 setUiFocus({
787 kind: "bounty",
788 kind: "bounty",
@@ -795,7 +796,7 @@ function flushPendingInteract ()
795
796
796 if (pendingInteract.kind === "barber")
797 if (pendingInteract.kind === "barber")
797 {
798 {
798 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
799 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
799 { return; }
800 { return; }
800 setUiFocus({
801 setUiFocus({
801 kind: "barber",
802 kind: "barber",
@@ -809,7 +810,7 @@ function flushPendingInteract ()
809
810
810 if (pendingInteract.kind === "cauldron")
811 if (pendingInteract.kind === "cauldron")
811 {
812 {
812 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
813 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
813 { return; }
814 { return; }
814 setUiFocus({
815 setUiFocus({
815 kind: "cauldron",
816 kind: "cauldron",
@@ -823,7 +824,7 @@ function flushPendingInteract ()
823
824
824 if (pendingInteract.kind === "station")
825 if (pendingInteract.kind === "station")
825 {
826 {
826 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
827 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
827 { return; }
828 { return; }
828 setUiFocus({
829 setUiFocus({
829 kind: "station",
830 kind: "station",
@@ -840,7 +841,7 @@ function flushPendingInteract ()
840
841
841 if (pendingInteract.kind === "mine")
842 if (pendingInteract.kind === "mine")
842 {
843 {
843 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
844 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
844 { return; }
845 { return; }
845 socket.send({
846 socket.send({
846 type: MessageType.mine,
847 type: MessageType.mine,
@@ -853,7 +854,7 @@ function flushPendingInteract ()
853
854
854 if (pendingInteract.kind === "start-fire")
855 if (pendingInteract.kind === "start-fire")
855 {
856 {
856 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
857 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
857 { return; }
858 { return; }
858 socket.send({
859 socket.send({
859 type: MessageType.startFire,
860 type: MessageType.startFire,
@@ -865,7 +866,7 @@ function flushPendingInteract ()
865
866
866 if (pendingInteract.kind === "fish")
867 if (pendingInteract.kind === "fish")
867 {
868 {
868 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
869 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
869 { return; }
870 { return; }
870 socket.send({
871 socket.send({
871 type: MessageType.startFish,
872 type: MessageType.startFish,
@@ -878,7 +879,7 @@ function flushPendingInteract ()
878
879
879 if (pendingInteract.kind === "chop")
880 if (pendingInteract.kind === "chop")
880 {
881 {
881 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
882 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
882 { return; }
883 { return; }
883 socket.send({
884 socket.send({
884 type: MessageType.chop,
885 type: MessageType.chop,
@@ -891,7 +892,7 @@ function flushPendingInteract ()
891
892
892 if (pendingInteract.kind === "pick")
893 if (pendingInteract.kind === "pick")
893 {
894 {
894 if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
895 if (!isAdjacentTile(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY))
895 { return; }
896 { return; }
896 socket.send({
897 socket.send({
897 type: MessageType.pick,
898 type: MessageType.pick,
@@ -910,7 +911,7 @@ function flushPendingInteract ()
910 clearPendingInteract();
911 clearPendingInteract();
911 return;
912 return;
912 }
913 }
913 if (chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1)
914 if (!isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY))
914 {
915 {
915 // Target may have moved — keep chasing.
916 // Target may have moved — keep chasing.
916 approachAdjacentTile(target.tileX, target.tileY);
917 approachAdjacentTile(target.tileX, target.tileY);
@@ -938,7 +939,7 @@ function flushPendingInteract ()
938 clearPendingInteract();
939 clearPendingInteract();
939 return;
940 return;
940 }
941 }
941 if (chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1)
942 if (!isAdjacentTile(local.tileX, local.tileY, target.tileX, target.tileY))
942 {
943 {
943 approachAdjacentTile(target.tileX, target.tileY);
944 approachAdjacentTile(target.tileX, target.tileY);
944 return;
945 return;
server/src/alchemy/service.js +2 −0
@@ -110,6 +110,8 @@ function nearCauldron (world, tileX, tileY)
110 110 {
111 111 for (let dx = -1; dx <= 1; dx++)
112 112 {
113 if (dx === 0 && dy === 0)
114 { continue; }
113 115 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
114 116 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
115 117 if (data.blocks[index]?.typeId === BlockType.cauldron)
@@ -110,6 +110,8 @@ function nearCauldron (world, tileX, tileY)
110 {
110 {
111 for (let dx = -1; dx <= 1; dx++)
111 for (let dx = -1; dx <= 1; dx++)
112 {
112 {
113 if (dx === 0 && dy === 0)
114 { continue; }
113 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
115 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
114 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
116 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
115 if (data.blocks[index]?.typeId === BlockType.cauldron)
117 if (data.blocks[index]?.typeId === BlockType.cauldron)
server/src/barber/service.js +2 −0
@@ -114,6 +114,8 @@ function isAdjacentToBarber (simulation, tileX, tileY)
114 114 {
115 115 for (let dx = -1; dx <= 1; dx++)
116 116 {
117 if (dx === 0 && dy === 0)
118 { continue; }
117 119 if (blockTypeAt(simulation, tileX + dx, tileY + dy) === BlockType.barber)
118 120 { return true; }
119 121 }
@@ -114,6 +114,8 @@ function isAdjacentToBarber (simulation, tileX, tileY)
114 {
114 {
115 for (let dx = -1; dx <= 1; dx++)
115 for (let dx = -1; dx <= 1; dx++)
116 {
116 {
117 if (dx === 0 && dy === 0)
118 { continue; }
117 if (blockTypeAt(simulation, tileX + dx, tileY + dy) === BlockType.barber)
119 if (blockTypeAt(simulation, tileX + dx, tileY + dy) === BlockType.barber)
118 { return true; }
120 { return true; }
119 }
121 }
server/src/bounty/service.js +2 −5
@@ -18,10 +18,7 @@ function userError (message)
18 18 return error;
19 19 }
20 20
21 function chebyshev (ax, ay, bx, by)
22 {
23 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
24 }
21 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
25 22
26 23 /**
27 24 * Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.
@@ -295,7 +292,7 @@ export class BountyService
295 292 if (!tiles.length)
296 293 { throw userError("No Bounty Office exists in this world yet."); }
297 294 const near = tiles.some((tile) =>
298 chebyshev(position.tileX, position.tileY, tile.tileX, tile.tileY) <= 1);
295 isAdjacentTile(position.tileX, position.tileY, tile.tileX, tile.tileY));
299 296 if (!near)
300 297 { throw userError("Stand next to a Bounty Office."); }
301 298 return position;
@@ -18,10 +18,7 @@ function userError (message)
18 return error;
18 return error;
19}
19}
20
20
21function chebyshev (ax, ay, bx, by)
21import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
22{
23 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
24}
25
22
26/**
23/**
27 * Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.
24 * Bounty office: place/raise bounties (near office), settle PvP kills into killer vault + letter.
@@ -295,7 +292,7 @@ export class BountyService
295 if (!tiles.length)
292 if (!tiles.length)
296 { throw userError("No Bounty Office exists in this world yet."); }
293 { throw userError("No Bounty Office exists in this world yet."); }
297 const near = tiles.some((tile) =>
294 const near = tiles.some((tile) =>
298 chebyshev(position.tileX, position.tileY, tile.tileX, tile.tileY) <= 1);
295 isAdjacentTile(position.tileX, position.tileY, tile.tileX, tile.tileY));
299 if (!near)
296 if (!near)
300 { throw userError("Stand next to a Bounty Office."); }
297 { throw userError("Stand next to a Bounty Office."); }
301 return position;
298 return position;
server/src/crafting/service.js +20 −13
@@ -12,6 +12,8 @@ import
12 12 hasRecipeInputs
13 13 } from "../../../shared/crafting/recipes.js";
14 14 import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
15 import { pickEmptiestDyeSlot } from "../../../shared/crafting/dye.js";
16 import { dyeColorKey as dyeInstanceColorKey } from "../../../shared/definitions/dyes.js";
15 17 import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
16 18 import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
17 19 import
@@ -54,6 +56,8 @@ function nearStationBlock (world, tileX, tileY, blockType)
54 56 {
55 57 for (let dx = -1; dx <= 1; dx++)
56 58 {
59 if (dx === 0 && dy === 0)
60 { continue; }
57 61 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
58 62 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
59 63 if (data.blocks[index]?.typeId === blockType)
@@ -165,7 +169,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
165 169 const skills = world.ecs.get(handle, Component.skills);
166 170 const level = skillLevel(skills, stationDef.skillId ?? SkillId.smithing);
167 171
168 let dyeSlotIndex = null;
172 let dyeColorKey = null;
169 173 if (recipe.tailorTemplate)
170 174 {
171 175 if (stationId !== CraftingStationId.tailorBench)
@@ -175,7 +179,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
175 179 if (dyeIdx != null && dyeIdx >= 0)
176 180 {
177 181 dyeStack = inventory?.slots?.[dyeIdx | 0] ?? null;
178 dyeSlotIndex = dyeIdx | 0;
182 dyeColorKey = dyeStack ? dyeInstanceColorKey(dyeStack.instance) : null;
179 183 }
180 184 const resolved = resolveTailorCraft({
181 185 templateId: recipe.tailorTemplate,
@@ -189,26 +193,28 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
189 193 else if (options.dyeSlotIndex != null)
190 194 {
191 195 // Dye is tailor-only; ignore client-supplied dye on other stations.
192 dyeSlotIndex = null;
196 dyeColorKey = null;
193 197 }
194 198
195 if (!canStartCraft(inventory?.slots ?? [], recipe, level, { dyeSlotIndex }))
199 if (!canStartCraft(inventory?.slots ?? [], recipe, level, { dyeColorKey, dyeSlotIndex: options.dyeSlotIndex ?? null }))
196 200 {
197 201 if ((level | 0) < (recipe.minSkillLevel | 0 || 1))
198 202 { throw userError(`Requires ${stationDef.skillId} ${recipe.minSkillLevel}.`); }
199 203 if (!hasRecipeInputs(inventory?.slots ?? [], recipe))
200 204 { throw userError("Missing materials."); }
201 if (recipe.consumeDye && dyeSlotIndex != null)
205 if (recipe.consumeDye && dyeColorKey != null)
202 206 {
203 const dyeProbe = consumeDyeUse(inventory?.slots ?? [], dyeSlotIndex);
207 const probeSlot = pickEmptiestDyeSlot(inventory?.slots ?? [], dyeColorKey);
208 const dyeProbe = consumeDyeUse(inventory?.slots ?? [], probeSlot);
204 209 if (!dyeProbe.ok)
205 210 { throw userError("Need bag space to separate the partially used dye."); }
206 211 }
207 212 throw userError("Not enough bag space for the result.");
208 213 }
209 if (recipe.consumeDye && dyeSlotIndex != null)
214 if (recipe.consumeDye && dyeColorKey != null)
210 215 {
211 const dye = inventory?.slots?.[dyeSlotIndex];
216 const probeSlot = pickEmptiestDyeSlot(inventory?.slots ?? [], dyeColorKey);
217 const dye = inventory?.slots?.[probeSlot];
212 218 if (!dye || dye.itemId !== ItemId.dye)
213 219 { throw userError("Selected dye is missing."); }
214 220 }
@@ -230,7 +236,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
230 236 stationId,
231 237 recipeId,
232 238 recipe,
233 dyeSlotIndex,
239 dyeColorKey,
234 240 batchRemaining,
235 241 durationMs,
236 242 finishesAt: now + durationMs
@@ -345,7 +351,7 @@ export function stepCrafting (world, now)
345 351
346 352 if (!recipe || !stationDef || !inventory
347 353 || (blockType && !nearStationBlock(world, position.tileX, position.tileY, blockType))
348 || !canCraftFitInventory(inventory.slots, recipe, { dyeSlotIndex: session.dyeSlotIndex })
354 || !canCraftFitInventory(inventory.slots, recipe, { dyeColorKey: session.dyeColorKey })
349 355 || (level | 0) < (recipe.minSkillLevel | 0 || 1))
350 356 {
351 357 events.push({
@@ -371,9 +377,10 @@ export function stepCrafting (world, now)
371 377 continue;
372 378 }
373 379 let slotsAfter = taken.slots;
374 if (recipe.consumeDye && session.dyeSlotIndex != null)
380 if (recipe.consumeDye && session.dyeColorKey != null)
375 381 {
376 const dyeTaken = consumeDyeUse(slotsAfter, session.dyeSlotIndex);
382 const consumeSlot = pickEmptiestDyeSlot(slotsAfter, session.dyeColorKey);
383 const dyeTaken = consumeDyeUse(slotsAfter, consumeSlot);
377 384 if (!dyeTaken.ok)
378 385 {
379 386 events.push({
@@ -467,7 +474,7 @@ export function stepCrafting (world, now)
467 474 inventory.slots,
468 475 recipe,
469 476 level,
470 { dyeSlotIndex: session.dyeSlotIndex }
477 { dyeColorKey: session.dyeColorKey, dyeSlotIndex: null }
471 478 ))
472 479 {
473 480 const durationMs = session.durationMs ?? craftDurationMs(recipe, CRAFT_DURATION_MS);
@@ -12,6 +12,8 @@ import
12 hasRecipeInputs
12 hasRecipeInputs
13} from "../../../shared/crafting/recipes.js";
13} from "../../../shared/crafting/recipes.js";
14import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
14import { resolveTailorCraft } from "../../../shared/crafting/tailor.js";
15import { pickEmptiestDyeSlot } from "../../../shared/crafting/dye.js";
16import { dyeColorKey as dyeInstanceColorKey } from "../../../shared/definitions/dyes.js";
15import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
17import { craftDurationMs, craftXpForConsumedInputs } from "../../../shared/definitions/gathering.js";
16import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
18import { takeFromSlot, insertStack, stackQuantity, consumeFillCharge } from "../../../shared/items/inventory.js";
17import
19import
@@ -54,6 +56,8 @@ function nearStationBlock (world, tileX, tileY, blockType)
54 {
56 {
55 for (let dx = -1; dx <= 1; dx++)
57 for (let dx = -1; dx <= 1; dx++)
56 {
58 {
59 if (dx === 0 && dy === 0)
60 { continue; }
57 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
61 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
58 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
62 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
59 if (data.blocks[index]?.typeId === blockType)
63 if (data.blocks[index]?.typeId === blockType)
@@ -165,7 +169,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
165 const skills = world.ecs.get(handle, Component.skills);
169 const skills = world.ecs.get(handle, Component.skills);
166 const level = skillLevel(skills, stationDef.skillId ?? SkillId.smithing);
170 const level = skillLevel(skills, stationDef.skillId ?? SkillId.smithing);
167
171
168 let dyeSlotIndex = null;
172 let dyeColorKey = null;
169 if (recipe.tailorTemplate)
173 if (recipe.tailorTemplate)
170 {
174 {
171 if (stationId !== CraftingStationId.tailorBench)
175 if (stationId !== CraftingStationId.tailorBench)
@@ -175,7 +179,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
175 if (dyeIdx != null && dyeIdx >= 0)
179 if (dyeIdx != null && dyeIdx >= 0)
176 {
180 {
177 dyeStack = inventory?.slots?.[dyeIdx | 0] ?? null;
181 dyeStack = inventory?.slots?.[dyeIdx | 0] ?? null;
178 dyeSlotIndex = dyeIdx | 0;
182 dyeColorKey = dyeStack ? dyeInstanceColorKey(dyeStack.instance) : null;
179 }
183 }
180 const resolved = resolveTailorCraft({
184 const resolved = resolveTailorCraft({
181 templateId: recipe.tailorTemplate,
185 templateId: recipe.tailorTemplate,
@@ -189,26 +193,28 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
189 else if (options.dyeSlotIndex != null)
193 else if (options.dyeSlotIndex != null)
190 {
194 {
191 // Dye is tailor-only; ignore client-supplied dye on other stations.
195 // Dye is tailor-only; ignore client-supplied dye on other stations.
192 dyeSlotIndex = null;
196 dyeColorKey = null;
193 }
197 }
194
198
195 if (!canStartCraft(inventory?.slots ?? [], recipe, level, { dyeSlotIndex }))
199 if (!canStartCraft(inventory?.slots ?? [], recipe, level, { dyeColorKey, dyeSlotIndex: options.dyeSlotIndex ?? null }))
196 {
200 {
197 if ((level | 0) < (recipe.minSkillLevel | 0 || 1))
201 if ((level | 0) < (recipe.minSkillLevel | 0 || 1))
198 { throw userError(`Requires ${stationDef.skillId} ${recipe.minSkillLevel}.`); }
202 { throw userError(`Requires ${stationDef.skillId} ${recipe.minSkillLevel}.`); }
199 if (!hasRecipeInputs(inventory?.slots ?? [], recipe))
203 if (!hasRecipeInputs(inventory?.slots ?? [], recipe))
200 { throw userError("Missing materials."); }
204 { throw userError("Missing materials."); }
201 if (recipe.consumeDye && dyeSlotIndex != null)
205 if (recipe.consumeDye && dyeColorKey != null)
202 {
206 {
203 const dyeProbe = consumeDyeUse(inventory?.slots ?? [], dyeSlotIndex);
207 const probeSlot = pickEmptiestDyeSlot(inventory?.slots ?? [], dyeColorKey);
208 const dyeProbe = consumeDyeUse(inventory?.slots ?? [], probeSlot);
204 if (!dyeProbe.ok)
209 if (!dyeProbe.ok)
205 { throw userError("Need bag space to separate the partially used dye."); }
210 { throw userError("Need bag space to separate the partially used dye."); }
206 }
211 }
207 throw userError("Not enough bag space for the result.");
212 throw userError("Not enough bag space for the result.");
208 }
213 }
209 if (recipe.consumeDye && dyeSlotIndex != null)
214 if (recipe.consumeDye && dyeColorKey != null)
210 {
215 {
211 const dye = inventory?.slots?.[dyeSlotIndex];
216 const probeSlot = pickEmptiestDyeSlot(inventory?.slots ?? [], dyeColorKey);
217 const dye = inventory?.slots?.[probeSlot];
212 if (!dye || dye.itemId !== ItemId.dye)
218 if (!dye || dye.itemId !== ItemId.dye)
213 { throw userError("Selected dye is missing."); }
219 { throw userError("Selected dye is missing."); }
214 }
220 }
@@ -230,7 +236,7 @@ export function startCraft (world, sessionId, characterId, stationId, recipeId,
230 stationId,
236 stationId,
231 recipeId,
237 recipeId,
232 recipe,
238 recipe,
233 dyeSlotIndex,
239 dyeColorKey,
234 batchRemaining,
240 batchRemaining,
235 durationMs,
241 durationMs,
236 finishesAt: now + durationMs
242 finishesAt: now + durationMs
@@ -345,7 +351,7 @@ export function stepCrafting (world, now)
345
351
346 if (!recipe || !stationDef || !inventory
352 if (!recipe || !stationDef || !inventory
347 || (blockType && !nearStationBlock(world, position.tileX, position.tileY, blockType))
353 || (blockType && !nearStationBlock(world, position.tileX, position.tileY, blockType))
348 || !canCraftFitInventory(inventory.slots, recipe, { dyeSlotIndex: session.dyeSlotIndex })
354 || !canCraftFitInventory(inventory.slots, recipe, { dyeColorKey: session.dyeColorKey })
349 || (level | 0) < (recipe.minSkillLevel | 0 || 1))
355 || (level | 0) < (recipe.minSkillLevel | 0 || 1))
350 {
356 {
351 events.push({
357 events.push({
@@ -371,9 +377,10 @@ export function stepCrafting (world, now)
371 continue;
377 continue;
372 }
378 }
373 let slotsAfter = taken.slots;
379 let slotsAfter = taken.slots;
374 if (recipe.consumeDye && session.dyeSlotIndex != null)
380 if (recipe.consumeDye && session.dyeColorKey != null)
375 {
381 {
376 const dyeTaken = consumeDyeUse(slotsAfter, session.dyeSlotIndex);
382 const consumeSlot = pickEmptiestDyeSlot(slotsAfter, session.dyeColorKey);
383 const dyeTaken = consumeDyeUse(slotsAfter, consumeSlot);
377 if (!dyeTaken.ok)
384 if (!dyeTaken.ok)
378 {
385 {
379 events.push({
386 events.push({
@@ -467,7 +474,7 @@ export function stepCrafting (world, now)
467 inventory.slots,
474 inventory.slots,
468 recipe,
475 recipe,
469 level,
476 level,
470 { dyeSlotIndex: session.dyeSlotIndex }
477 { dyeColorKey: session.dyeColorKey, dyeSlotIndex: null }
471 ))
478 ))
472 {
479 {
473 const durationMs = session.durationMs ?? craftDurationMs(recipe, CRAFT_DURATION_MS);
480 const durationMs = session.durationMs ?? craftDurationMs(recipe, CRAFT_DURATION_MS);
server/src/firestarting/service.js +3 −3
@@ -19,7 +19,7 @@ import { rollSkill } from "../../../shared/combat/rolls.js";
19 19 import { stackQuantity } from "../../../shared/items/inventory.js";
20 20 import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";
21 21 import { addGroundItem, publicGroundItem, removeGroundItem, bagView } from "../items/bags.js";
22 import { chebyshev } from "../combat/service.js";
22 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
23 23 import { tileToChunk, tileToLocal } from "../world/coordinates.js";
24 24 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
25 25
@@ -242,7 +242,7 @@ export function startFire (world, sessionId, characterId, groundItemId, now)
242 242 { throw userError("You can only light wood logs."); }
243 243
244 244 const position = world.ecs.get(handle, Component.position);
245 if (chebyshev(position.tileX, position.tileY, item.tileX, item.tileY) > 1)
245 if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY))
246 246 { throw userError("You need to stand next to the logs."); }
247 247
248 248 if (blockAt(world, item.tileX, item.tileY))
@@ -408,7 +408,7 @@ export function stepFirestarting (world, now)
408 408 continue;
409 409 }
410 410 const position = world.ecs.get(handle, Component.position);
411 if (chebyshev(position.tileX, position.tileY, session.tileX, session.tileY) > 1)
411 if (!isAdjacentTile(position.tileX, position.tileY, session.tileX, session.tileY))
412 412 {
413 413 clearFireSession(world, characterId);
414 414 continue;
@@ -19,7 +19,7 @@ import { rollSkill } from "../../../shared/combat/rolls.js";
19import { stackQuantity } from "../../../shared/items/inventory.js";
19import { stackQuantity } from "../../../shared/items/inventory.js";
20import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";
20import { attachOrigins, ashOrigin } from "../../../shared/items/origin.js";
21import { addGroundItem, publicGroundItem, removeGroundItem, bagView } from "../items/bags.js";
21import { addGroundItem, publicGroundItem, removeGroundItem, bagView } from "../items/bags.js";
22import { chebyshev } from "../combat/service.js";
22import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
23import { tileToChunk, tileToLocal } from "../world/coordinates.js";
23import { tileToChunk, tileToLocal } from "../world/coordinates.js";
24import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
24import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
25
25
@@ -242,7 +242,7 @@ export function startFire (world, sessionId, characterId, groundItemId, now)
242 { throw userError("You can only light wood logs."); }
242 { throw userError("You can only light wood logs."); }
243
243
244 const position = world.ecs.get(handle, Component.position);
244 const position = world.ecs.get(handle, Component.position);
245 if (chebyshev(position.tileX, position.tileY, item.tileX, item.tileY) > 1)
245 if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY))
246 { throw userError("You need to stand next to the logs."); }
246 { throw userError("You need to stand next to the logs."); }
247
247
248 if (blockAt(world, item.tileX, item.tileY))
248 if (blockAt(world, item.tileX, item.tileY))
@@ -408,7 +408,7 @@ export function stepFirestarting (world, now)
408 continue;
408 continue;
409 }
409 }
410 const position = world.ecs.get(handle, Component.position);
410 const position = world.ecs.get(handle, Component.position);
411 if (chebyshev(position.tileX, position.tileY, session.tileX, session.tileY) > 1)
411 if (!isAdjacentTile(position.tileX, position.tileY, session.tileX, session.tileY))
412 {
412 {
413 clearFireSession(world, characterId);
413 clearFireSession(world, characterId);
414 continue;
414 continue;
server/src/fishing/service.js +3 −3
@@ -36,7 +36,7 @@ import {
36 36 } from "../../../shared/items/inventory.js";
37 37 import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
38 38 import { addGroundItem, publicGroundItem, bagView } from "../items/bags.js";
39 import { chebyshev } from "../combat/service.js";
39 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
40 40 import { tileToChunk, tileToLocal } from "../world/coordinates.js";
41 41 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
42 42 import { tileShoveEvent } from "../simulation/tileInteract.js";
@@ -185,7 +185,7 @@ export function startFish (world, sessionId, characterId, tileX, tileY, now = Da
185 185 { throw userError("You are dead."); }
186 186
187 187 const position = world.ecs.get(handle, Component.position);
188 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
188 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
189 189 { throw userError("You need to stand next to the fishing spot."); }
190 190
191 191 const block = blockAt(world, tileX, tileY);
@@ -409,7 +409,7 @@ export function stepFishing (world, now)
409 409 continue;
410 410 }
411 411 const position = world.ecs.get(handle, Component.position);
412 if (chebyshev(position.tileX, position.tileY, session.tileX, session.tileY) > 1)
412 if (!isAdjacentTile(position.tileX, position.tileY, session.tileX, session.tileY))
413 413 {
414 414 clearFishSession(world, characterId);
415 415 continue;
@@ -36,7 +36,7 @@ import {
36} from "../../../shared/items/inventory.js";
36} from "../../../shared/items/inventory.js";
37import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
37import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
38import { addGroundItem, publicGroundItem, bagView } from "../items/bags.js";
38import { addGroundItem, publicGroundItem, bagView } from "../items/bags.js";
39import { chebyshev } from "../combat/service.js";
39import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
40import { tileToChunk, tileToLocal } from "../world/coordinates.js";
40import { tileToChunk, tileToLocal } from "../world/coordinates.js";
41import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
41import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
42import { tileShoveEvent } from "../simulation/tileInteract.js";
42import { tileShoveEvent } from "../simulation/tileInteract.js";
@@ -185,7 +185,7 @@ export function startFish (world, sessionId, characterId, tileX, tileY, now = Da
185 { throw userError("You are dead."); }
185 { throw userError("You are dead."); }
186
186
187 const position = world.ecs.get(handle, Component.position);
187 const position = world.ecs.get(handle, Component.position);
188 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
188 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
189 { throw userError("You need to stand next to the fishing spot."); }
189 { throw userError("You need to stand next to the fishing spot."); }
190
190
191 const block = blockAt(world, tileX, tileY);
191 const block = blockAt(world, tileX, tileY);
@@ -409,7 +409,7 @@ export function stepFishing (world, now)
409 continue;
409 continue;
410 }
410 }
411 const position = world.ecs.get(handle, Component.position);
411 const position = world.ecs.get(handle, Component.position);
412 if (chebyshev(position.tileX, position.tileY, session.tileX, session.tileY) > 1)
412 if (!isAdjacentTile(position.tileX, position.tileY, session.tileX, session.tileY))
413 {
413 {
414 clearFishSession(world, characterId);
414 clearFishSession(world, characterId);
415 continue;
415 continue;
server/src/gathering/service.js +6 −5
@@ -42,7 +42,8 @@ import {
42 42 scaleRegrowDurationMs
43 43 } from "../../../shared/world/season.js";
44 44 import { bagView } from "../items/bags.js";
45 import { chebyshev, clearEngage } from "../combat/service.js";
45 import { clearEngage } from "../combat/service.js";
46 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
46 47 import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
47 48 import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
48 49
@@ -362,7 +363,7 @@ export function startMine (world, sessionId, characterId, tileX, tileY, now)
362 363 { throw userError("You are dead."); }
363 364
364 365 const position = world.ecs.get(handle, Component.position);
365 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
366 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
366 367 { throw userError("You need to stand next to the rock."); }
367 368
368 369 const block = blockAt(world, tileX, tileY);
@@ -409,7 +410,7 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)
409 410 { throw userError("You are dead."); }
410 411
411 412 const position = world.ecs.get(handle, Component.position);
412 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
413 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
413 414 { throw userError("You need to stand next to the tree."); }
414 415
415 416 const block = blockAt(world, tileX, tileY);
@@ -454,7 +455,7 @@ export function startPick (world, sessionId, characterId, tileX, tileY, now)
454 455 { throw userError("You are dead."); }
455 456
456 457 const position = world.ecs.get(handle, Component.position);
457 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
458 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
458 459 { throw userError("You need to stand next to the plant."); }
459 460
460 461 const block = blockAt(world, tileX, tileY);
@@ -813,7 +814,7 @@ export function stepGather (world, now)
813 814 clearGather(world.ecs, handle);
814 815 continue;
815 816 }
816 if (chebyshev(position.tileX, position.tileY, gather.tileX, gather.tileY) > 1)
817 if (!isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY))
817 818 {
818 819 clearGather(world.ecs, handle);
819 820 continue;
@@ -42,7 +42,8 @@ import {
42 scaleRegrowDurationMs
42 scaleRegrowDurationMs
43} from "../../../shared/world/season.js";
43} from "../../../shared/world/season.js";
44import { bagView } from "../items/bags.js";
44import { bagView } from "../items/bags.js";
45import { chebyshev, clearEngage } from "../combat/service.js";
45import { clearEngage } from "../combat/service.js";
46import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
46import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
47import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
47import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
48import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
48
49
@@ -362,7 +363,7 @@ export function startMine (world, sessionId, characterId, tileX, tileY, now)
362 { throw userError("You are dead."); }
363 { throw userError("You are dead."); }
363
364
364 const position = world.ecs.get(handle, Component.position);
365 const position = world.ecs.get(handle, Component.position);
365 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
366 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
366 { throw userError("You need to stand next to the rock."); }
367 { throw userError("You need to stand next to the rock."); }
367
368
368 const block = blockAt(world, tileX, tileY);
369 const block = blockAt(world, tileX, tileY);
@@ -409,7 +410,7 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)
409 { throw userError("You are dead."); }
410 { throw userError("You are dead."); }
410
411
411 const position = world.ecs.get(handle, Component.position);
412 const position = world.ecs.get(handle, Component.position);
412 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
413 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
413 { throw userError("You need to stand next to the tree."); }
414 { throw userError("You need to stand next to the tree."); }
414
415
415 const block = blockAt(world, tileX, tileY);
416 const block = blockAt(world, tileX, tileY);
@@ -454,7 +455,7 @@ export function startPick (world, sessionId, characterId, tileX, tileY, now)
454 { throw userError("You are dead."); }
455 { throw userError("You are dead."); }
455
456
456 const position = world.ecs.get(handle, Component.position);
457 const position = world.ecs.get(handle, Component.position);
457 if (chebyshev(position.tileX, position.tileY, tileX, tileY) > 1)
458 if (!isAdjacentTile(position.tileX, position.tileY, tileX, tileY))
458 { throw userError("You need to stand next to the plant."); }
459 { throw userError("You need to stand next to the plant."); }
459
460
460 const block = blockAt(world, tileX, tileY);
461 const block = blockAt(world, tileX, tileY);
@@ -813,7 +814,7 @@ export function stepGather (world, now)
813 clearGather(world.ecs, handle);
814 clearGather(world.ecs, handle);
814 continue;
815 continue;
815 }
816 }
816 if (chebyshev(position.tileX, position.tileY, gather.tileX, gather.tileY) > 1)
817 if (!isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY))
817 {
818 {
818 clearGather(world.ecs, handle);
819 clearGather(world.ecs, handle);
819 continue;
820 continue;
server/src/items/bags.js +2 −0
@@ -1046,6 +1046,8 @@ function nearBank (world, tileX, tileY)
1046 1046 {
1047 1047 for (let dx = -1; dx <= 1; dx++)
1048 1048 {
1049 if (dx === 0 && dy === 0)
1050 { continue; }
1049 1051 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
1050 1052 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
1051 1053 if (data.blocks[index]?.typeId === BlockType.bank)
@@ -1046,6 +1046,8 @@ function nearBank (world, tileX, tileY)
1046 {
1046 {
1047 for (let dx = -1; dx <= 1; dx++)
1047 for (let dx = -1; dx <= 1; dx++)
1048 {
1048 {
1049 if (dx === 0 && dy === 0)
1050 { continue; }
1049 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
1051 const data = world.chunkData(tileToChunk(tileX + dx), tileToChunk(tileY + dy));
1050 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
1052 const index = tileToLocal(tileY + dy) * CHUNK_SIZE + tileToLocal(tileX + dx);
1051 if (data.blocks[index]?.typeId === BlockType.bank)
1053 if (data.blocks[index]?.typeId === BlockType.bank)
server/src/market/service.js +4 −7
@@ -43,10 +43,7 @@ function userError (message)
43 43 return error;
44 44 }
45 45
46 function chebyshev (ax, ay, bx, by)
47 {
48 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
49 }
46 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
50 47
51 48 export class MarketService
52 49 {
@@ -786,7 +783,7 @@ export class MarketService
786 783 if (!this.marketTiles.length)
787 784 { throw userError("The Central Exchange is not open in this world yet."); }
788 785 const near = this.marketTiles.some((tile) =>
789 chebyshev(position.tileX, position.tileY, tile.tileX, tile.tileY) <= 1);
786 isAdjacentTile(position.tileX, position.tileY, tile.tileX, tile.tileY));
790 787 if (!near)
791 788 { throw userError("Stand next to the Central Exchange counter."); }
792 789 return { position, entityId };
@@ -797,7 +794,7 @@ export class MarketService
797 794 const targets = [];
798 795 for (const tile of this.marketTiles)
799 796 {
800 if (chebyshev(tileX, tileY, tile.tileX, tile.tileY) > 1)
797 if (!isAdjacentTile(tileX, tileY, tile.tileX, tile.tileY))
801 798 { continue; }
802 799 if (tile.tileX === tileX && tile.tileY === tileY)
803 800 { continue; }
@@ -862,7 +859,7 @@ export class MarketService
862 859 const position = entityId ? this.simulation.positionOf(entityId) : null;
863 860 if (!position)
864 861 { return false; }
865 return chebyshev(position.tileX, position.tileY, marketTileX, marketTileY) <= 1;
862 return isAdjacentTile(position.tileX, position.tileY, marketTileX, marketTileY);
866 863 }
867 864
868 865 #releaseStation (key)
@@ -43,10 +43,7 @@ function userError (message)
43 return error;
43 return error;
44}
44}
45
45
46function chebyshev (ax, ay, bx, by)
46import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
47{
48 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
49}
50
47
51export class MarketService
48export class MarketService
52{
49{
@@ -786,7 +783,7 @@ export class MarketService
786 if (!this.marketTiles.length)
783 if (!this.marketTiles.length)
787 { throw userError("The Central Exchange is not open in this world yet."); }
784 { throw userError("The Central Exchange is not open in this world yet."); }
788 const near = this.marketTiles.some((tile) =>
785 const near = this.marketTiles.some((tile) =>
789 chebyshev(position.tileX, position.tileY, tile.tileX, tile.tileY) <= 1);
786 isAdjacentTile(position.tileX, position.tileY, tile.tileX, tile.tileY));
790 if (!near)
787 if (!near)
791 { throw userError("Stand next to the Central Exchange counter."); }
788 { throw userError("Stand next to the Central Exchange counter."); }
792 return { position, entityId };
789 return { position, entityId };
@@ -797,7 +794,7 @@ export class MarketService
797 const targets = [];
794 const targets = [];
798 for (const tile of this.marketTiles)
795 for (const tile of this.marketTiles)
799 {
796 {
800 if (chebyshev(tileX, tileY, tile.tileX, tile.tileY) > 1)
797 if (!isAdjacentTile(tileX, tileY, tile.tileX, tile.tileY))
801 { continue; }
798 { continue; }
802 if (tile.tileX === tileX && tile.tileY === tileY)
799 if (tile.tileX === tileX && tile.tileY === tileY)
803 { continue; }
800 { continue; }
@@ -862,7 +859,7 @@ export class MarketService
862 const position = entityId ? this.simulation.positionOf(entityId) : null;
859 const position = entityId ? this.simulation.positionOf(entityId) : null;
863 if (!position)
860 if (!position)
864 { return false; }
861 { return false; }
865 return chebyshev(position.tileX, position.tileY, marketTileX, marketTileY) <= 1;
862 return isAdjacentTile(position.tileX, position.tileY, marketTileX, marketTileY);
866 }
863 }
867
864
868 #releaseStation (key)
865 #releaseStation (key)
server/src/shearing/service.js +3 −3
@@ -11,7 +11,7 @@ import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../share
11 11 import { insertStack } from "../../../shared/items/inventory.js";
12 12 import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
13 13 import { bagView } from "../items/bags.js";
14 import { chebyshev } from "../combat/service.js";
14 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
15 15 import { publicEntityView, replicationAppearance } from "../ecs/serialize.js";
16 16 import { scaleRegrowDurationMs } from "../../../shared/world/season.js";
17 17 import { tileShoveEvent } from "../simulation/tileInteract.js";
@@ -128,7 +128,7 @@ export function startShear (world, sessionId, characterId, targetEntityId, now)
128 128
129 129 const playerPos = world.ecs.get(handle, Component.position);
130 130 const targetPos = world.ecs.get(targetHandle, Component.position);
131 if (chebyshev(playerPos.tileX, playerPos.tileY, targetPos.tileX, targetPos.tileY) > 1)
131 if (!isAdjacentTile(playerPos.tileX, playerPos.tileY, targetPos.tileX, targetPos.tileY))
132 132 { throw userError("You need to stand next to it."); }
133 133
134 134 const inventory = world.ecs.get(handle, Component.inventory);
@@ -332,7 +332,7 @@ export function stepShearing (world, now)
332 332
333 333 const position = world.ecs.get(handle, Component.position);
334 334 const targetPos = world.ecs.get(targetHandle, Component.position);
335 if (chebyshev(position.tileX, position.tileY, targetPos.tileX, targetPos.tileY) > 1)
335 if (!isAdjacentTile(position.tileX, position.tileY, targetPos.tileX, targetPos.tileY))
336 336 {
337 337 clearShearSession(world, characterId);
338 338 continue;
@@ -11,7 +11,7 @@ import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../share
11import { insertStack } from "../../../shared/items/inventory.js";
11import { insertStack } from "../../../shared/items/inventory.js";
12import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
12import { attachOrigins, gatherOrigin, GatherOriginVerb } from "../../../shared/items/origin.js";
13import { bagView } from "../items/bags.js";
13import { bagView } from "../items/bags.js";
14import { chebyshev } from "../combat/service.js";
14import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
15import { publicEntityView, replicationAppearance } from "../ecs/serialize.js";
15import { publicEntityView, replicationAppearance } from "../ecs/serialize.js";
16import { scaleRegrowDurationMs } from "../../../shared/world/season.js";
16import { scaleRegrowDurationMs } from "../../../shared/world/season.js";
17import { tileShoveEvent } from "../simulation/tileInteract.js";
17import { tileShoveEvent } from "../simulation/tileInteract.js";
@@ -128,7 +128,7 @@ export function startShear (world, sessionId, characterId, targetEntityId, now)
128
128
129 const playerPos = world.ecs.get(handle, Component.position);
129 const playerPos = world.ecs.get(handle, Component.position);
130 const targetPos = world.ecs.get(targetHandle, Component.position);
130 const targetPos = world.ecs.get(targetHandle, Component.position);
131 if (chebyshev(playerPos.tileX, playerPos.tileY, targetPos.tileX, targetPos.tileY) > 1)
131 if (!isAdjacentTile(playerPos.tileX, playerPos.tileY, targetPos.tileX, targetPos.tileY))
132 { throw userError("You need to stand next to it."); }
132 { throw userError("You need to stand next to it."); }
133
133
134 const inventory = world.ecs.get(handle, Component.inventory);
134 const inventory = world.ecs.get(handle, Component.inventory);
@@ -332,7 +332,7 @@ export function stepShearing (world, now)
332
332
333 const position = world.ecs.get(handle, Component.position);
333 const position = world.ecs.get(handle, Component.position);
334 const targetPos = world.ecs.get(targetHandle, Component.position);
334 const targetPos = world.ecs.get(targetHandle, Component.position);
335 if (chebyshev(position.tileX, position.tileY, targetPos.tileX, targetPos.tileY) > 1)
335 if (!isAdjacentTile(position.tileX, position.tileY, targetPos.tileX, targetPos.tileY))
336 {
336 {
337 clearShearSession(world, characterId);
337 clearShearSession(world, characterId);
338 continue;
338 continue;
server/src/shop/service.js +4 −4
@@ -29,7 +29,7 @@ import {
29 29 shopRestockDayKey
30 30 } from "../../../shared/shop/pricing.js";
31 31 import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
32 import { chebyshev } from "../combat/service.js";
32 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
33 33 import { objectPronoun } from "../../../shared/speech/pronouns.js";
34 34
35 35 function userError (message)
@@ -115,12 +115,12 @@ export function pruneShopBrowsers (world)
115 115 const playerHandle = world.ecs.handleOf(playerEntityId);
116 116 const playerPos = world.ecs.get(playerHandle, Component.position);
117 117 const stillNear = playerPos
118 && chebyshev(
118 && isAdjacentTile(
119 119 playerPos.tileX,
120 120 playerPos.tileY,
121 121 entity.position.tileX,
122 122 entity.position.tileY
123 ) <= 1;
123 );
124 124 if (stillNear)
125 125 { continue; }
126 126 removeShopBrowser(shop, characterId);
@@ -447,7 +447,7 @@ function requireShopAccess (world, sessionId, characterId, npcEntityId)
447 447
448 448 const playerPos = world.ecs.get(handle, Component.position);
449 449 const npcPos = world.ecs.get(npcHandle, Component.position);
450 if (!playerPos || !npcPos || chebyshev(playerPos.tileX, playerPos.tileY, npcPos.tileX, npcPos.tileY) > 1)
450 if (!playerPos || !npcPos || !isAdjacentTile(playerPos.tileX, playerPos.tileY, npcPos.tileX, npcPos.tileY))
451 451 { throw userError(`You need to stand next to ${objectPronoun(sex)}.`); }
452 452
453 453 return { handle, npcHandle, shop, entityId };
@@ -29,7 +29,7 @@ import {
29 shopRestockDayKey
29 shopRestockDayKey
30} from "../../../shared/shop/pricing.js";
30} from "../../../shared/shop/pricing.js";
31import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
31import { DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
32import { chebyshev } from "../combat/service.js";
32import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
33import { objectPronoun } from "../../../shared/speech/pronouns.js";
33import { objectPronoun } from "../../../shared/speech/pronouns.js";
34
34
35function userError (message)
35function userError (message)
@@ -115,12 +115,12 @@ export function pruneShopBrowsers (world)
115 const playerHandle = world.ecs.handleOf(playerEntityId);
115 const playerHandle = world.ecs.handleOf(playerEntityId);
116 const playerPos = world.ecs.get(playerHandle, Component.position);
116 const playerPos = world.ecs.get(playerHandle, Component.position);
117 const stillNear = playerPos
117 const stillNear = playerPos
118 && chebyshev(
118 && isAdjacentTile(
119 playerPos.tileX,
119 playerPos.tileX,
120 playerPos.tileY,
120 playerPos.tileY,
121 entity.position.tileX,
121 entity.position.tileX,
122 entity.position.tileY
122 entity.position.tileY
123 ) <= 1;
123 );
124 if (stillNear)
124 if (stillNear)
125 { continue; }
125 { continue; }
126 removeShopBrowser(shop, characterId);
126 removeShopBrowser(shop, characterId);
@@ -447,7 +447,7 @@ function requireShopAccess (world, sessionId, characterId, npcEntityId)
447
447
448 const playerPos = world.ecs.get(handle, Component.position);
448 const playerPos = world.ecs.get(handle, Component.position);
449 const npcPos = world.ecs.get(npcHandle, Component.position);
449 const npcPos = world.ecs.get(npcHandle, Component.position);
450 if (!playerPos || !npcPos || chebyshev(playerPos.tileX, playerPos.tileY, npcPos.tileX, npcPos.tileY) > 1)
450 if (!playerPos || !npcPos || !isAdjacentTile(playerPos.tileX, playerPos.tileY, npcPos.tileX, npcPos.tileY))
451 { throw userError(`You need to stand next to ${objectPronoun(sex)}.`); }
451 { throw userError(`You need to stand next to ${objectPronoun(sex)}.`); }
452
452
453 return { handle, npcHandle, shop, entityId };
453 return { handle, npcHandle, shop, entityId };
server/src/simulation/simulation.js +2 −2
@@ -50,7 +50,7 @@ import { findReservedChequeIndex } from "../items/bags.js";
50 50 import { hairFromCharacterRow, appearanceHairFields } from "../../../shared/appearance/hair.js";
51 51 import { QuestContentCache } from "../quests/contentCache.js";
52 52 import { QuestRuntime } from "../quests/runtime.js";
53 import { chebyshev } from "../combat/service.js";
53 import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
54 54
55 55 export class Simulation
56 56 {
@@ -1879,7 +1879,7 @@ export class Simulation
1879 1879 }
1880 1880 const tileX = doorwayTileX | 0;
1881 1881 const tileY = doorwayTileY | 0;
1882 if (chebyshev(record.tileX, record.tileY, tileX, tileY) > 1)
1882 if (!isAdjacentTile(record.tileX, record.tileY, tileX, tileY))
1883 1883 {
1884 1884 const error = new Error("You are too far from that doorway.");
1885 1885 error.userFacing = true;
@@ -50,7 +50,7 @@ import { findReservedChequeIndex } from "../items/bags.js";
50import { hairFromCharacterRow, appearanceHairFields } from "../../../shared/appearance/hair.js";
50import { hairFromCharacterRow, appearanceHairFields } from "../../../shared/appearance/hair.js";
51import { QuestContentCache } from "../quests/contentCache.js";
51import { QuestContentCache } from "../quests/contentCache.js";
52import { QuestRuntime } from "../quests/runtime.js";
52import { QuestRuntime } from "../quests/runtime.js";
53import { chebyshev } from "../combat/service.js";
53import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
54
54
55export class Simulation
55export class Simulation
56{
56{
@@ -1879,7 +1879,7 @@ export class Simulation
1879 }
1879 }
1880 const tileX = doorwayTileX | 0;
1880 const tileX = doorwayTileX | 0;
1881 const tileY = doorwayTileY | 0;
1881 const tileY = doorwayTileY | 0;
1882 if (chebyshev(record.tileX, record.tileY, tileX, tileY) > 1)
1882 if (!isAdjacentTile(record.tileX, record.tileY, tileX, tileY))
1883 {
1883 {
1884 const error = new Error("You are too far from that doorway.");
1884 const error = new Error("You are too far from that doorway.");
1885 error.userFacing = true;
1885 error.userFacing = true;
server/tests/adjacency-interaction.test.js added +93 −0
@@ -0,0 +1,93 @@
1 import test from "node:test";
2 import assert from "node:assert/strict";
3 import { BlockType } from "../../shared/definitions/tiles.js";
4 import { ItemId } from "../../shared/definitions/items.js";
5 import { SkillId } from "../../shared/definitions/skills.js";
6 import { isAdjacentTile } from "../../shared/navigation/adjacency.js";
7 import { totalXpForLevel } from "../../shared/skills/progression.js";
8 import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
9 import { Component } from "../src/ecs/components.js";
10
11 test("isAdjacentTile excludes same tile and allows neighbours", () =>
12 {
13 assert.equal(isAdjacentTile(5, 5, 5, 5), false);
14 assert.equal(isAdjacentTile(5, 5, 6, 5), true);
15 assert.equal(isAdjacentTile(5, 5, 7, 5), false);
16 });
17
18 function placeOre (worker, tileX, tileY, state)
19 {
20 const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
21 const localX = tileX % 16;
22 const localY = tileY % 16;
23 const index = localY * 16 + localX;
24 data.blocks[index] = { typeId: BlockType.boulder, state, config: null };
25 }
26
27 function placeFlower (worker, tileX, tileY)
28 {
29 const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
30 const localX = tileX % 16;
31 const localY = tileY % 16;
32 const index = localY * 16 + localX;
33 data.blocks[index] = { typeId: BlockType.flower, state: "red", config: null };
34 }
35
36 test("mining rejects standing on the ore boulder", () =>
37 {
38 const harness = makeSimulation({ workerCount: 1 });
39 try
40 {
41 const character = makeCharacter(harness.stateDb, { tileX: 9, tileY: 8 });
42 const playerId = harness.simulation.spawnCharacter(1, character);
43 const record = harness.simulation.entityRecord(playerId);
44 const worker = harness.simulation.workers[record.workerId];
45 const handle = worker.world.ecs.handleOf(playerId);
46 worker.world.ecs.get(handle, Component.inventory).slots[0] = {
47 itemId: ItemId.bronzePickaxe,
48 quantity: 1
49 };
50 const skills = worker.world.ecs.get(handle, Component.skills);
51 skills.xp[SkillId.mining] = totalXpForLevel(10);
52 placeOre(worker, 9, 8, "iron-ore");
53
54 harness.simulation.enqueue(1, {
55 type: "mine",
56 characterId: character.character_id,
57 tileX: 9,
58 tileY: 8
59 });
60 const result = harness.simulation.step();
61 assert.ok(result.events.some((event) =>
62 event.type === "command-error"
63 && /stand next/i.test(event.message ?? "")));
64 }
65 finally
66 { harness.close(); }
67 });
68
69 test("picking rejects standing on the plant", () =>
70 {
71 const harness = makeSimulation({ workerCount: 1 });
72 try
73 {
74 const character = makeCharacter(harness.stateDb, { tileX: 9, tileY: 8 });
75 const playerId = harness.simulation.spawnCharacter(1, character);
76 const record = harness.simulation.entityRecord(playerId);
77 const worker = harness.simulation.workers[record.workerId];
78 placeFlower(worker, 9, 8);
79
80 harness.simulation.enqueue(1, {
81 type: "pick",
82 characterId: character.character_id,
83 tileX: 9,
84 tileY: 8
85 });
86 const result = harness.simulation.step();
87 assert.ok(result.events.some((event) =>
88 event.type === "command-error"
89 && /stand next/i.test(event.message ?? "")));
90 }
91 finally
92 { harness.close(); }
93 });
@@ -0,0 +1,93 @@
1import test from "node:test";
2import assert from "node:assert/strict";
3import { BlockType } from "../../shared/definitions/tiles.js";
4import { ItemId } from "../../shared/definitions/items.js";
5import { SkillId } from "../../shared/definitions/skills.js";
6import { isAdjacentTile } from "../../shared/navigation/adjacency.js";
7import { totalXpForLevel } from "../../shared/skills/progression.js";
8import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
9import { Component } from "../src/ecs/components.js";
10
11test("isAdjacentTile excludes same tile and allows neighbours", () =>
12{
13 assert.equal(isAdjacentTile(5, 5, 5, 5), false);
14 assert.equal(isAdjacentTile(5, 5, 6, 5), true);
15 assert.equal(isAdjacentTile(5, 5, 7, 5), false);
16});
17
18function placeOre (worker, tileX, tileY, state)
19{
20 const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
21 const localX = tileX % 16;
22 const localY = tileY % 16;
23 const index = localY * 16 + localX;
24 data.blocks[index] = { typeId: BlockType.boulder, state, config: null };
25}
26
27function placeFlower (worker, tileX, tileY)
28{
29 const data = worker.world.chunkData(Math.floor(tileX / 16), Math.floor(tileY / 16));
30 const localX = tileX % 16;
31 const localY = tileY % 16;
32 const index = localY * 16 + localX;
33 data.blocks[index] = { typeId: BlockType.flower, state: "red", config: null };
34}
35
36test("mining rejects standing on the ore boulder", () =>
37{
38 const harness = makeSimulation({ workerCount: 1 });
39 try
40 {
41 const character = makeCharacter(harness.stateDb, { tileX: 9, tileY: 8 });
42 const playerId = harness.simulation.spawnCharacter(1, character);
43 const record = harness.simulation.entityRecord(playerId);
44 const worker = harness.simulation.workers[record.workerId];
45 const handle = worker.world.ecs.handleOf(playerId);
46 worker.world.ecs.get(handle, Component.inventory).slots[0] = {
47 itemId: ItemId.bronzePickaxe,
48 quantity: 1
49 };
50 const skills = worker.world.ecs.get(handle, Component.skills);
51 skills.xp[SkillId.mining] = totalXpForLevel(10);
52 placeOre(worker, 9, 8, "iron-ore");
53
54 harness.simulation.enqueue(1, {
55 type: "mine",
56 characterId: character.character_id,
57 tileX: 9,
58 tileY: 8
59 });
60 const result = harness.simulation.step();
61 assert.ok(result.events.some((event) =>
62 event.type === "command-error"
63 && /stand next/i.test(event.message ?? "")));
64 }
65 finally
66 { harness.close(); }
67});
68
69test("picking rejects standing on the plant", () =>
70{
71 const harness = makeSimulation({ workerCount: 1 });
72 try
73 {
74 const character = makeCharacter(harness.stateDb, { tileX: 9, tileY: 8 });
75 const playerId = harness.simulation.spawnCharacter(1, character);
76 const record = harness.simulation.entityRecord(playerId);
77 const worker = harness.simulation.workers[record.workerId];
78 placeFlower(worker, 9, 8);
79
80 harness.simulation.enqueue(1, {
81 type: "pick",
82 characterId: character.character_id,
83 tileX: 9,
84 tileY: 8
85 });
86 const result = harness.simulation.step();
87 assert.ok(result.events.some((event) =>
88 event.type === "command-error"
89 && /stand next/i.test(event.message ?? "")));
90 }
91 finally
92 { harness.close(); }
93});
server/tests/shop.test.js +16 −14
@@ -104,7 +104,7 @@ test("buy paper from a shopkeeper with explicit catalog", () =>
104 104 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
105 105 const playerHandle = worker.world.ecs.handleOf(playerId);
106 106 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
107 playerPos.tileX = npcPos.tileX;
107 playerPos.tileX = npcPos.tileX - 1;
108 108 playerPos.tileY = npcPos.tileY;
109 109
110 110 harness.simulation.enqueue(1, {
@@ -308,7 +308,7 @@ test("shopkeeper with buysItems accepts paper from the player", () =>
308 308 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
309 309 const playerHandle = worker.world.ecs.handleOf(playerId);
310 310 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
311 playerPos.tileX = npcPos.tileX;
311 playerPos.tileX = npcPos.tileX - 1;
312 312 playerPos.tileY = npcPos.tileY;
313 313
314 314 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
@@ -405,7 +405,7 @@ test("buy copper ore from a spawned shopkeeper", () =>
405 405 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
406 406 const playerHandle = worker.world.ecs.handleOf(playerId);
407 407 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
408 playerPos.tileX = npcPos.tileX;
408 playerPos.tileX = npcPos.tileX - 1;
409 409 playerPos.tileY = npcPos.tileY;
410 410
411 411 harness.simulation.enqueue(1, {
@@ -522,7 +522,7 @@ test("shop overflow goes to bank vault when inventory is full", () =>
522 522 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
523 523 const playerHandle = worker.world.ecs.handleOf(playerId);
524 524 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
525 playerPos.tileX = npcPos.tileX;
525 playerPos.tileX = npcPos.tileX - 1;
526 526 playerPos.tileY = npcPos.tileY;
527 527
528 528 harness.simulation.enqueue(1, {
@@ -596,7 +596,7 @@ test("buysItems refills limited catalog then stores extras for 120% resale", ()
596 596 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
597 597 const playerHandle = worker.world.ecs.handleOf(playerId);
598 598 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
599 playerPos.tileX = npcPos.tileX;
599 playerPos.tileX = npcPos.tileX - 1;
600 600 playerPos.tileY = npcPos.tileY;
601 601
602 602 // Fund coins and buy out limited stock first.
@@ -754,10 +754,12 @@ test("shopkeeper stops wandering while a player has the shop open", () =>
754 754 }
755 755 assert.ok(npc);
756 756
757 const npcStartX = npc.position.tileX;
758 const npcStartY = npc.position.tileY;
757 759 const playerHandle = worker.world.ecs.handleOf(playerId);
758 760 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
759 playerPos.tileX = npc.position.tileX;
760 playerPos.tileY = npc.position.tileY;
761 playerPos.tileX = npcStartX - 1;
762 playerPos.tileY = npcStartY;
761 763
762 764 harness.simulation.enqueue(1, {
763 765 type: "interact",
@@ -772,8 +774,8 @@ test("shopkeeper stops wandering while a player has the shop open", () =>
772 774 for (let i = 0; i < 20; i++)
773 775 { harness.simulation.step(); }
774 776 assert.equal(npc.path.tiles.length, 0);
775 assert.equal(npc.position.tileX, playerPos.tileX);
776 assert.equal(npc.position.tileY, playerPos.tileY);
777 assert.equal(npc.position.tileX, npcStartX);
778 assert.equal(npc.position.tileY, npcStartY);
777 779
778 780 harness.simulation.enqueue(1, {
779 781 type: "close-shop",
@@ -841,7 +843,7 @@ test("buysItems accepts non-ingredient tools like sticks", () =>
841 843 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
842 844 const playerHandle = worker.world.ecs.handleOf(playerId);
843 845 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
844 playerPos.tileX = npcPos.tileX;
846 playerPos.tileX = npcPos.tileX - 1;
845 847 playerPos.tileY = npcPos.tileY;
846 848
847 849 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
@@ -944,7 +946,7 @@ test("selling a filled cheque pays reserved-goods price minus 5% admin fee", ()
944 946 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
945 947 const playerHandle = worker.world.ecs.handleOf(playerId);
946 948 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
947 playerPos.tileX = npcPos.tileX;
949 playerPos.tileX = npcPos.tileX - 1;
948 950 playerPos.tileY = npcPos.tileY;
949 951
950 952 const quote = resolveShopSellQuote(bag.inventory[chequeIndex]);
@@ -1032,7 +1034,7 @@ test("resale stock keeps the seller origin instead of Bought from NPC", () =>
1032 1034 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1033 1035 const playerHandle = worker.world.ecs.handleOf(playerId);
1034 1036 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1035 playerPos.tileX = npcPos.tileX;
1037 playerPos.tileX = npcPos.tileX - 1;
1036 1038 playerPos.tileY = npcPos.tileY;
1037 1039
1038 1040 harness.simulation.enqueue(1, {
@@ -1139,7 +1141,7 @@ test("NPC letter sales pay out and destroy the letter without stock", () =>
1139 1141 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1140 1142 const playerHandle = worker.world.ecs.handleOf(playerId);
1141 1143 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1142 playerPos.tileX = npcPos.tileX;
1144 playerPos.tileX = npcPos.tileX - 1;
1143 1145 playerPos.tileY = npcPos.tileY;
1144 1146
1145 1147 const letterSlot = harness.simulation.bagOf(playerId).inventory
@@ -1236,7 +1238,7 @@ test("vendor bought dye stays split by colour and resells that colour", () =>
1236 1238 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1237 1239 const playerHandle = worker.world.ecs.handleOf(playerId);
1238 1240 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1239 playerPos.tileX = npcPos.tileX;
1241 playerPos.tileX = npcPos.tileX - 1;
1240 1242 playerPos.tileY = npcPos.tileY;
1241 1243
1242 1244 for (const slotIndex of [1, 2])
@@ -104,7 +104,7 @@ test("buy paper from a shopkeeper with explicit catalog", () =>
104 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
104 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
105 const playerHandle = worker.world.ecs.handleOf(playerId);
105 const playerHandle = worker.world.ecs.handleOf(playerId);
106 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
106 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
107 playerPos.tileX = npcPos.tileX;
107 playerPos.tileX = npcPos.tileX - 1;
108 playerPos.tileY = npcPos.tileY;
108 playerPos.tileY = npcPos.tileY;
109
109
110 harness.simulation.enqueue(1, {
110 harness.simulation.enqueue(1, {
@@ -308,7 +308,7 @@ test("shopkeeper with buysItems accepts paper from the player", () =>
308 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
308 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
309 const playerHandle = worker.world.ecs.handleOf(playerId);
309 const playerHandle = worker.world.ecs.handleOf(playerId);
310 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
310 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
311 playerPos.tileX = npcPos.tileX;
311 playerPos.tileX = npcPos.tileX - 1;
312 playerPos.tileY = npcPos.tileY;
312 playerPos.tileY = npcPos.tileY;
313
313
314 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
314 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
@@ -405,7 +405,7 @@ test("buy copper ore from a spawned shopkeeper", () =>
405 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
405 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
406 const playerHandle = worker.world.ecs.handleOf(playerId);
406 const playerHandle = worker.world.ecs.handleOf(playerId);
407 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
407 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
408 playerPos.tileX = npcPos.tileX;
408 playerPos.tileX = npcPos.tileX - 1;
409 playerPos.tileY = npcPos.tileY;
409 playerPos.tileY = npcPos.tileY;
410
410
411 harness.simulation.enqueue(1, {
411 harness.simulation.enqueue(1, {
@@ -522,7 +522,7 @@ test("shop overflow goes to bank vault when inventory is full", () =>
522 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
522 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
523 const playerHandle = worker.world.ecs.handleOf(playerId);
523 const playerHandle = worker.world.ecs.handleOf(playerId);
524 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
524 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
525 playerPos.tileX = npcPos.tileX;
525 playerPos.tileX = npcPos.tileX - 1;
526 playerPos.tileY = npcPos.tileY;
526 playerPos.tileY = npcPos.tileY;
527
527
528 harness.simulation.enqueue(1, {
528 harness.simulation.enqueue(1, {
@@ -596,7 +596,7 @@ test("buysItems refills limited catalog then stores extras for 120% resale", ()
596 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
596 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
597 const playerHandle = worker.world.ecs.handleOf(playerId);
597 const playerHandle = worker.world.ecs.handleOf(playerId);
598 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
598 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
599 playerPos.tileX = npcPos.tileX;
599 playerPos.tileX = npcPos.tileX - 1;
600 playerPos.tileY = npcPos.tileY;
600 playerPos.tileY = npcPos.tileY;
601
601
602 // Fund coins and buy out limited stock first.
602 // Fund coins and buy out limited stock first.
@@ -754,10 +754,12 @@ test("shopkeeper stops wandering while a player has the shop open", () =>
754 }
754 }
755 assert.ok(npc);
755 assert.ok(npc);
756
756
757 const npcStartX = npc.position.tileX;
758 const npcStartY = npc.position.tileY;
757 const playerHandle = worker.world.ecs.handleOf(playerId);
759 const playerHandle = worker.world.ecs.handleOf(playerId);
758 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
760 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
759 playerPos.tileX = npc.position.tileX;
761 playerPos.tileX = npcStartX - 1;
760 playerPos.tileY = npc.position.tileY;
762 playerPos.tileY = npcStartY;
761
763
762 harness.simulation.enqueue(1, {
764 harness.simulation.enqueue(1, {
763 type: "interact",
765 type: "interact",
@@ -772,8 +774,8 @@ test("shopkeeper stops wandering while a player has the shop open", () =>
772 for (let i = 0; i < 20; i++)
774 for (let i = 0; i < 20; i++)
773 { harness.simulation.step(); }
775 { harness.simulation.step(); }
774 assert.equal(npc.path.tiles.length, 0);
776 assert.equal(npc.path.tiles.length, 0);
775 assert.equal(npc.position.tileX, playerPos.tileX);
777 assert.equal(npc.position.tileX, npcStartX);
776 assert.equal(npc.position.tileY, playerPos.tileY);
778 assert.equal(npc.position.tileY, npcStartY);
777
779
778 harness.simulation.enqueue(1, {
780 harness.simulation.enqueue(1, {
779 type: "close-shop",
781 type: "close-shop",
@@ -841,7 +843,7 @@ test("buysItems accepts non-ingredient tools like sticks", () =>
841 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
843 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
842 const playerHandle = worker.world.ecs.handleOf(playerId);
844 const playerHandle = worker.world.ecs.handleOf(playerId);
843 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
845 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
844 playerPos.tileX = npcPos.tileX;
846 playerPos.tileX = npcPos.tileX - 1;
845 playerPos.tileY = npcPos.tileY;
847 playerPos.tileY = npcPos.tileY;
846
848
847 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
849 const beforeCoins = countCoinsInSlots(worker.world.ecs.get(playerHandle, Component.inventory).slots);
@@ -944,7 +946,7 @@ test("selling a filled cheque pays reserved-goods price minus 5% admin fee", ()
944 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
946 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
945 const playerHandle = worker.world.ecs.handleOf(playerId);
947 const playerHandle = worker.world.ecs.handleOf(playerId);
946 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
948 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
947 playerPos.tileX = npcPos.tileX;
949 playerPos.tileX = npcPos.tileX - 1;
948 playerPos.tileY = npcPos.tileY;
950 playerPos.tileY = npcPos.tileY;
949
951
950 const quote = resolveShopSellQuote(bag.inventory[chequeIndex]);
952 const quote = resolveShopSellQuote(bag.inventory[chequeIndex]);
@@ -1032,7 +1034,7 @@ test("resale stock keeps the seller origin instead of Bought from NPC", () =>
1032 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1034 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1033 const playerHandle = worker.world.ecs.handleOf(playerId);
1035 const playerHandle = worker.world.ecs.handleOf(playerId);
1034 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1036 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1035 playerPos.tileX = npcPos.tileX;
1037 playerPos.tileX = npcPos.tileX - 1;
1036 playerPos.tileY = npcPos.tileY;
1038 playerPos.tileY = npcPos.tileY;
1037
1039
1038 harness.simulation.enqueue(1, {
1040 harness.simulation.enqueue(1, {
@@ -1139,7 +1141,7 @@ test("NPC letter sales pay out and destroy the letter without stock", () =>
1139 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1141 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1140 const playerHandle = worker.world.ecs.handleOf(playerId);
1142 const playerHandle = worker.world.ecs.handleOf(playerId);
1141 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1143 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1142 playerPos.tileX = npcPos.tileX;
1144 playerPos.tileX = npcPos.tileX - 1;
1143 playerPos.tileY = npcPos.tileY;
1145 playerPos.tileY = npcPos.tileY;
1144
1146
1145 const letterSlot = harness.simulation.bagOf(playerId).inventory
1147 const letterSlot = harness.simulation.bagOf(playerId).inventory
@@ -1236,7 +1238,7 @@ test("vendor bought dye stays split by colour and resells that colour", () =>
1236 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1238 const npcPos = worker.world.ecs.get(npcHandle, Component.position);
1237 const playerHandle = worker.world.ecs.handleOf(playerId);
1239 const playerHandle = worker.world.ecs.handleOf(playerId);
1238 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1240 const playerPos = worker.world.ecs.get(playerHandle, Component.position);
1239 playerPos.tileX = npcPos.tileX;
1241 playerPos.tileX = npcPos.tileX - 1;
1240 playerPos.tileY = npcPos.tileY;
1242 playerPos.tileY = npcPos.tileY;
1241
1243
1242 for (const slotIndex of [1, 2])
1244 for (const slotIndex of [1, 2])
shared/navigation/adjacency.js added +32 −0
@@ -0,0 +1,32 @@
1 /** Chebyshev distance between tile centres (0 = same tile). */
2 export function chebyshevTileDistance (ax, ay, bx, by)
3 {
4 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
5 }
6
7 /** Orthogonal or diagonal neighbour — not the same tile. Block interaction range. */
8 export function isAdjacentTile (ax, ay, bx, by)
9 {
10 return chebyshevTileDistance(ax, ay, bx, by) === 1;
11 }
12
13 export function isSameTile (ax, ay, bx, by)
14 {
15 return ax === bx && ay === by;
16 }
17
18 /** True when blockType exists on a tile adjacent to (tileX, tileY), not on that tile. */
19 export function hasAdjacentBlockType (getBlockTypeAt, tileX, tileY, blockType)
20 {
21 for (let dy = -1; dy <= 1; dy++)
22 {
23 for (let dx = -1; dx <= 1; dx++)
24 {
25 if (dx === 0 && dy === 0)
26 { continue; }
27 if (getBlockTypeAt(tileX + dx, tileY + dy) === blockType)
28 { return true; }
29 }
30 }
31 return false;
32 }
@@ -0,0 +1,32 @@
1/** Chebyshev distance between tile centres (0 = same tile). */
2export function chebyshevTileDistance (ax, ay, bx, by)
3{
4 return Math.max(Math.abs(ax - bx), Math.abs(ay - by));
5}
6
7/** Orthogonal or diagonal neighbour — not the same tile. Block interaction range. */
8export function isAdjacentTile (ax, ay, bx, by)
9{
10 return chebyshevTileDistance(ax, ay, bx, by) === 1;
11}
12
13export function isSameTile (ax, ay, bx, by)
14{
15 return ax === bx && ay === by;
16}
17
18/** True when blockType exists on a tile adjacent to (tileX, tileY), not on that tile. */
19export function hasAdjacentBlockType (getBlockTypeAt, tileX, tileY, blockType)
20{
21 for (let dy = -1; dy <= 1; dy++)
22 {
23 for (let dx = -1; dx <= 1; dx++)
24 {
25 if (dx === 0 && dy === 0)
26 { continue; }
27 if (getBlockTypeAt(tileX + dx, tileY + dy) === blockType)
28 { return true; }
29 }
30 }
31 return false;
32}