Make debark a 2s axe gather and ignore UI-drag world clicks.
Debarking now uses the gather swing loop with the axe overlay like chopping. Left-clicks that start or continue over UI (inventory/spell bar) are absorbed so dragging out of a panel no longer issues a move order.
@@ -1545,7 +1545,13 @@ function startPlay (payload)
1545
1545
const leftHeld = GameInput.mouseHeld(GameInput.MouseButtons.Left);
1546
1546
if (!leftPressed && !leftHeld)
1547
1547
{ leftClickConsumed = false; }
1548
else if (!leftClickConsumed && playing && !uiBlocked())
1548
else if (uiBlocked())
1549
{
1550
// Absorb presses that begin (or continue) over UI so dragging out of a
1551
// panel does not issue a world move/order on the same mouse hold.
1552
leftClickConsumed = true;
1553
}
1554
else if (!leftClickConsumed && playing)
1549
1555
{
1550
1556
leftClickConsumed = true;
1551
1557
const canvas = scene.canvas;
@@ -1545,7 +1545,13 @@ function startPlay (payload)1545
const leftHeld = GameInput.mouseHeld(GameInput.MouseButtons.Left);1545
const leftHeld = GameInput.mouseHeld(GameInput.MouseButtons.Left);1546
if (!leftPressed && !leftHeld)1546
if (!leftPressed && !leftHeld)1547
{ leftClickConsumed = false; }1547
{ leftClickConsumed = false; }1548
else if (!leftClickConsumed && playing && !uiBlocked())1548
else if (uiBlocked())1549
{1550
// Absorb presses that begin (or continue) over UI so dragging out of a1551
// panel does not issue a world move/order on the same mouse hold.1552
leftClickConsumed = true;1553
}1554
else if (!leftClickConsumed && playing)1549
{1555
{1550
leftClickConsumed = true;1556
leftClickConsumed = true;1551
const canvas = scene.canvas;1557
const canvas = scene.canvas;@@ -1,162 +1,14 @@
1
import { Component } from "../ecs/components.js";
2
import {
3
barkItemIdForWood,
4
debarkedLogInstance,
5
isLogDebarked
6
} from "../../../shared/definitions/woodItems.js";
7
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
8
import { itemDefinition } from "../../../shared/definitions/items.js";
9
import { resolveWoodcuttingAxe } from "../../../shared/definitions/gathering.js";
10
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
11
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
12
import { attachOrigins, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";
13
import { stackQuantity } from "../../../shared/items/inventory.js";
1
import { startDebark } from "../gathering/service.js";
14
2
15
function userError (message)
16
{
17
const error = new Error(message);
18
error.userFacing = true;
19
return error;
20
}
21
22
function characterDisplayName (world, handle)
23
{
24
const appearance = world.ecs.get(handle, Component.appearance);
25
const name = [appearance?.firstName, appearance?.lastName].filter(Boolean).join(" ").trim();
26
return name || "someone";
27
}
28
29
function woodTierFromLogItemId (itemId)
30
{
31
const def = itemDefinition(itemId);
32
if (!def || def.familyId !== ItemFamilyId.log)
33
{ return null; }
34
return def.tier ?? null;
35
}
36
37
function axeForWood (world, handle, woodTier)
38
{
39
const inventory = world.ecs.get(handle, Component.inventory);
40
const equipment = world.ecs.get(handle, Component.equipment);
41
const skills = world.ecs.get(handle, Component.skills);
42
return resolveWoodcuttingAxe({
43
inventorySlots: inventory?.slots,
44
equipmentSlots: equipment?.slots,
45
skills,
46
woodTier
47
});
48
}
49
50
function publishGround (item)
51
{
52
return {
53
type: "ground-item-appear",
54
...publicGroundItem(item),
55
stack: item.stack,
56
droppedAt: item.droppedAt,
57
source: item.source,
58
droppedByCharacterId: item.droppedByCharacterId,
59
expiresAt: item.expiresAt
60
};
61
}
62
63
/**
64
* Strip bark from a ground wood log. Requires an axe of the same tier gate as chopping
65
* that wood. Leaves a debarked log (same itemId + instance flag) and bark.
66
*/
3
/** @deprecated Prefer gather command routing; kept for direct tests / imports. */
67
4
export function debarkLog (world, sessionId, characterId, groundItemId, now = Date.now())
68
5
{
69
const { handle } = world.requireOwnedEntity(sessionId, characterId);
70
const item = world.groundItems.get(groundItemId);
71
if (!item?.stack)
72
{ throw userError("That item is no longer on the ground."); }
73
74
const woodTier = woodTierFromLogItemId(item.stack.itemId);
75
if (!woodTier)
76
{ throw userError("That is not a log."); }
77
if (isLogDebarked(item.stack))
78
{ throw userError("That log is already stripped of bark."); }
79
80
const position = world.ecs.get(handle, Component.position);
81
if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY)
82
&& !(position.tileX === item.tileX && position.tileY === item.tileY))
83
{ throw userError("Stand next to the log."); }
84
85
const axe = axeForWood(world, handle, woodTier);
86
if (!axe.ok)
87
{ throw userError(axe.reason || "You need an axe to strip this bark."); }
88
89
const barkId = barkItemIdForWood(woodTier);
90
if (barkId == null)
91
{ throw userError("That bark cannot be stripped."); }
92
93
const qty = stackQuantity(item.stack.quantity);
94
if (qty <= 0)
95
{ throw userError("That item is no longer on the ground."); }
96
97
const events = [];
98
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;
99
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));
100
const debarkedStack = attachOrigins({
101
itemId: item.stack.itemId,
102
quantity: 1,
103
instance: debarkedLogInstance(),
104
origins: item.stack.origins ?? []
105
});
106
107
if (qty === 1)
108
{
109
item.stack = debarkedStack;
110
events.push(publishGround(item));
111
}
112
else
113
{
114
item.stack = {
115
...item.stack,
116
quantity: qty - 1
117
};
118
events.push(publishGround(item));
119
120
const debarkedItem = {
121
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
122
tileX: item.tileX,
123
tileY: item.tileY,
124
stack: debarkedStack,
125
droppedAt: now,
126
expiresAt: now + despawnMs,
127
source: "debark",
128
droppedByCharacterId: characterId
129
};
130
addGroundItem(world, debarkedItem);
131
events.push(publishGround(debarkedItem));
132
}
133
134
const barkItem = {
135
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
136
tileX: item.tileX,
137
tileY: item.tileY,
138
stack: attachOrigins({
139
itemId: barkId,
140
quantity: 1,
141
origins: [{ origin, quantity: 1 }]
142
}),
143
droppedAt: now,
144
expiresAt: now + despawnMs,
145
source: "debark",
146
droppedByCharacterId: characterId
147
};
148
addGroundItem(world, barkItem);
149
events.push(publishGround(barkItem));
150
151
return {
152
events,
153
private: bagView(world.ecs, handle)
154
};
6
return startDebark(world, sessionId, characterId, groundItemId, now);
155
7
}
156
8
157
9
export function handleDebarkCommand (world, sessionId, command, now = Date.now())
158
10
{
159
11
if (command.type !== "debark-log")
160
12
{ return null; }
161
return debarkLog(world, sessionId, command.characterId, command.groundItemId, now);
13
return startDebark(world, sessionId, command.characterId, command.groundItemId, now);
162
14
}
@@ -1,162 +1,14 @@1
import { Component } from "../ecs/components.js";1
import { startDebark } from "../gathering/service.js";2
import {3
barkItemIdForWood,4
debarkedLogInstance,5
isLogDebarked6
} from "../../../shared/definitions/woodItems.js";7
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";8
import { itemDefinition } from "../../../shared/definitions/items.js";9
import { resolveWoodcuttingAxe } from "../../../shared/definitions/gathering.js";10
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";11
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";12
import { attachOrigins, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";13
import { stackQuantity } from "../../../shared/items/inventory.js";14
2
15
function userError (message)3
/** @deprecated Prefer gather command routing; kept for direct tests / imports. */16
{17
const error = new Error(message);18
error.userFacing = true;19
return error;20
}21
22
function characterDisplayName (world, handle)23
{24
const appearance = world.ecs.get(handle, Component.appearance);25
const name = [appearance?.firstName, appearance?.lastName].filter(Boolean).join(" ").trim();26
return name || "someone";27
}28
29
function woodTierFromLogItemId (itemId)30
{31
const def = itemDefinition(itemId);32
if (!def || def.familyId !== ItemFamilyId.log)33
{ return null; }34
return def.tier ?? null;35
}36
37
function axeForWood (world, handle, woodTier)38
{39
const inventory = world.ecs.get(handle, Component.inventory);40
const equipment = world.ecs.get(handle, Component.equipment);41
const skills = world.ecs.get(handle, Component.skills);42
return resolveWoodcuttingAxe({43
inventorySlots: inventory?.slots,44
equipmentSlots: equipment?.slots,45
skills,46
woodTier47
});48
}49
50
function publishGround (item)51
{52
return {53
type: "ground-item-appear",54
...publicGroundItem(item),55
stack: item.stack,56
droppedAt: item.droppedAt,57
source: item.source,58
droppedByCharacterId: item.droppedByCharacterId,59
expiresAt: item.expiresAt60
};61
}62
63
/**64
* Strip bark from a ground wood log. Requires an axe of the same tier gate as chopping65
* that wood. Leaves a debarked log (same itemId + instance flag) and bark.66
*/67
export function debarkLog (world, sessionId, characterId, groundItemId, now = Date.now())4
export function debarkLog (world, sessionId, characterId, groundItemId, now = Date.now())68
{5
{69
const { handle } = world.requireOwnedEntity(sessionId, characterId);6
return startDebark(world, sessionId, characterId, groundItemId, now);70
const item = world.groundItems.get(groundItemId);71
if (!item?.stack)72
{ throw userError("That item is no longer on the ground."); }73
74
const woodTier = woodTierFromLogItemId(item.stack.itemId);75
if (!woodTier)76
{ throw userError("That is not a log."); }77
if (isLogDebarked(item.stack))78
{ throw userError("That log is already stripped of bark."); }79
80
const position = world.ecs.get(handle, Component.position);81
if (!isAdjacentTile(position.tileX, position.tileY, item.tileX, item.tileY)82
&& !(position.tileX === item.tileX && position.tileY === item.tileY))83
{ throw userError("Stand next to the log."); }84
85
const axe = axeForWood(world, handle, woodTier);86
if (!axe.ok)87
{ throw userError(axe.reason || "You need an axe to strip this bark."); }88
89
const barkId = barkItemIdForWood(woodTier);90
if (barkId == null)91
{ throw userError("That bark cannot be stripped."); }92
93
const qty = stackQuantity(item.stack.quantity);94
if (qty <= 0)95
{ throw userError("That item is no longer on the ground."); }96
97
const events = [];98
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;99
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));100
const debarkedStack = attachOrigins({101
itemId: item.stack.itemId,102
quantity: 1,103
instance: debarkedLogInstance(),104
origins: item.stack.origins ?? []105
});106
107
if (qty === 1)108
{109
item.stack = debarkedStack;110
events.push(publishGround(item));111
}112
else113
{114
item.stack = {115
...item.stack,116
quantity: qty - 1117
};118
events.push(publishGround(item));119
120
const debarkedItem = {121
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),122
tileX: item.tileX,123
tileY: item.tileY,124
stack: debarkedStack,125
droppedAt: now,126
expiresAt: now + despawnMs,127
source: "debark",128
droppedByCharacterId: characterId129
};130
addGroundItem(world, debarkedItem);131
events.push(publishGround(debarkedItem));132
}133
134
const barkItem = {135
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),136
tileX: item.tileX,137
tileY: item.tileY,138
stack: attachOrigins({139
itemId: barkId,140
quantity: 1,141
origins: [{ origin, quantity: 1 }]142
}),143
droppedAt: now,144
expiresAt: now + despawnMs,145
source: "debark",146
droppedByCharacterId: characterId147
};148
addGroundItem(world, barkItem);149
events.push(publishGround(barkItem));150
151
return {152
events,153
private: bagView(world.ecs, handle)154
};155
}7
}156
8
157
export function handleDebarkCommand (world, sessionId, command, now = Date.now())9
export function handleDebarkCommand (world, sessionId, command, now = Date.now())158
{10
{159
if (command.type !== "debark-log")11
if (command.type !== "debark-log")160
{ return null; }12
{ return null; }161
return debarkLog(world, sessionId, command.characterId, command.groundItemId, now);13
return startDebark(world, sessionId, command.characterId, command.groundItemId, now);162
}14
}@@ -32,8 +32,8 @@ import {
32
32
randomFlowerColorId
33
33
} from "../../../shared/definitions/dyes.js";
34
34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";
35
import { insertStack } from "../../../shared/items/inventory.js";
36
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";
35
import { insertStack, stackQuantity } from "../../../shared/items/inventory.js";
36
import { attachOrigins, GatherOriginVerb, gatherOrigin, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";
37
37
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";
38
38
import
39
39
{
@@ -46,13 +46,21 @@ import {
46
46
SeasonId,
47
47
scaleRegrowDurationMs
48
48
} from "../../../shared/world/season.js";
49
import { bagView } from "../items/bags.js";
49
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";
50
50
import { clearEngage } from "../combat/service.js";
51
51
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";
52
52
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
53
53
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
54
import {
55
barkItemIdForWood,
56
debarkedLogInstance,
57
isLogDebarked
58
} from "../../../shared/definitions/woodItems.js";
59
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";
54
60
55
61
const GATHER_SWING_INTERVAL_MS = 900;
62
/** Fixed strip duration — short axe work on a felled log. */
63
export const DEBARK_DURATION_MS = 2000;
56
64
57
65
function userError (message)
58
66
{
@@ -452,6 +460,85 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)
452
460
}, now);
453
461
}
454
462
463
function woodTierFromLogItemId (itemId)
464
{
465
const def = itemDefinition(itemId);
466
if (!def || def.familyId !== ItemFamilyId.log)
467
{ return null; }
468
return def.tier ?? null;
469
}
470
471
function nearDebarkTarget (position, tileX, tileY)
472
{
473
return isAdjacentTile(position.tileX, position.tileY, tileX, tileY)
474
|| (position.tileX === tileX && position.tileY === tileY);
475
}
476
477
function publishGroundItem (item)
478
{
479
return {
480
type: "ground-item-appear",
481
...publicGroundItem(item),
482
stack: item.stack,
483
droppedAt: item.droppedAt,
484
source: item.source,
485
droppedByCharacterId: item.droppedByCharacterId,
486
expiresAt: item.expiresAt
487
};
488
}
489
490
/**
491
* Start stripping bark from a ground log (2s axe swings, then bark + debarked flag).
492
*/
493
export function startDebark (world, sessionId, characterId, groundItemId, now)
494
{
495
const entityId = world.characterEntities.get(characterId);
496
if (entityId == null)
497
{ throw userError("Character is not in the world."); }
498
const handle = world.ecs.handleOf(entityId);
499
const identity = world.ecs.get(handle, Component.networkIdentity);
500
if (!identity || identity.sessionId !== sessionId)
501
{ throw userError("Character is not in the world."); }
502
if (world.ecs.has(handle, Component.dead))
503
{ throw userError("You are dead."); }
504
505
const item = world.groundItems.get(groundItemId);
506
if (!item?.stack)
507
{ throw userError("That item is no longer on the ground."); }
508
509
const woodTier = woodTierFromLogItemId(item.stack.itemId);
510
if (!woodTier)
511
{ throw userError("That is not a log."); }
512
if (isLogDebarked(item.stack))
513
{ throw userError("That log is already stripped of bark."); }
514
515
const position = world.ecs.get(handle, Component.position);
516
if (!nearDebarkTarget(position, item.tileX, item.tileY))
517
{ throw userError("Stand next to the log."); }
518
519
const axe = axeForWood(world, handle, woodTier);
520
if (!axe.ok)
521
{ throw userError(axe.reason || "You need an axe to strip this bark."); }
522
523
const barkId = barkItemIdForWood(woodTier);
524
if (barkId == null)
525
{ throw userError("That bark cannot be stripped."); }
526
527
const toolItemId = axe.tool.stack?.itemId ?? null;
528
return beginGatherSwing(world, handle, entityId, position, {
529
kind: "debark",
530
tileX: item.tileX,
531
tileY: item.tileY,
532
groundItemId,
533
woodTier,
534
logItemId: item.stack.itemId,
535
barkItemId: barkId,
536
toolTier: axe.tool.tier,
537
toolItemId,
538
durationMs: DEBARK_DURATION_MS
539
}, now);
540
}
541
455
542
/**
456
543
* Pick a plant node (flower / cotton; no tools required).
457
544
*/
@@ -718,6 +805,90 @@ function completeWoodcutting (world, handle, entityId, character, gather, events
718
805
});
719
806
}
720
807
808
function completeDebark (world, handle, entityId, character, gather, events, privates, now)
809
{
810
const item = world.groundItems.get(gather.groundItemId);
811
if (!item?.stack
812
|| (item.stack.itemId | 0) !== (gather.logItemId | 0)
813
|| isLogDebarked(item.stack)
814
|| item.tileX !== gather.tileX
815
|| item.tileY !== gather.tileY)
816
{
817
clearGather(world.ecs, handle);
818
return;
819
}
820
821
const qty = stackQuantity(item.stack.quantity);
822
if (qty <= 0)
823
{
824
clearGather(world.ecs, handle);
825
return;
826
}
827
828
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));
829
const debarkedStack = attachOrigins({
830
itemId: item.stack.itemId,
831
quantity: 1,
832
instance: debarkedLogInstance(),
833
origins: item.stack.origins ?? []
834
});
835
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;
836
837
if (qty === 1)
838
{
839
item.stack = debarkedStack;
840
events.push(publishGroundItem(item));
841
}
842
else
843
{
844
item.stack = {
845
...item.stack,
846
quantity: qty - 1
847
};
848
events.push(publishGroundItem(item));
849
850
const debarkedItem = {
851
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
852
tileX: item.tileX,
853
tileY: item.tileY,
854
stack: debarkedStack,
855
droppedAt: now,
856
expiresAt: now + despawnMs,
857
source: "debark",
858
droppedByCharacterId: character.characterId
859
};
860
addGroundItem(world, debarkedItem);
861
events.push(publishGroundItem(debarkedItem));
862
}
863
864
const barkItem = {
865
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),
866
tileX: item.tileX,
867
tileY: item.tileY,
868
stack: attachOrigins({
869
itemId: gather.barkItemId,
870
quantity: 1,
871
origins: [{ origin, quantity: 1 }]
872
}),
873
droppedAt: now,
874
expiresAt: now + despawnMs,
875
source: "debark",
876
droppedByCharacterId: character.characterId
877
};
878
addGroundItem(world, barkItem);
879
events.push(publishGroundItem(barkItem));
880
881
clearGather(world.ecs, handle);
882
pushBagUpdate(events, privates, world, handle, entityId, character, false, null, []);
883
events.push({
884
type: "gather-complete",
885
characterId: character.characterId,
886
kind: "debark",
887
woodTier: gather.woodTier,
888
itemId: gather.barkItemId
889
});
890
}
891
721
892
function completePlant (world, handle, entityId, character, gather, events, privates, now)
722
893
{
723
894
const inventory = world.ecs.get(handle, Component.inventory);
@@ -849,7 +1020,10 @@ export function stepGather (world, now)
849
1020
clearGather(world.ecs, handle);
850
1021
continue;
851
1022
}
852
if (!isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY))
1023
const nearTarget = gather.kind === "debark"
1024
? nearDebarkTarget(position, gather.tileX, gather.tileY)
1025
: isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY);
1026
if (!nearTarget)
853
1027
{
854
1028
clearGather(world.ecs, handle);
855
1029
continue;
@@ -881,6 +1055,19 @@ export function stepGather (world, now)
881
1055
continue;
882
1056
}
883
1057
}
1058
else if (gather.kind === "debark")
1059
{
1060
const item = world.groundItems.get(gather.groundItemId);
1061
if (!item?.stack
1062
|| (item.stack.itemId | 0) !== (gather.logItemId | 0)
1063
|| isLogDebarked(item.stack)
1064
|| item.tileX !== gather.tileX
1065
|| item.tileY !== gather.tileY)
1066
{
1067
clearGather(world.ecs, handle);
1068
continue;
1069
}
1070
}
884
1071
else
885
1072
{
886
1073
clearGather(world.ecs, handle);
@@ -909,6 +1096,8 @@ export function stepGather (world, now)
909
1096
{ completeMining(world, handle, entityId, character, gather, events, privates, now); }
910
1097
else if (gather.kind === "woodcutting")
911
1098
{ completeWoodcutting(world, handle, entityId, character, gather, events, privates, now); }
1099
else if (gather.kind === "debark")
1100
{ completeDebark(world, handle, entityId, character, gather, events, privates, now); }
912
1101
else
913
1102
{ completePlant(world, handle, entityId, character, gather, events, privates, now); }
914
1103
}
@@ -925,6 +1114,8 @@ export function handleGatherCommand (world, sessionId, command, now)
925
1114
return startChop(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);
926
1115
case "pick":
927
1116
return startPick(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);
1117
case "debark-log":
1118
return startDebark(world, sessionId, command.characterId, command.groundItemId | 0, now);
928
1119
case "cancel-gather":
929
1120
{
930
1121
const entityId = world.characterEntities.get(command.characterId);
@@ -32,8 +32,8 @@ import {32
randomFlowerColorId32
randomFlowerColorId33
} from "../../../shared/definitions/dyes.js";33
} from "../../../shared/definitions/dyes.js";34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";34
import { herbDefinition, isHerbId } from "../../../shared/definitions/herbs.js";35
import { insertStack } from "../../../shared/items/inventory.js";35
import { insertStack, stackQuantity } from "../../../shared/items/inventory.js";36
import { attachOrigins, GatherOriginVerb, gatherOrigin } from "../../../shared/items/origin.js";36
import { attachOrigins, GatherOriginVerb, gatherOrigin, craftOrigin, CraftOriginVerb } from "../../../shared/items/origin.js";37
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";37
import { applySkillXp, publicSkillsPayload, storedSkillXp } from "../../../shared/skills/state.js";38
import38
import39
{39
{@@ -46,13 +46,21 @@ import {46
SeasonId,46
SeasonId,47
scaleRegrowDurationMs47
scaleRegrowDurationMs48
} from "../../../shared/world/season.js";48
} from "../../../shared/world/season.js";49
import { bagView } from "../items/bags.js";49
import { bagView, addGroundItem, publicGroundItem } from "../items/bags.js";50
import { clearEngage } from "../combat/service.js";50
import { clearEngage } from "../combat/service.js";51
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";51
import { isAdjacentTile } from "../../../shared/navigation/adjacency.js";52
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";52
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";53
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";53
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";54
import {55
barkItemIdForWood,56
debarkedLogInstance,57
isLogDebarked58
} from "../../../shared/definitions/woodItems.js";59
import { ItemFamilyId } from "../../../shared/definitions/tierFamilies.js";54
60
55
const GATHER_SWING_INTERVAL_MS = 900;61
const GATHER_SWING_INTERVAL_MS = 900;62
/** Fixed strip duration — short axe work on a felled log. */63
export const DEBARK_DURATION_MS = 2000;56
64
57
function userError (message)65
function userError (message)58
{66
{@@ -452,6 +460,85 @@ export function startChop (world, sessionId, characterId, tileX, tileY, now)452
}, now);460
}, now);453
}461
}454
462
463
function woodTierFromLogItemId (itemId)464
{465
const def = itemDefinition(itemId);466
if (!def || def.familyId !== ItemFamilyId.log)467
{ return null; }468
return def.tier ?? null;469
}470
471
function nearDebarkTarget (position, tileX, tileY)472
{473
return isAdjacentTile(position.tileX, position.tileY, tileX, tileY)474
|| (position.tileX === tileX && position.tileY === tileY);475
}476
477
function publishGroundItem (item)478
{479
return {480
type: "ground-item-appear",481
...publicGroundItem(item),482
stack: item.stack,483
droppedAt: item.droppedAt,484
source: item.source,485
droppedByCharacterId: item.droppedByCharacterId,486
expiresAt: item.expiresAt487
};488
}489
490
/**491
* Start stripping bark from a ground log (2s axe swings, then bark + debarked flag).492
*/493
export function startDebark (world, sessionId, characterId, groundItemId, now)494
{495
const entityId = world.characterEntities.get(characterId);496
if (entityId == null)497
{ throw userError("Character is not in the world."); }498
const handle = world.ecs.handleOf(entityId);499
const identity = world.ecs.get(handle, Component.networkIdentity);500
if (!identity || identity.sessionId !== sessionId)501
{ throw userError("Character is not in the world."); }502
if (world.ecs.has(handle, Component.dead))503
{ throw userError("You are dead."); }504
505
const item = world.groundItems.get(groundItemId);506
if (!item?.stack)507
{ throw userError("That item is no longer on the ground."); }508
509
const woodTier = woodTierFromLogItemId(item.stack.itemId);510
if (!woodTier)511
{ throw userError("That is not a log."); }512
if (isLogDebarked(item.stack))513
{ throw userError("That log is already stripped of bark."); }514
515
const position = world.ecs.get(handle, Component.position);516
if (!nearDebarkTarget(position, item.tileX, item.tileY))517
{ throw userError("Stand next to the log."); }518
519
const axe = axeForWood(world, handle, woodTier);520
if (!axe.ok)521
{ throw userError(axe.reason || "You need an axe to strip this bark."); }522
523
const barkId = barkItemIdForWood(woodTier);524
if (barkId == null)525
{ throw userError("That bark cannot be stripped."); }526
527
const toolItemId = axe.tool.stack?.itemId ?? null;528
return beginGatherSwing(world, handle, entityId, position, {529
kind: "debark",530
tileX: item.tileX,531
tileY: item.tileY,532
groundItemId,533
woodTier,534
logItemId: item.stack.itemId,535
barkItemId: barkId,536
toolTier: axe.tool.tier,537
toolItemId,538
durationMs: DEBARK_DURATION_MS539
}, now);540
}541
455
/**542
/**456
* Pick a plant node (flower / cotton; no tools required).543
* Pick a plant node (flower / cotton; no tools required).457
*/544
*/@@ -718,6 +805,90 @@ function completeWoodcutting (world, handle, entityId, character, gather, events718
});805
});719
}806
}720
807
808
function completeDebark (world, handle, entityId, character, gather, events, privates, now)809
{810
const item = world.groundItems.get(gather.groundItemId);811
if (!item?.stack812
|| (item.stack.itemId | 0) !== (gather.logItemId | 0)813
|| isLogDebarked(item.stack)814
|| item.tileX !== gather.tileX815
|| item.tileY !== gather.tileY)816
{817
clearGather(world.ecs, handle);818
return;819
}820
821
const qty = stackQuantity(item.stack.quantity);822
if (qty <= 0)823
{824
clearGather(world.ecs, handle);825
return;826
}827
828
const origin = craftOrigin(CraftOriginVerb.made, characterDisplayName(world, handle));829
const debarkedStack = attachOrigins({830
itemId: item.stack.itemId,831
quantity: 1,832
instance: debarkedLogInstance(),833
origins: item.stack.origins ?? []834
});835
const despawnMs = world.settings.groundItemDespawnDurationMs ?? 600_000;836
837
if (qty === 1)838
{839
item.stack = debarkedStack;840
events.push(publishGroundItem(item));841
}842
else843
{844
item.stack = {845
...item.stack,846
quantity: qty - 1847
};848
events.push(publishGroundItem(item));849
850
const debarkedItem = {851
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),852
tileX: item.tileX,853
tileY: item.tileY,854
stack: debarkedStack,855
droppedAt: now,856
expiresAt: now + despawnMs,857
source: "debark",858
droppedByCharacterId: character.characterId859
};860
addGroundItem(world, debarkedItem);861
events.push(publishGroundItem(debarkedItem));862
}863
864
const barkItem = {865
groundItemId: (world.nextGroundItemId = (world.nextGroundItemId ?? 1) + 1),866
tileX: item.tileX,867
tileY: item.tileY,868
stack: attachOrigins({869
itemId: gather.barkItemId,870
quantity: 1,871
origins: [{ origin, quantity: 1 }]872
}),873
droppedAt: now,874
expiresAt: now + despawnMs,875
source: "debark",876
droppedByCharacterId: character.characterId877
};878
addGroundItem(world, barkItem);879
events.push(publishGroundItem(barkItem));880
881
clearGather(world.ecs, handle);882
pushBagUpdate(events, privates, world, handle, entityId, character, false, null, []);883
events.push({884
type: "gather-complete",885
characterId: character.characterId,886
kind: "debark",887
woodTier: gather.woodTier,888
itemId: gather.barkItemId889
});890
}891
721
function completePlant (world, handle, entityId, character, gather, events, privates, now)892
function completePlant (world, handle, entityId, character, gather, events, privates, now)722
{893
{723
const inventory = world.ecs.get(handle, Component.inventory);894
const inventory = world.ecs.get(handle, Component.inventory);@@ -849,7 +1020,10 @@ export function stepGather (world, now)849
clearGather(world.ecs, handle);1020
clearGather(world.ecs, handle);850
continue;1021
continue;851
}1022
}852
if (!isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY))1023
const nearTarget = gather.kind === "debark"1024
? nearDebarkTarget(position, gather.tileX, gather.tileY)1025
: isAdjacentTile(position.tileX, position.tileY, gather.tileX, gather.tileY);1026
if (!nearTarget)853
{1027
{854
clearGather(world.ecs, handle);1028
clearGather(world.ecs, handle);855
continue;1029
continue;@@ -881,6 +1055,19 @@ export function stepGather (world, now)881
continue;1055
continue;882
}1056
}883
}1057
}1058
else if (gather.kind === "debark")1059
{1060
const item = world.groundItems.get(gather.groundItemId);1061
if (!item?.stack1062
|| (item.stack.itemId | 0) !== (gather.logItemId | 0)1063
|| isLogDebarked(item.stack)1064
|| item.tileX !== gather.tileX1065
|| item.tileY !== gather.tileY)1066
{1067
clearGather(world.ecs, handle);1068
continue;1069
}1070
}884
else1071
else885
{1072
{886
clearGather(world.ecs, handle);1073
clearGather(world.ecs, handle);@@ -909,6 +1096,8 @@ export function stepGather (world, now)909
{ completeMining(world, handle, entityId, character, gather, events, privates, now); }1096
{ completeMining(world, handle, entityId, character, gather, events, privates, now); }910
else if (gather.kind === "woodcutting")1097
else if (gather.kind === "woodcutting")911
{ completeWoodcutting(world, handle, entityId, character, gather, events, privates, now); }1098
{ completeWoodcutting(world, handle, entityId, character, gather, events, privates, now); }1099
else if (gather.kind === "debark")1100
{ completeDebark(world, handle, entityId, character, gather, events, privates, now); }912
else1101
else913
{ completePlant(world, handle, entityId, character, gather, events, privates, now); }1102
{ completePlant(world, handle, entityId, character, gather, events, privates, now); }914
}1103
}@@ -925,6 +1114,8 @@ export function handleGatherCommand (world, sessionId, command, now)925
return startChop(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);1114
return startChop(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);926
case "pick":1115
case "pick":927
return startPick(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);1116
return startPick(world, sessionId, command.characterId, command.tileX | 0, command.tileY | 0, now);1117
case "debark-log":1118
return startDebark(world, sessionId, command.characterId, command.groundItemId | 0, now);928
case "cancel-gather":1119
case "cancel-gather":929
{1120
{930
const entityId = world.characterEntities.get(command.characterId);1121
const entityId = world.characterEntities.get(command.characterId);@@ -53,7 +53,6 @@ import {
53
53
} from "../gathering/service.js";
54
54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";
55
55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";
56
import { handleDebarkCommand } from "../debark/service.js";
57
56
import { handleFishingCommand, stepFishing } from "../fishing/service.js";
58
57
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";
59
58
import { handleAlchemyCommand } from "../alchemy/service.js";
@@ -539,9 +538,6 @@ export class WorkerWorld
539
538
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());
540
539
if (fire)
541
540
{ return fire; }
542
const debark = handleDebarkCommand(this, sessionId, command, message.now ?? Date.now());
543
if (debark)
544
{ return debark; }
545
541
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());
546
542
if (fishing)
547
543
{ return fishing; }
@@ -53,7 +53,6 @@ import {53
} from "../gathering/service.js";53
} from "../gathering/service.js";54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";54
import { handleCraftCommand, stepCrafting } from "../crafting/service.js";55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";55
import { handleFirestartingCommand, stepFirestarting } from "../firestarting/service.js";56
import { handleDebarkCommand } from "../debark/service.js";57
import { handleFishingCommand, stepFishing } from "../fishing/service.js";56
import { handleFishingCommand, stepFishing } from "../fishing/service.js";58
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";57
import { handleShearingCommand, stepShearing, originIsBusyPinned } from "../shearing/service.js";59
import { handleAlchemyCommand } from "../alchemy/service.js";58
import { handleAlchemyCommand } from "../alchemy/service.js";@@ -539,9 +538,6 @@ export class WorkerWorld539
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());538
const fire = handleFirestartingCommand(this, sessionId, command, message.now ?? Date.now());540
if (fire)539
if (fire)541
{ return fire; }540
{ return fire; }542
const debark = handleDebarkCommand(this, sessionId, command, message.now ?? Date.now());543
if (debark)544
{ return debark; }545
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());541
const fishing = handleFishingCommand(this, sessionId, command, message.now ?? Date.now());546
if (fishing)542
if (fishing)547
{ return fishing; }543
{ return fishing; }@@ -122,6 +122,17 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
122
122
});
123
123
harness.simulation.step();
124
124
125
const handle = worker.world.ecs.handleOf(entityId);
126
const gather = worker.world.ecs.get(handle, Component.gather);
127
assert.equal(gather?.kind, "debark");
128
assert.equal(gather?.durationMs, 2000);
129
130
for (let i = 0; i < 50; i++)
131
{
132
harness.advance(50);
133
harness.simulation.step();
134
}
135
125
136
const item = worker.world.groundItems.get(groundItemId);
126
137
assert.ok(item);
127
138
assert.equal(isLogDebarked(item.stack), true);
@@ -131,6 +142,7 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>
131
142
.find((row) => row.stack?.itemId === WoodItemId.oakBark);
132
143
assert.ok(bark);
133
144
assert.equal(bark.stack.quantity, 1);
145
assert.equal(worker.world.ecs.has(handle, Component.gather), false);
134
146
}
135
147
finally
136
148
{ harness.close(); }
@@ -122,6 +122,17 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>122
});122
});123
harness.simulation.step();123
harness.simulation.step();124
124
125
const handle = worker.world.ecs.handleOf(entityId);126
const gather = worker.world.ecs.get(handle, Component.gather);127
assert.equal(gather?.kind, "debark");128
assert.equal(gather?.durationMs, 2000);129
130
for (let i = 0; i < 50; i++)131
{132
harness.advance(50);133
harness.simulation.step();134
}135
125
const item = worker.world.groundItems.get(groundItemId);136
const item = worker.world.groundItems.get(groundItemId);126
assert.ok(item);137
assert.ok(item);127
assert.equal(isLogDebarked(item.stack), true);138
assert.equal(isLogDebarked(item.stack), true);@@ -131,6 +142,7 @@ test("debark-log on ground oak log yields bark and debarked flag", () =>131
.find((row) => row.stack?.itemId === WoodItemId.oakBark);142
.find((row) => row.stack?.itemId === WoodItemId.oakBark);132
assert.ok(bark);143
assert.ok(bark);133
assert.equal(bark.stack.quantity, 1);144
assert.equal(bark.stack.quantity, 1);145
assert.equal(worker.world.ecs.has(handle, Component.gather), false);134
}146
}135
finally147
finally136
{ harness.close(); }148
{ harness.close(); }