Hand off duplicate logins and add leatherworking table interact.
Kick the previous client instead of blocking re-login on the same character instance; add click and context-menu crafting for leatherworking tables with server proximity checks.
@@ -647,6 +647,8 @@ function handleLeftClick (mouseX, mouseY)
647
647
{ requestOpenCraftStation(CraftingStationId.loom, tile.tileX, tile.tileY); }
648
648
else if (isTailorBenchTile(view, tile.tileX, tile.tileY))
649
649
{ requestOpenCraftStation(CraftingStationId.tailorBench, tile.tileX, tile.tileY); }
650
else if (isLeatherworkingTableTile(view, tile.tileX, tile.tileY))
651
{ requestOpenCraftStation(CraftingStationId.leatherworkingStation, tile.tileX, tile.tileY); }
650
652
else if (isOreBoulderTile(view, tile.tileX, tile.tileY))
651
653
{ requestMine(tile.tileX, tile.tileY); }
652
654
else if (isChopableTreeTile(view, tile.tileX, tile.tileY))
@@ -846,6 +848,14 @@ function handleRightClick (event, mouseX, mouseY)
846
848
});
847
849
}
848
850
851
if (isLeatherworkingTableTile(view, tile.tileX, tile.tileY))
852
{
853
items.push({
854
label: "Leatherwork",
855
onSelect: () => requestOpenCraftStation(CraftingStationId.leatherworkingStation, tile.tileX, tile.tileY)
856
});
857
}
858
849
859
if (isOreBoulderTile(view, tile.tileX, tile.tileY))
850
860
{
851
861
items.push({
@@ -1787,6 +1797,11 @@ function isTailorBenchTile (view, tileX, tileY)
1787
1797
return blockTypeAt(view, tileX, tileY) === BlockType.tailorBench;
1788
1798
}
1789
1799
1800
function isLeatherworkingTableTile (view, tileX, tileY)
1801
{
1802
return blockTypeAt(view, tileX, tileY) === BlockType.leatherworkingTable;
1803
}
1804
1790
1805
function isOreBoulderTile (view, tileX, tileY)
1791
1806
{
1792
1807
const block = blockAt(view, tileX, tileY);
@@ -647,6 +647,8 @@ function handleLeftClick (mouseX, mouseY)647
{ requestOpenCraftStation(CraftingStationId.loom, tile.tileX, tile.tileY); }647
{ requestOpenCraftStation(CraftingStationId.loom, tile.tileX, tile.tileY); }648
else if (isTailorBenchTile(view, tile.tileX, tile.tileY))648
else if (isTailorBenchTile(view, tile.tileX, tile.tileY))649
{ requestOpenCraftStation(CraftingStationId.tailorBench, tile.tileX, tile.tileY); }649
{ requestOpenCraftStation(CraftingStationId.tailorBench, tile.tileX, tile.tileY); }650
else if (isLeatherworkingTableTile(view, tile.tileX, tile.tileY))651
{ requestOpenCraftStation(CraftingStationId.leatherworkingStation, tile.tileX, tile.tileY); }650
else if (isOreBoulderTile(view, tile.tileX, tile.tileY))652
else if (isOreBoulderTile(view, tile.tileX, tile.tileY))651
{ requestMine(tile.tileX, tile.tileY); }653
{ requestMine(tile.tileX, tile.tileY); }652
else if (isChopableTreeTile(view, tile.tileX, tile.tileY))654
else if (isChopableTreeTile(view, tile.tileX, tile.tileY))@@ -846,6 +848,14 @@ function handleRightClick (event, mouseX, mouseY)846
});848
});847
}849
}848
850
851
if (isLeatherworkingTableTile(view, tile.tileX, tile.tileY))852
{853
items.push({854
label: "Leatherwork",855
onSelect: () => requestOpenCraftStation(CraftingStationId.leatherworkingStation, tile.tileX, tile.tileY)856
});857
}858
849
if (isOreBoulderTile(view, tile.tileX, tile.tileY))859
if (isOreBoulderTile(view, tile.tileX, tile.tileY))850
{860
{851
items.push({861
items.push({@@ -1787,6 +1797,11 @@ function isTailorBenchTile (view, tileX, tileY)1787
return blockTypeAt(view, tileX, tileY) === BlockType.tailorBench;1797
return blockTypeAt(view, tileX, tileY) === BlockType.tailorBench;1788
}1798
}1789
1799
1800
function isLeatherworkingTableTile (view, tileX, tileY)1801
{1802
return blockTypeAt(view, tileX, tileY) === BlockType.leatherworkingTable;1803
}1804
1790
function isOreBoulderTile (view, tileX, tileY)1805
function isOreBoulderTile (view, tileX, tileY)1791
{1806
{1792
const block = blockAt(view, tileX, tileY);1807
const block = blockAt(view, tileX, tileY);@@ -76,6 +76,8 @@ function stationBlockType (stationId)
76
76
{ return BlockType.loom; }
77
77
if (stationId === CraftingStationId.tailorBench)
78
78
{ return BlockType.tailorBench; }
79
if (stationId === CraftingStationId.leatherworkingStation)
80
{ return BlockType.leatherworkingTable; }
79
81
return null;
80
82
}
81
83
@@ -76,6 +76,8 @@ function stationBlockType (stationId)76
{ return BlockType.loom; }76
{ return BlockType.loom; }77
if (stationId === CraftingStationId.tailorBench)77
if (stationId === CraftingStationId.tailorBench)78
{ return BlockType.tailorBench; }78
{ return BlockType.tailorBench; }79
if (stationId === CraftingStationId.leatherworkingStation)80
{ return BlockType.leatherworkingTable; }79
return null;81
return null;80
}82
}81
83
@@ -116,7 +116,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
116
116
117
117
socket.on("close", () =>
118
118
{
119
leaveWorld(session);
119
if (!session.suppressLeaveWorldOnClose)
120
{ leaveWorld(session); }
120
121
auth.release(session);
121
122
sessions.delete(session.id);
122
123
});
@@ -1041,17 +1042,41 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1041
1042
error.userFacing = true;
1042
1043
throw error;
1043
1044
}
1044
for (const other of sessions.values())
1045
const targetCharacterId = character.character_id;
1046
let handoffEntityId = null;
1047
for (const other of [...sessions.values()])
1048
{
1049
if (other === session || other.account.account_id !== session.account.account_id || !other.characterId)
1050
{ continue; }
1051
const sameCharacter = other.characterId === targetCharacterId;
1052
if (sameCharacter && simulation.isCharacterOnline(targetCharacterId))
1053
{ handoffEntityId = simulation.entityForCharacter(targetCharacterId); }
1054
disconnectPlayingSession(other, {
1055
despawn: !sameCharacter,
1056
reason: sameCharacter
1057
? "This character was opened in another window."
1058
: "Logged in from another window."
1059
});
1060
}
1061
session.characterId = targetCharacterId;
1062
if (handoffEntityId != null)
1045
1063
{
1046
if (other !== session && other.account.account_id === session.account.account_id && other.characterId)
1064
const entityId = simulation.reattachCharacterSession(targetCharacterId, session.id);
1065
if (!entityId)
1047
1066
{
1048
const error = new Error("This account already has a character in the world.");
1067
const error = new Error("Could not resume that character. Please try again.");
1049
1068
error.userFacing = true;
1050
1069
throw error;
1051
1070
}
1071
session.entityId = entityId;
1052
1072
}
1053
session.characterId = character.character_id;
1054
session.entityId = simulation.spawnCharacter(session.id, character);
1073
else
1074
{ session.entityId = simulation.spawnCharacter(session.id, character); }
1075
sendEnterWorld(session, character);
1076
}
1077
1078
function sendEnterWorld (session, character)
1079
{
1055
1080
const spawned = simulation.entityRecord(session.entityId);
1056
1081
const enterDim = normalizeDimensionId(spawned.dimensionId ?? OVERWORLD_ID);
1057
1082
const dimRecord = simulation.getDimensionRecord?.(enterDim);
@@ -1114,6 +1139,24 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1114
1139
publishReplication(simulation.drainReplication());
1115
1140
}
1116
1141
1142
function disconnectPlayingSession (session, { despawn = true, reason = "Logged in from another window." } = {})
1143
{
1144
send(session, { type: MessageType.forceLogout, reason });
1145
const characterId = session.characterId;
1146
session.characterId = null;
1147
session.entityId = null;
1148
session.entitySubscribed.clear();
1149
session.staticSubscribed.clear();
1150
if (despawn && characterId)
1151
{
1152
simulation.despawnCharacter(characterId);
1153
publishReplication(simulation.drainReplication());
1154
}
1155
session.suppressLeaveWorldOnClose = true;
1156
if (session.socket.readyState === 1)
1157
{ session.socket.close(4000, "Logged in elsewhere"); }
1158
}
1159
1117
1160
function leaveWorld (session)
1118
1161
{
1119
1162
if (session.characterId)
@@ -116,7 +116,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,116
116
117
socket.on("close", () =>117
socket.on("close", () =>118
{118
{119
leaveWorld(session);119
if (!session.suppressLeaveWorldOnClose)120
{ leaveWorld(session); }120
auth.release(session);121
auth.release(session);121
sessions.delete(session.id);122
sessions.delete(session.id);122
});123
});@@ -1041,17 +1042,41 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1041
error.userFacing = true;1042
error.userFacing = true;1042
throw error;1043
throw error;1043
}1044
}1044
for (const other of sessions.values())1045
const targetCharacterId = character.character_id;1046
let handoffEntityId = null;1047
for (const other of [...sessions.values()])1048
{1049
if (other === session || other.account.account_id !== session.account.account_id || !other.characterId)1050
{ continue; }1051
const sameCharacter = other.characterId === targetCharacterId;1052
if (sameCharacter && simulation.isCharacterOnline(targetCharacterId))1053
{ handoffEntityId = simulation.entityForCharacter(targetCharacterId); }1054
disconnectPlayingSession(other, {1055
despawn: !sameCharacter,1056
reason: sameCharacter1057
? "This character was opened in another window."1058
: "Logged in from another window."1059
});1060
}1061
session.characterId = targetCharacterId;1062
if (handoffEntityId != null)1045
{1063
{1046
if (other !== session && other.account.account_id === session.account.account_id && other.characterId)1064
const entityId = simulation.reattachCharacterSession(targetCharacterId, session.id);1065
if (!entityId)1047
{1066
{1048
const error = new Error("This account already has a character in the world.");1067
const error = new Error("Could not resume that character. Please try again.");1049
error.userFacing = true;1068
error.userFacing = true;1050
throw error;1069
throw error;1051
}1070
}1071
session.entityId = entityId;1052
}1072
}1053
session.characterId = character.character_id;1073
else1054
session.entityId = simulation.spawnCharacter(session.id, character);1074
{ session.entityId = simulation.spawnCharacter(session.id, character); }1075
sendEnterWorld(session, character);1076
}1077
1078
function sendEnterWorld (session, character)1079
{1055
const spawned = simulation.entityRecord(session.entityId);1080
const spawned = simulation.entityRecord(session.entityId);1056
const enterDim = normalizeDimensionId(spawned.dimensionId ?? OVERWORLD_ID);1081
const enterDim = normalizeDimensionId(spawned.dimensionId ?? OVERWORLD_ID);1057
const dimRecord = simulation.getDimensionRecord?.(enterDim);1082
const dimRecord = simulation.getDimensionRecord?.(enterDim);@@ -1114,6 +1139,24 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,1114
publishReplication(simulation.drainReplication());1139
publishReplication(simulation.drainReplication());1115
}1140
}1116
1141
1142
function disconnectPlayingSession (session, { despawn = true, reason = "Logged in from another window." } = {})1143
{1144
send(session, { type: MessageType.forceLogout, reason });1145
const characterId = session.characterId;1146
session.characterId = null;1147
session.entityId = null;1148
session.entitySubscribed.clear();1149
session.staticSubscribed.clear();1150
if (despawn && characterId)1151
{1152
simulation.despawnCharacter(characterId);1153
publishReplication(simulation.drainReplication());1154
}1155
session.suppressLeaveWorldOnClose = true;1156
if (session.socket.readyState === 1)1157
{ session.socket.close(4000, "Logged in elsewhere"); }1158
}1159
1117
function leaveWorld (session)1160
function leaveWorld (session)1118
{1161
{1119
if (session.characterId)1162
if (session.characterId)@@ -206,6 +206,17 @@ export class MarketService
206
206
{ this.#releaseStation(key); }
207
207
}
208
208
209
/** Keep CE attendance open but route private events to a new gateway session. */
210
reattachSession (characterId, sessionId)
211
{
212
const id = characterId | 0;
213
for (const entry of this.stationAttendance.values())
214
{
215
if (entry.browsers.has(id))
216
{ entry.browsers.set(id, sessionId); }
217
}
218
}
219
209
220
placeSellOrder (sessionId, characterId, slotIndex, quantity, minUnitPrice, now = Date.now())
210
221
{
211
222
const { position } = this.#requireAtMarket(characterId);
@@ -206,6 +206,17 @@ export class MarketService206
{ this.#releaseStation(key); }206
{ this.#releaseStation(key); }207
}207
}208
208
209
/** Keep CE attendance open but route private events to a new gateway session. */210
reattachSession (characterId, sessionId)211
{212
const id = characterId | 0;213
for (const entry of this.stationAttendance.values())214
{215
if (entry.browsers.has(id))216
{ entry.browsers.set(id, sessionId); }217
}218
}219
209
placeSellOrder (sessionId, characterId, slotIndex, quantity, minUnitPrice, now = Date.now())220
placeSellOrder (sessionId, characterId, slotIndex, quantity, minUnitPrice, now = Date.now())210
{221
{211
const { position } = this.#requireAtMarket(characterId);222
const { position } = this.#requireAtMarket(characterId);@@ -9,6 +9,7 @@ export const WorkerMessage = Object.freeze({
9
9
spawn: "spawn",
10
10
despawn: "despawn",
11
11
despawnCharacter: "despawnCharacter",
12
reattachSession: "reattachSession",
12
13
command: "command",
13
14
stepMovement: "stepMovement",
14
15
applyTransfer: "applyTransfer",
@@ -9,6 +9,7 @@ export const WorkerMessage = Object.freeze({9
spawn: "spawn",9
spawn: "spawn",10
despawn: "despawn",10
despawn: "despawn",11
despawnCharacter: "despawnCharacter",11
despawnCharacter: "despawnCharacter",12
reattachSession: "reattachSession",12
command: "command",13
command: "command",13
stepMovement: "stepMovement",14
stepMovement: "stepMovement",14
applyTransfer: "applyTransfer",15
applyTransfer: "applyTransfer",@@ -487,6 +487,25 @@ export class Simulation
487
487
return this.characterEntities.has(characterId);
488
488
}
489
489
490
reattachCharacterSession (characterId, sessionId)
491
{
492
const entityId = this.characterEntities.get(characterId | 0);
493
if (!entityId)
494
{ return null; }
495
const record = this.directory.get(entityId);
496
if (!record)
497
{ return null; }
498
const result = this.workers[record.workerId].call({
499
type: WorkerMessage.reattachSession,
500
characterId,
501
sessionId
502
});
503
if (!result?.ok)
504
{ return null; }
505
this.market?.reattachSession?.(characterId, sessionId);
506
return entityId;
507
}
508
490
509
spawnEntity (components, options = {})
491
510
{
492
511
const entityId = options.entityId ?? this.nextEntityId++;
@@ -487,6 +487,25 @@ export class Simulation487
return this.characterEntities.has(characterId);487
return this.characterEntities.has(characterId);488
}488
}489
489
490
reattachCharacterSession (characterId, sessionId)491
{492
const entityId = this.characterEntities.get(characterId | 0);493
if (!entityId)494
{ return null; }495
const record = this.directory.get(entityId);496
if (!record)497
{ return null; }498
const result = this.workers[record.workerId].call({499
type: WorkerMessage.reattachSession,500
characterId,501
sessionId502
});503
if (!result?.ok)504
{ return null; }505
this.market?.reattachSession?.(characterId, sessionId);506
return entityId;507
}508
490
spawnEntity (components, options = {})509
spawnEntity (components, options = {})491
{510
{492
const entityId = options.entityId ?? this.nextEntityId++;511
const entityId = options.entityId ?? this.nextEntityId++;@@ -118,6 +118,8 @@ export class WorkerWorld
118
118
return this.#despawn(message.entityId);
119
119
case WorkerMessage.despawnCharacter:
120
120
return this.#despawnCharacter(message.characterId);
121
case WorkerMessage.reattachSession:
122
return this.#reattachSession(message.characterId, message.sessionId);
121
123
case WorkerMessage.command:
122
124
return this.#command(message);
123
125
case WorkerMessage.stepMovement:
@@ -413,6 +415,18 @@ export class WorkerWorld
413
415
return this.#destroyEntity(entityId);
414
416
}
415
417
418
#reattachSession (characterId, sessionId)
419
{
420
const entityId = this.characterEntities.get(characterId | 0);
421
if (!entityId)
422
{ return { ok: false }; }
423
const handle = this.ecs.handleOf(entityId);
424
if (handle == null)
425
{ return { ok: false }; }
426
this.ecs.add(handle, Component.networkIdentity, { sessionId });
427
return { ok: true, entityId };
428
}
429
416
430
#destroyEntity (entityId)
417
431
{
418
432
const handle = this.ecs.handleOf(entityId);
@@ -118,6 +118,8 @@ export class WorkerWorld118
return this.#despawn(message.entityId);118
return this.#despawn(message.entityId);119
case WorkerMessage.despawnCharacter:119
case WorkerMessage.despawnCharacter:120
return this.#despawnCharacter(message.characterId);120
return this.#despawnCharacter(message.characterId);121
case WorkerMessage.reattachSession:122
return this.#reattachSession(message.characterId, message.sessionId);121
case WorkerMessage.command:123
case WorkerMessage.command:122
return this.#command(message);124
return this.#command(message);123
case WorkerMessage.stepMovement:125
case WorkerMessage.stepMovement:@@ -413,6 +415,18 @@ export class WorkerWorld413
return this.#destroyEntity(entityId);415
return this.#destroyEntity(entityId);414
}416
}415
417
418
#reattachSession (characterId, sessionId)419
{420
const entityId = this.characterEntities.get(characterId | 0);421
if (!entityId)422
{ return { ok: false }; }423
const handle = this.ecs.handleOf(entityId);424
if (handle == null)425
{ return { ok: false }; }426
this.ecs.add(handle, Component.networkIdentity, { sessionId });427
return { ok: true, entityId };428
}429
416
#destroyEntity (entityId)430
#destroyEntity (entityId)417
{431
{418
const handle = this.ecs.handleOf(entityId);432
const handle = this.ecs.handleOf(entityId);@@ -0,0 +1,63 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { makeCharacter, makeSimulation, stepTimes, walkTicks } from "./helpers/simulationHarness.js";
4
5
test("reattachCharacterSession moves command ownership to a new session", () =>
6
{
7
const harness = makeSimulation({ workerCount: 1 });
8
try
9
{
10
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
11
const entityId = harness.simulation.spawnCharacter(1, character);
12
harness.simulation.enqueue(1, {
13
type: "move-to",
14
characterId: character.character_id,
15
tileX: 12,
16
tileY: 8
17
});
18
stepTimes(harness.simulation, walkTicks(5));
19
const before = harness.simulation.entityRecord(entityId);
20
assert.equal(before.tileX, 12);
21
22
const again = harness.simulation.reattachCharacterSession(character.character_id, 2);
23
assert.equal(again, entityId);
24
25
harness.simulation.enqueue(2, {
26
type: "move-to",
27
characterId: character.character_id,
28
tileX: 10,
29
tileY: 8
30
});
31
stepTimes(harness.simulation, walkTicks(3));
32
const after = harness.simulation.entityRecord(entityId);
33
assert.equal(after.tileX, 10);
34
assert.equal(harness.simulation.entityForCharacter(character.character_id), entityId);
35
}
36
finally
37
{ harness.close(); }
38
});
39
40
test("reattachCharacterSession rejects commands from the old session", () =>
41
{
42
const harness = makeSimulation({ workerCount: 1 });
43
try
44
{
45
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
46
const entityId = harness.simulation.spawnCharacter(1, character);
47
harness.simulation.reattachCharacterSession(character.character_id, 2);
48
49
harness.simulation.enqueue(1, {
50
type: "move-to",
51
characterId: character.character_id,
52
tileX: 12,
53
tileY: 8
54
});
55
stepTimes(harness.simulation, walkTicks(5));
56
57
const stayed = harness.simulation.entityRecord(entityId);
58
assert.equal(stayed.tileX, 8);
59
assert.equal(stayed.tileY, 8);
60
}
61
finally
62
{ harness.close(); }
63
});
@@ -0,0 +1,63 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { makeCharacter, makeSimulation, stepTimes, walkTicks } from "./helpers/simulationHarness.js";4
5
test("reattachCharacterSession moves command ownership to a new session", () =>6
{7
const harness = makeSimulation({ workerCount: 1 });8
try9
{10
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });11
const entityId = harness.simulation.spawnCharacter(1, character);12
harness.simulation.enqueue(1, {13
type: "move-to",14
characterId: character.character_id,15
tileX: 12,16
tileY: 817
});18
stepTimes(harness.simulation, walkTicks(5));19
const before = harness.simulation.entityRecord(entityId);20
assert.equal(before.tileX, 12);21
22
const again = harness.simulation.reattachCharacterSession(character.character_id, 2);23
assert.equal(again, entityId);24
25
harness.simulation.enqueue(2, {26
type: "move-to",27
characterId: character.character_id,28
tileX: 10,29
tileY: 830
});31
stepTimes(harness.simulation, walkTicks(3));32
const after = harness.simulation.entityRecord(entityId);33
assert.equal(after.tileX, 10);34
assert.equal(harness.simulation.entityForCharacter(character.character_id), entityId);35
}36
finally37
{ harness.close(); }38
});39
40
test("reattachCharacterSession rejects commands from the old session", () =>41
{42
const harness = makeSimulation({ workerCount: 1 });43
try44
{45
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });46
const entityId = harness.simulation.spawnCharacter(1, character);47
harness.simulation.reattachCharacterSession(character.character_id, 2);48
49
harness.simulation.enqueue(1, {50
type: "move-to",51
characterId: character.character_id,52
tileX: 12,53
tileY: 854
});55
stepTimes(harness.simulation, walkTicks(5));56
57
const stayed = harness.simulation.entityRecord(entityId);58
assert.equal(stayed.tileX, 8);59
assert.equal(stayed.tileY, 8);60
}61
finally62
{ harness.close(); }63
});@@ -168,6 +168,35 @@ test("open furnace near station emits shove and station-open", () =>
168
168
{ harness.close(); }
169
169
});
170
170
171
test("open leatherworking table near station emits station-open", () =>
172
{
173
const harness = makeSimulation({ workerCount: 1 });
174
try
175
{
176
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
177
const playerId = harness.simulation.spawnCharacter(1, character);
178
const record = harness.simulation.entityRecord(playerId);
179
const worker = harness.simulation.workers[record.workerId];
180
const data = worker.world.chunkData(Math.floor(9 / 16), Math.floor(8 / 16));
181
data.blocks[8 * 16 + 9] = {
182
typeId: BlockType.leatherworkingTable,
183
state: "leatherworking-table",
184
config: null
185
};
186
187
harness.simulation.enqueue(1, {
188
type: "open-station",
189
characterId: character.character_id,
190
stationId: CraftingStationId.leatherworkingStation
191
});
192
const result = harness.simulation.step();
193
assert.ok(result.events.some((event) =>
194
event.type === "station-open" && event.stationId === CraftingStationId.leatherworkingStation));
195
}
196
finally
197
{ harness.close(); }
198
});
199
171
200
test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>
172
201
{
173
202
const harness = makeSimulation({ workerCount: 1 });
@@ -168,6 +168,35 @@ test("open furnace near station emits shove and station-open", () =>168
{ harness.close(); }168
{ harness.close(); }169
});169
});170
170
171
test("open leatherworking table near station emits station-open", () =>172
{173
const harness = makeSimulation({ workerCount: 1 });174
try175
{176
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });177
const playerId = harness.simulation.spawnCharacter(1, character);178
const record = harness.simulation.entityRecord(playerId);179
const worker = harness.simulation.workers[record.workerId];180
const data = worker.world.chunkData(Math.floor(9 / 16), Math.floor(8 / 16));181
data.blocks[8 * 16 + 9] = {182
typeId: BlockType.leatherworkingTable,183
state: "leatherworking-table",184
config: null185
};186
187
harness.simulation.enqueue(1, {188
type: "open-station",189
characterId: character.character_id,190
stationId: CraftingStationId.leatherworkingStation191
});192
const result = harness.simulation.step();193
assert.ok(result.events.some((event) =>194
event.type === "station-open" && event.stationId === CraftingStationId.leatherworkingStation));195
}196
finally197
{ harness.close(); }198
});199
171
test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>200
test("smelting bronze consumes tin and copper, grants bar and Smithing XP", () =>172
{201
{173
const harness = makeSimulation({ workerCount: 1 });202
const harness = makeSimulation({ workerCount: 1 });