@adatechnology/game-interactables 0.12.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/index.d.ts +255 -13
- package/dist/index.global.js +757 -43
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +663 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,196 @@
|
|
|
1
|
+
// src/basin-drain.ts
|
|
2
|
+
var FLUSH_POUR_SECONDS = 3;
|
|
3
|
+
var CLOGGED = 0.5;
|
|
4
|
+
var REFILL_RATE = 0.12;
|
|
5
|
+
var BREAK_DEPTH = 0.035;
|
|
6
|
+
var WEIR_SHARE = 0.25;
|
|
7
|
+
var SEEP = 0.04;
|
|
8
|
+
var TURN_PER_LITRE = 2.4;
|
|
9
|
+
var TRAP_LITRES = 3.5;
|
|
10
|
+
var PLUNGE_PACKED = 0.34;
|
|
11
|
+
var PLUNGE_LODGED = 0.2;
|
|
12
|
+
var PLUNGER_WATER = 0.03;
|
|
13
|
+
var SOFT_SQUEEZE = 1.6;
|
|
14
|
+
var SWIRL_SETTLED = 1e-4;
|
|
15
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
16
|
+
var passingSize = (size) => [...size].sort((a, b) => b - a)[1] ?? 0;
|
|
17
|
+
function createBasinDrain(basin, drain) {
|
|
18
|
+
const width = basin.to[0] - basin.from[0];
|
|
19
|
+
const deep = basin.to[2] - basin.from[2];
|
|
20
|
+
const radius = Math.min(width, deep) / 2;
|
|
21
|
+
const area = basin.shape === "round" ? Math.PI * radius * radius : width * deep;
|
|
22
|
+
const litresAt = (level) => area * level * 1e3;
|
|
23
|
+
const levelOf = (litres) => litres / (area * 1e3);
|
|
24
|
+
const capacity = litresAt(basin.to[1] - basin.from[1]);
|
|
25
|
+
const still = litresAt(drain.weir);
|
|
26
|
+
const water = { litres: still, phase: "still", swirl: 0, turned: 0, clog: 0, cause: "none", cistern: 1, pouring: 0, pourRate: 0, carried: 0 };
|
|
27
|
+
let serial = 0;
|
|
28
|
+
let contents = [];
|
|
29
|
+
let shown = null;
|
|
30
|
+
const step = { spilled: 0, swallowed: [] };
|
|
31
|
+
const open = () => Math.max(SEEP, 1 - water.clog);
|
|
32
|
+
const lodge = (c, packed) => {
|
|
33
|
+
c.stage = "lodged";
|
|
34
|
+
c.depth = 1;
|
|
35
|
+
c.radius = 0;
|
|
36
|
+
water.clog = packed ? Math.max(water.clog, Math.min(0.95, water.clog + 0.55 + 0.3 * (c.kg / drain.carries))) : 0.97;
|
|
37
|
+
water.cause = water.cause === "object" || !packed ? "object" : "packed";
|
|
38
|
+
};
|
|
39
|
+
const reachTrap = (c, swallowed) => {
|
|
40
|
+
const hard = c.kind === "object";
|
|
41
|
+
if (passingSize(c.size) > drain.trap * (hard ? 1 : SOFT_SQUEEZE) || !hard && water.carried + c.kg > drain.carries) {
|
|
42
|
+
lodge(c, !hard);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (!hard) water.carried += c.kg;
|
|
46
|
+
c.stage = "gone";
|
|
47
|
+
if (c.objectId) swallowed.push(c.objectId);
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
const stepContents = (moved, pulled, swallowed) => {
|
|
51
|
+
water.turned += moved * TURN_PER_LITRE;
|
|
52
|
+
const takesUrine = water.phase === "siphon" && water.swirl > 0.3;
|
|
53
|
+
let leaving = false;
|
|
54
|
+
for (const c of contents) {
|
|
55
|
+
if (c.kind === "urine" && takesUrine) leaving = true;
|
|
56
|
+
if (c.stage === "gone" || c.stage === "lodged") continue;
|
|
57
|
+
c.angle = c.start + water.turned;
|
|
58
|
+
if (water.phase !== "siphon" || c.kind === "urine") continue;
|
|
59
|
+
c.stage = "going";
|
|
60
|
+
c.travel = clamp01(c.travel + pulled / TRAP_LITRES);
|
|
61
|
+
c.depth = Math.max(c.depth, c.travel);
|
|
62
|
+
c.radius = c.startRadius * (1 - c.travel);
|
|
63
|
+
if (c.travel >= 1 && reachTrap(c, swallowed)) leaving = true;
|
|
64
|
+
}
|
|
65
|
+
if (leaving) contents = contents.filter((c) => c.stage !== "gone" && !(c.kind === "urine" && takesUrine));
|
|
66
|
+
};
|
|
67
|
+
const outflow = (dt) => {
|
|
68
|
+
const level = levelOf(water.litres);
|
|
69
|
+
if (water.phase === "siphon") return drain.siphon * open() * dt * Math.sqrt(clamp01(level / Math.max(1e-3, drain.weir)));
|
|
70
|
+
const head = level - drain.weir;
|
|
71
|
+
if (head <= 0) return 0;
|
|
72
|
+
return drain.siphon * WEIR_SHARE * open() * dt * Math.sqrt(clamp01(head / drain.prime));
|
|
73
|
+
};
|
|
74
|
+
const stepPhase = () => {
|
|
75
|
+
const head = levelOf(water.litres) - drain.weir;
|
|
76
|
+
if (water.phase !== "siphon" && head >= drain.prime && open() > CLOGGED) {
|
|
77
|
+
water.phase = "siphon";
|
|
78
|
+
water.carried = 0;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (water.phase === "siphon" && (head <= -BREAK_DEPTH || open() <= CLOGGED)) water.phase = "refill";
|
|
82
|
+
if (water.phase === "refill" && water.litres >= still - 1e-6 && water.pouring <= 0) water.phase = "still";
|
|
83
|
+
if (water.phase === "still" && water.pouring > 0) water.phase = "filling";
|
|
84
|
+
if (water.phase === "filling" && water.pouring <= 0 && head <= 1e-4) water.phase = "still";
|
|
85
|
+
};
|
|
86
|
+
const stepInflow = (dt) => {
|
|
87
|
+
const poured = water.pouring > 0 ? water.pourRate * Math.min(dt, water.pouring) : 0;
|
|
88
|
+
water.pouring = Math.max(0, water.pouring - dt);
|
|
89
|
+
water.litres += poured;
|
|
90
|
+
if ((water.phase === "refill" || water.phase === "still") && water.litres < still && water.clog < CLOGGED) water.litres = Math.min(still, water.litres + REFILL_RATE * dt);
|
|
91
|
+
return poured;
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
flush(asked) {
|
|
95
|
+
shown = null;
|
|
96
|
+
const litresIn = asked * water.cistern;
|
|
97
|
+
water.cistern = 0;
|
|
98
|
+
if (litresIn <= 0) return 0;
|
|
99
|
+
water.pouring = FLUSH_POUR_SECONDS;
|
|
100
|
+
water.pourRate = litresIn / FLUSH_POUR_SECONDS;
|
|
101
|
+
if (water.phase === "still") water.phase = "filling";
|
|
102
|
+
return litresIn;
|
|
103
|
+
},
|
|
104
|
+
add(content) {
|
|
105
|
+
shown = null;
|
|
106
|
+
water.litres += content.litres ?? 0;
|
|
107
|
+
const k = serial++;
|
|
108
|
+
const start = k * 2.39996;
|
|
109
|
+
const startRadius = 0.25 + k * 0.37 % 0.45;
|
|
110
|
+
contents.push({
|
|
111
|
+
start,
|
|
112
|
+
startRadius,
|
|
113
|
+
travel: 0,
|
|
114
|
+
id: `c${k}`,
|
|
115
|
+
kind: content.kind,
|
|
116
|
+
kg: content.kg,
|
|
117
|
+
size: content.size,
|
|
118
|
+
...content.objectId ? { objectId: content.objectId } : {},
|
|
119
|
+
stage: "afloat",
|
|
120
|
+
angle: start + water.turned,
|
|
121
|
+
radius: startRadius,
|
|
122
|
+
depth: content.kind === "object" ? 0.5 : 0
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
plunge() {
|
|
126
|
+
shown = null;
|
|
127
|
+
if (levelOf(water.litres) < PLUNGER_WATER) return false;
|
|
128
|
+
if (water.clog <= 0) return true;
|
|
129
|
+
const lodged = contents.filter((c) => c.stage === "lodged");
|
|
130
|
+
const hard = lodged.some((c) => c.kind === "object");
|
|
131
|
+
water.clog = Math.max(0, water.clog - (hard ? PLUNGE_LODGED : PLUNGE_PACKED));
|
|
132
|
+
if (water.clog > CLOGGED * 0.4) return true;
|
|
133
|
+
water.clog = 0;
|
|
134
|
+
water.cause = "none";
|
|
135
|
+
for (const c of lodged) {
|
|
136
|
+
if (c.kind === "object") Object.assign(c, { stage: "afloat", depth: 0.6, radius: 0.3, startRadius: 0.3, travel: 0 });
|
|
137
|
+
else c.stage = "gone";
|
|
138
|
+
}
|
|
139
|
+
contents = contents.filter((c) => c.stage !== "gone");
|
|
140
|
+
return true;
|
|
141
|
+
},
|
|
142
|
+
update(dt) {
|
|
143
|
+
step.spilled = 0;
|
|
144
|
+
step.swallowed.length = 0;
|
|
145
|
+
if (dt <= 0) return step;
|
|
146
|
+
const { litres, swirl, cistern, phase, clog } = water;
|
|
147
|
+
const count = contents.length;
|
|
148
|
+
water.cistern = clamp01(water.cistern + dt / drain.refill);
|
|
149
|
+
const poured = stepInflow(dt);
|
|
150
|
+
const out = Math.min(water.litres, outflow(dt));
|
|
151
|
+
water.litres -= out;
|
|
152
|
+
stepPhase();
|
|
153
|
+
const pull = water.phase === "siphon" ? clamp01(out / (drain.siphon * dt)) : 0;
|
|
154
|
+
const jets = poured > 0 ? 0.35 : 0;
|
|
155
|
+
const swirlTo = Math.max(pull, jets);
|
|
156
|
+
water.swirl = Math.abs(swirlTo - water.swirl) < SWIRL_SETTLED ? swirlTo : water.swirl + (swirlTo - water.swirl) * clamp01(dt * 6);
|
|
157
|
+
const moved = poured + out;
|
|
158
|
+
stepContents(moved, water.phase === "siphon" ? out : 0, step.swallowed);
|
|
159
|
+
step.spilled = Math.max(0, water.litres - capacity);
|
|
160
|
+
water.litres -= step.spilled;
|
|
161
|
+
const changed = moved > 0 || water.litres !== litres || water.swirl !== swirl || water.cistern !== cistern || water.phase !== phase || water.clog !== clog || contents.length !== count;
|
|
162
|
+
if (changed) shown = null;
|
|
163
|
+
return step;
|
|
164
|
+
},
|
|
165
|
+
state() {
|
|
166
|
+
shown ?? (shown = {
|
|
167
|
+
litres: water.litres,
|
|
168
|
+
level: levelOf(water.litres),
|
|
169
|
+
phase: water.phase,
|
|
170
|
+
swirl: water.swirl,
|
|
171
|
+
turned: water.turned,
|
|
172
|
+
clog: water.clog,
|
|
173
|
+
cause: water.cause,
|
|
174
|
+
cistern: water.cistern,
|
|
175
|
+
contents: contents.map(({ start: _start, startRadius: _startRadius, travel: _travel, ...c }) => c)
|
|
176
|
+
});
|
|
177
|
+
return shown;
|
|
178
|
+
},
|
|
179
|
+
litres: () => water.litres,
|
|
180
|
+
level: () => levelOf(water.litres),
|
|
181
|
+
clog: () => water.clog,
|
|
182
|
+
cause: () => water.cause,
|
|
183
|
+
dirty: () => contents.some((c) => c.kind !== "object"),
|
|
184
|
+
save: () => ({ water: { ...water }, serial, contents: contents.map((c) => ({ ...c })) }),
|
|
185
|
+
restore(saved) {
|
|
186
|
+
shown = null;
|
|
187
|
+
Object.assign(water, saved.water);
|
|
188
|
+
serial = saved.serial;
|
|
189
|
+
contents = saved.contents.map((c) => ({ ...c }));
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
1
194
|
// src/gestures.ts
|
|
2
195
|
var GESTURE_OF_ACTION = {
|
|
3
196
|
toggle_part: null,
|
|
@@ -21,6 +214,7 @@ var GESTURE_OF_USE = {
|
|
|
21
214
|
empty: "tip",
|
|
22
215
|
fill: "pour",
|
|
23
216
|
relieve: null,
|
|
217
|
+
plunge: null,
|
|
24
218
|
wash: null,
|
|
25
219
|
drink: null
|
|
26
220
|
};
|
|
@@ -159,9 +353,14 @@ function fitsSize(size, max) {
|
|
|
159
353
|
if (size[1] > max[1] + eps) return false;
|
|
160
354
|
return size[0] <= max[0] + eps && size[2] <= max[2] + eps || size[2] <= max[0] + eps && size[0] <= max[2] + eps;
|
|
161
355
|
}
|
|
356
|
+
function laidSize(size, lay) {
|
|
357
|
+
if (lay === "x") return [size[1], size[0], size[2]];
|
|
358
|
+
if (lay === "z") return [size[0], size[2], size[1]];
|
|
359
|
+
return size;
|
|
360
|
+
}
|
|
162
361
|
function fitsSlot(type, slot, items) {
|
|
163
362
|
const def = items?.[type];
|
|
164
|
-
return def ? fitsSize(def.size, slot.max) : true;
|
|
363
|
+
return def ? fitsSize(laidSize(def.size, slot.lay), slot.max) : true;
|
|
165
364
|
}
|
|
166
365
|
function generateLoot(tables, tableId, slots, seed, items) {
|
|
167
366
|
const table = tables?.[tableId];
|
|
@@ -249,7 +448,21 @@ var locales = {
|
|
|
249
448
|
done_relieve_feces: "You pooed in {name}",
|
|
250
449
|
done_clean: "{name} flushed clean",
|
|
251
450
|
"use.wash_dishes": "Wash the dishes",
|
|
252
|
-
"use.drink_water": "Drink water",
|
|
451
|
+
"use.drink_water": "Drink water from the glass",
|
|
452
|
+
"use.drink_from_hands": "Drink water from your hands",
|
|
453
|
+
"use.lather_body": "Soap yourself",
|
|
454
|
+
"use.shampoo_hair": "Shampoo your hair",
|
|
455
|
+
"use.wash_hands": "Wash your hands",
|
|
456
|
+
"use.brush_teeth": "Brush your teeth",
|
|
457
|
+
needs_in_hand: "Pick up {item} first",
|
|
458
|
+
needs_vessel: "You need a glass",
|
|
459
|
+
vessel_not_empty: "Empty {item} first",
|
|
460
|
+
hands_busy: "Your hands are busy",
|
|
461
|
+
no_animation: "Cannot be done here: the body has no movement for it",
|
|
462
|
+
needs_free_hand: "You need your hands free",
|
|
463
|
+
not_drunk: "No water was drunk",
|
|
464
|
+
drink_from_vessel: "You have a glass in your hand: drink from it",
|
|
465
|
+
done_drink_hands: "You drank {litres} l of water from your hands",
|
|
253
466
|
busy: "Already in use",
|
|
254
467
|
needs_running: "Turn the water on first",
|
|
255
468
|
needs_item: "You need {need}",
|
|
@@ -259,7 +472,21 @@ var locales = {
|
|
|
259
472
|
started_drink: "{label}\u2026",
|
|
260
473
|
done_wash: "Washed and rinsed",
|
|
261
474
|
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
262
|
-
done_drink: "You drank {litres} l of water"
|
|
475
|
+
done_drink: "You drank {litres} l of water",
|
|
476
|
+
"use.plunge": "Unclog {name} with the plunger",
|
|
477
|
+
needs_plunger: "Hold a plunger",
|
|
478
|
+
plunge_no_water: "No water over the trap for the plunger",
|
|
479
|
+
done_plunge: "You work the plunger in {name}",
|
|
480
|
+
plunge_cleared: "{name} unclogged: the water goes down",
|
|
481
|
+
plunge_object: "{name} unclogged: something came back up the trap",
|
|
482
|
+
plunge_still: "{name} is still clogged",
|
|
483
|
+
clogged: "{name} is clogged",
|
|
484
|
+
overflow: "{name} is overflowing",
|
|
485
|
+
needs_body: "There is no body here to use {name}",
|
|
486
|
+
host_lacks: "This place cannot run {name} (it lacks {capability})",
|
|
487
|
+
body_no_seat: "{name} has no seat to sit on",
|
|
488
|
+
body_object_gone: "{name} is not here",
|
|
489
|
+
body_busy: "You are busy with something else"
|
|
263
490
|
},
|
|
264
491
|
"pt-BR": {
|
|
265
492
|
"prompt.open": "Abrir {name}",
|
|
@@ -314,7 +541,21 @@ var locales = {
|
|
|
314
541
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
315
542
|
done_clean: "Descarga dada: {name} limpo",
|
|
316
543
|
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
317
|
-
"use.drink_water": "Beber \xE1gua",
|
|
544
|
+
"use.drink_water": "Beber \xE1gua no copo",
|
|
545
|
+
"use.drink_from_hands": "Beber \xE1gua com a m\xE3o",
|
|
546
|
+
"use.lather_body": "Ensaboar-se",
|
|
547
|
+
"use.shampoo_hair": "Passar shampoo",
|
|
548
|
+
"use.wash_hands": "Lavar as m\xE3os",
|
|
549
|
+
"use.brush_teeth": "Escovar os dentes",
|
|
550
|
+
needs_in_hand: "Pegue {item} antes",
|
|
551
|
+
needs_vessel: "Precisa de um copo",
|
|
552
|
+
vessel_not_empty: "Esvazie {item} antes",
|
|
553
|
+
hands_busy: "As m\xE3os est\xE3o ocupadas",
|
|
554
|
+
no_animation: "N\xE3o d\xE1 para fazer isso aqui: o corpo n\xE3o tem o movimento",
|
|
555
|
+
needs_free_hand: "Precisa das m\xE3os livres",
|
|
556
|
+
not_drunk: "Nenhuma \xE1gua foi bebida",
|
|
557
|
+
drink_from_vessel: "Voc\xEA est\xE1 com um copo na m\xE3o: beba nele",
|
|
558
|
+
done_drink_hands: "Voc\xEA bebeu {litres} l de \xE1gua com a m\xE3o",
|
|
318
559
|
busy: "J\xE1 est\xE1 em uso",
|
|
319
560
|
needs_running: "Abra a \xE1gua primeiro",
|
|
320
561
|
needs_item: "Precisa de {need}",
|
|
@@ -324,7 +565,21 @@ var locales = {
|
|
|
324
565
|
started_drink: "{label}\u2026",
|
|
325
566
|
done_wash: "Lavado e enxaguado",
|
|
326
567
|
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
327
|
-
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
568
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua",
|
|
569
|
+
"use.plunge": "Desentupir {name} com o desentupidor",
|
|
570
|
+
needs_plunger: "Segure um desentupidor",
|
|
571
|
+
plunge_no_water: "Sem \xE1gua sobre o sif\xE3o para o desentupidor",
|
|
572
|
+
done_plunge: "Voc\xEA bombeia o desentupidor em {name}",
|
|
573
|
+
plunge_cleared: "{name} desentupido: a \xE1gua desce",
|
|
574
|
+
plunge_object: "{name} desentupido: uma coisa voltou do sif\xE3o",
|
|
575
|
+
plunge_still: "{name} ainda est\xE1 entupido",
|
|
576
|
+
clogged: "{name} entupiu",
|
|
577
|
+
overflow: "{name} est\xE1 transbordando",
|
|
578
|
+
needs_body: "N\xE3o h\xE1 corpo aqui para usar {name}",
|
|
579
|
+
host_lacks: "Este lugar n\xE3o sabe usar {name} (falta {capability})",
|
|
580
|
+
body_no_seat: "{name} n\xE3o tem assento para sentar",
|
|
581
|
+
body_object_gone: "{name} n\xE3o est\xE1 aqui",
|
|
582
|
+
body_busy: "Voc\xEA est\xE1 ocupado com outra coisa"
|
|
328
583
|
}
|
|
329
584
|
};
|
|
330
585
|
function pickLocale(locale) {
|
|
@@ -1731,6 +1986,7 @@ function createWorld(options = {}) {
|
|
|
1731
1986
|
burners: /* @__PURE__ */ new Map(),
|
|
1732
1987
|
tanks: /* @__PURE__ */ new Map(),
|
|
1733
1988
|
fixtures: /* @__PURE__ */ new Map(),
|
|
1989
|
+
drains: /* @__PURE__ */ new Map(),
|
|
1734
1990
|
soft: /* @__PURE__ */ new Map(),
|
|
1735
1991
|
hp: /* @__PURE__ */ new Map(),
|
|
1736
1992
|
interactions: spec.interactions ?? deriveInteractions(spec)
|
|
@@ -1763,6 +2019,7 @@ function createWorld(options = {}) {
|
|
|
1763
2019
|
for (const b of spec.burners ?? []) o.burners.set(b.id, { spec: b, on: false, lit: false, smoke: 0 });
|
|
1764
2020
|
for (const tk of spec.tanks ?? []) o.tanks.set(tk.id, { spec: tk, level: clamp(tk.level ?? tk.capacity, 0, tk.capacity) });
|
|
1765
2021
|
for (const f of spec.fixtures ?? []) o.fixtures.set(f.id, { spec: f, on: false, flowing: false, frac: 0, timer: 0 });
|
|
2022
|
+
for (const b of spec.basins ?? []) if (b.drain) o.drains.set(b.id, createBasinDrain(b, b.drain));
|
|
1766
2023
|
let n = 0;
|
|
1767
2024
|
for (const s of spec.soft ?? []) {
|
|
1768
2025
|
const driver = options.partPhysics?.attachSoft?.(id, s, pub.transform);
|
|
@@ -1795,7 +2052,8 @@ function createWorld(options = {}) {
|
|
|
1795
2052
|
burners: Object.fromEntries([...o.burners].map(([k, b]) => [k, { on: b.on, lit: b.lit }])),
|
|
1796
2053
|
tanks: Object.fromEntries([...o.tanks].map(([k, tk]) => [k, tk.level])),
|
|
1797
2054
|
fixtures: Object.fromEntries([...o.fixtures].map(([k, f]) => [k, f.on])),
|
|
1798
|
-
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp]))
|
|
2055
|
+
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp])),
|
|
2056
|
+
drains: Object.fromEntries([...o.drains].map(([k, d]) => [k, d.save()]))
|
|
1799
2057
|
};
|
|
1800
2058
|
}
|
|
1801
2059
|
return {
|
|
@@ -1861,6 +2119,7 @@ function createWorld(options = {}) {
|
|
|
1861
2119
|
const h = o.hp.get(k);
|
|
1862
2120
|
if (h) h.hp = v;
|
|
1863
2121
|
}
|
|
2122
|
+
for (const [k, v] of Object.entries(st.drains ?? {})) o.drains.get(k)?.restore(v);
|
|
1864
2123
|
}
|
|
1865
2124
|
grid = state.grid;
|
|
1866
2125
|
main = state.main ?? true;
|
|
@@ -1985,6 +2244,7 @@ function createWorld(options = {}) {
|
|
|
1985
2244
|
locale = l;
|
|
1986
2245
|
table = resolveStrings(locale, options.strings);
|
|
1987
2246
|
},
|
|
2247
|
+
drain: (objectId, basin) => objs.get(objectId)?.drains.get(basin),
|
|
1988
2248
|
serialize,
|
|
1989
2249
|
load
|
|
1990
2250
|
};
|
|
@@ -2509,6 +2769,178 @@ function castWithMember(member, other) {
|
|
|
2509
2769
|
return wrapsMember(member, other) || endsMember(member, other);
|
|
2510
2770
|
}
|
|
2511
2771
|
|
|
2772
|
+
// src/drain-uses.ts
|
|
2773
|
+
import { PLUNGE_STROKE_SECONDS } from "@adatechnology/game-contracts";
|
|
2774
|
+
var RELIEVE_SECONDS = 8;
|
|
2775
|
+
var LANDS_AT = 0.7;
|
|
2776
|
+
var FLUSH_LITRES = 6;
|
|
2777
|
+
var SWALLOW_SECONDS = 0.5;
|
|
2778
|
+
var SPILL_GATHER_SECONDS = 0.25;
|
|
2779
|
+
var URINE = { kind: "urine", kg: 0.3, litres: 0.3, size: [0.02, 0.02, 0.02] };
|
|
2780
|
+
var FECES = { kind: "feces", kg: 0.2, size: [0.12, 0.035, 0.035] };
|
|
2781
|
+
var PAPER = { kind: "paper", kg: 8e-3, size: [0.06, 0.03, 0.03] };
|
|
2782
|
+
var PEE = [URINE];
|
|
2783
|
+
var POO = [FECES, PAPER, PAPER];
|
|
2784
|
+
var HOST_NEEDS = ["setBasin", "spill", "looseInside", "swallow"];
|
|
2785
|
+
function createDrainUses(options) {
|
|
2786
|
+
const { spec, t, world, objectId } = options;
|
|
2787
|
+
const basins = /* @__PURE__ */ new Map();
|
|
2788
|
+
for (const b of spec.basins ?? []) {
|
|
2789
|
+
const drain = world.drain(objectId, b.id);
|
|
2790
|
+
if (!drain) continue;
|
|
2791
|
+
const centre = [(b.from[0] + b.to[0]) / 2, b.from[1], (b.from[2] + b.to[2]) / 2];
|
|
2792
|
+
basins.set(b.id, { spec: b, drain, centre, frontRim: [centre[0], b.to[1], b.to[2]], clogged: false, overflowing: false, spill: 0, spillTime: 0 });
|
|
2793
|
+
}
|
|
2794
|
+
const flushes = new Map(
|
|
2795
|
+
(spec.fixtures ?? []).flatMap((f) => f.cleans && basins.has(f.cleans) ? [[f.id, { basin: f.cleans, litres: f.volume ?? FLUSH_LITRES }]] : [])
|
|
2796
|
+
);
|
|
2797
|
+
const list = [...basins.values()];
|
|
2798
|
+
let states = {};
|
|
2799
|
+
const pending = [];
|
|
2800
|
+
const swallowing = [];
|
|
2801
|
+
let plunging = null;
|
|
2802
|
+
const typeKey = `type.${spec.type}`;
|
|
2803
|
+
const name = () => {
|
|
2804
|
+
const text = t(typeKey);
|
|
2805
|
+
return text === typeKey ? spec.type.replace(/_/g, " ") : text.charAt(0).toLowerCase() + text.slice(1);
|
|
2806
|
+
};
|
|
2807
|
+
const takeLoose = (b, host) => {
|
|
2808
|
+
const top = [b.spec.to[0], b.spec.to[1] + 0.08, b.spec.to[2]];
|
|
2809
|
+
const inWater = new Set(b.drain.state().contents.flatMap((c) => c.objectId ? [c.objectId] : []));
|
|
2810
|
+
for (const thing of host?.looseInside?.(b.spec.from, top) ?? []) {
|
|
2811
|
+
if (inWater.has(thing.id)) continue;
|
|
2812
|
+
b.drain.add({ kind: "object", kg: thing.kg, size: thing.size, objectId: thing.id });
|
|
2813
|
+
}
|
|
2814
|
+
};
|
|
2815
|
+
const report = (b, host) => {
|
|
2816
|
+
const clogged = b.drain.clog() >= CLOGGED;
|
|
2817
|
+
if (clogged && !b.clogged) host?.say(t("clogged", { name: name() }));
|
|
2818
|
+
b.clogged = clogged;
|
|
2819
|
+
};
|
|
2820
|
+
const stepPending = (dt) => {
|
|
2821
|
+
let kept = 0;
|
|
2822
|
+
for (const p of pending) {
|
|
2823
|
+
p.left -= dt;
|
|
2824
|
+
if (p.left > 0) {
|
|
2825
|
+
pending[kept++] = p;
|
|
2826
|
+
continue;
|
|
2827
|
+
}
|
|
2828
|
+
for (const content of p.lands) basins.get(p.basin)?.drain.add(content);
|
|
2829
|
+
}
|
|
2830
|
+
pending.length = kept;
|
|
2831
|
+
};
|
|
2832
|
+
const stepPlunge = (dt, host) => {
|
|
2833
|
+
if (!plunging) return;
|
|
2834
|
+
const b = basins.get(plunging.basin);
|
|
2835
|
+
plunging.left -= dt;
|
|
2836
|
+
plunging.stroke += dt;
|
|
2837
|
+
if (b && plunging.stroke >= PLUNGE_STROKE_SECONDS) {
|
|
2838
|
+
plunging.stroke -= PLUNGE_STROKE_SECONDS;
|
|
2839
|
+
const cause = b.drain.cause();
|
|
2840
|
+
b.drain.plunge();
|
|
2841
|
+
if (cause !== "none" && b.drain.cause() === "none") {
|
|
2842
|
+
host?.say(t(cause === "object" ? "plunge_object" : "plunge_cleared", { name: name() }));
|
|
2843
|
+
b.clogged = false;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
if (plunging.left > 0) return;
|
|
2847
|
+
if (b && b.drain.clog() >= CLOGGED) host?.say(t("plunge_still", { name: name() }));
|
|
2848
|
+
plunging = null;
|
|
2849
|
+
};
|
|
2850
|
+
const stepSwallowing = (dt, host) => {
|
|
2851
|
+
let kept = 0;
|
|
2852
|
+
for (const s of swallowing) {
|
|
2853
|
+
s.time += dt;
|
|
2854
|
+
const progress = Math.min(1, s.time / SWALLOW_SECONDS);
|
|
2855
|
+
host?.swallow?.(s.id, s.point, progress);
|
|
2856
|
+
if (progress < 1) swallowing[kept++] = s;
|
|
2857
|
+
}
|
|
2858
|
+
swallowing.length = kept;
|
|
2859
|
+
};
|
|
2860
|
+
const stepSpill = (b, spilled, dt, host) => {
|
|
2861
|
+
if (spilled > 0 && !b.overflowing) host?.say(t("overflow", { name: name() }));
|
|
2862
|
+
b.overflowing = spilled > 0;
|
|
2863
|
+
b.spill += spilled;
|
|
2864
|
+
if (b.spill <= 0) return;
|
|
2865
|
+
b.spillTime += dt;
|
|
2866
|
+
if (b.spillTime < SPILL_GATHER_SECONDS) return;
|
|
2867
|
+
host?.spill?.(b.frontRim, b.spill, b.drain.dirty() ? "sewage" : "water");
|
|
2868
|
+
b.spill = 0;
|
|
2869
|
+
b.spillTime = 0;
|
|
2870
|
+
};
|
|
2871
|
+
const stepBasin = (b, dt, host) => {
|
|
2872
|
+
const step = b.drain.update(dt);
|
|
2873
|
+
for (const id of step.swallowed) swallowing.push({ id, point: b.centre, time: 0 });
|
|
2874
|
+
stepSpill(b, step.spilled, dt, host);
|
|
2875
|
+
host?.setBasin?.(b.spec.id, b.drain.litres());
|
|
2876
|
+
report(b, host);
|
|
2877
|
+
};
|
|
2878
|
+
return {
|
|
2879
|
+
has: (basin) => basins.has(basin),
|
|
2880
|
+
hostBlocked: (host) => HOST_NEEDS.find((need) => host[need] === void 0) ?? null,
|
|
2881
|
+
relieveBody(use, host) {
|
|
2882
|
+
const body = host.body?.();
|
|
2883
|
+
if (!body) return null;
|
|
2884
|
+
const seconds = use.seconds ?? RELIEVE_SECONDS;
|
|
2885
|
+
const b = basins.get(use.basin);
|
|
2886
|
+
if (use.kind === "urine" && use.stand && body.sex === "male") return { pose: "relieve_stand", seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
2887
|
+
return { pose: "relieve_sit", seconds, ...use.seat ? { seat: use.seat } : {} };
|
|
2888
|
+
},
|
|
2889
|
+
relieve(use, host, body) {
|
|
2890
|
+
if (use.cover) host.setPart(use.cover, true);
|
|
2891
|
+
if (use.ring) host.setPart(use.ring, body.pose === "relieve_stand");
|
|
2892
|
+
pending.push({ basin: use.basin, lands: use.kind === "urine" ? PEE : POO, left: body.seconds * LANDS_AT });
|
|
2893
|
+
return { ok: true, text: t(`done_relieve_${use.kind}`, { name: name() }), body };
|
|
2894
|
+
},
|
|
2895
|
+
plungeBlocked(use, host) {
|
|
2896
|
+
if (!host.hand()?.tools?.includes(use.tool)) return "needs_plunger";
|
|
2897
|
+
const b = basins.get(use.basin);
|
|
2898
|
+
return b && b.drain.level() < PLUNGER_WATER ? "plunge_no_water" : null;
|
|
2899
|
+
},
|
|
2900
|
+
plungeBody(use) {
|
|
2901
|
+
const b = basins.get(use.basin);
|
|
2902
|
+
return { pose: "plunge", seconds: use.seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
2903
|
+
},
|
|
2904
|
+
plunge(use, body) {
|
|
2905
|
+
plunging = { basin: use.basin, left: use.seconds, stroke: 0 };
|
|
2906
|
+
return { ok: true, text: t("done_plunge", { name: name() }), body };
|
|
2907
|
+
},
|
|
2908
|
+
flushed(fixture, host) {
|
|
2909
|
+
const flush = flushes.get(fixture);
|
|
2910
|
+
const b = flush ? basins.get(flush.basin) : void 0;
|
|
2911
|
+
if (!flush || !b) return false;
|
|
2912
|
+
takeLoose(b, host);
|
|
2913
|
+
b.drain.flush(flush.litres);
|
|
2914
|
+
return true;
|
|
2915
|
+
},
|
|
2916
|
+
update(dt, host) {
|
|
2917
|
+
stepPending(dt);
|
|
2918
|
+
stepPlunge(dt, host);
|
|
2919
|
+
stepSwallowing(dt, host);
|
|
2920
|
+
for (const b of list) stepBasin(b, dt, host);
|
|
2921
|
+
},
|
|
2922
|
+
dispose(host) {
|
|
2923
|
+
for (const s of swallowing) host?.swallow?.(s.id, s.point, 1);
|
|
2924
|
+
swallowing.length = 0;
|
|
2925
|
+
pending.length = 0;
|
|
2926
|
+
plunging = null;
|
|
2927
|
+
},
|
|
2928
|
+
soil(basin) {
|
|
2929
|
+
const contents = basins.get(basin)?.drain.state().contents ?? [];
|
|
2930
|
+
if (contents.some((c) => c.kind === "feces" || c.kind === "paper")) return "feces";
|
|
2931
|
+
return contents.some((c) => c.kind === "urine") ? "urine" : "clean";
|
|
2932
|
+
},
|
|
2933
|
+
state() {
|
|
2934
|
+
for (const b of list) {
|
|
2935
|
+
if (states[b.spec.id] === b.drain.state()) continue;
|
|
2936
|
+
states = Object.fromEntries(list.map((each) => [each.spec.id, each.drain.state()]));
|
|
2937
|
+
break;
|
|
2938
|
+
}
|
|
2939
|
+
return states;
|
|
2940
|
+
}
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2512
2944
|
// src/fits-volume.ts
|
|
2513
2945
|
function fitsInVolume(size, half) {
|
|
2514
2946
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2521,8 +2953,11 @@ var WASH_SCRUB_SECONDS = 3;
|
|
|
2521
2953
|
var DRINK_LITRES = 0.25;
|
|
2522
2954
|
var FILL_SHARE = 0.85;
|
|
2523
2955
|
var DRINK_LPS = 0.06;
|
|
2956
|
+
var DRINK_HANDS_LITRES = 0.12;
|
|
2957
|
+
var DRINK_HANDS_LPS = 0.03;
|
|
2524
2958
|
var REACH_SECONDS = 0.6;
|
|
2525
2959
|
var DRY_SECONDS = 0.5;
|
|
2960
|
+
var UNDER_STREAM = 0.14;
|
|
2526
2961
|
var SCRUBBED_DIRT = 0.15;
|
|
2527
2962
|
var YES = { available: true };
|
|
2528
2963
|
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
@@ -2541,16 +2976,59 @@ function dirtyDishes(use, spec, host) {
|
|
|
2541
2976
|
if (!dishes || !basin) return [];
|
|
2542
2977
|
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2543
2978
|
}
|
|
2979
|
+
function washBody(use, host) {
|
|
2980
|
+
const { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose } = host;
|
|
2981
|
+
if (!playUse || !lather || !rinse) return null;
|
|
2982
|
+
if (use.dishes && (!itemsInside || !placeItem || !setDirt)) return null;
|
|
2983
|
+
if (use.dose && !takeDose) return null;
|
|
2984
|
+
return { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose };
|
|
2985
|
+
}
|
|
2986
|
+
function vesselBody(host) {
|
|
2987
|
+
const { playUse, vesselAt, fillItem, drinkItem } = host;
|
|
2988
|
+
return playUse && vesselAt && fillItem && drinkItem ? { playUse, vesselAt, fillItem, drinkItem } : null;
|
|
2989
|
+
}
|
|
2990
|
+
function handsBody(host) {
|
|
2991
|
+
const { playUse, handsFree, drinkFromHands } = host;
|
|
2992
|
+
return playUse && handsFree && drinkFromHands ? { playUse, handsFree, drinkFromHands } : null;
|
|
2993
|
+
}
|
|
2994
|
+
var NO_BODY = { available: false, reason: "no_animation" };
|
|
2995
|
+
var NEEDS_FREE_HAND = { available: false, reason: "needs_free_hand" };
|
|
2544
2996
|
function sinkVerdict(use, spec, host, flowing) {
|
|
2545
|
-
if (use.do === "
|
|
2997
|
+
if (use.do === "drink") return drinkVerdict(use, host);
|
|
2998
|
+
if (!washBody(use, host)) return NO_BODY;
|
|
2999
|
+
if (use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2546
3000
|
const found = findNeeds(use.needs ?? [], host);
|
|
3001
|
+
if (!handsFreeFor(use, found.items, host)) return NEEDS_FREE_HAND;
|
|
2547
3002
|
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2548
|
-
if (use.do === "drink") return YES;
|
|
2549
3003
|
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2550
3004
|
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2551
3005
|
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2552
3006
|
return YES;
|
|
2553
3007
|
}
|
|
3008
|
+
function handsAreFree(host) {
|
|
3009
|
+
return host.handsFree?.() ?? host.hand() === null;
|
|
3010
|
+
}
|
|
3011
|
+
function handsFreeFor(use, needed, host) {
|
|
3012
|
+
if (handsAreFree(host)) return true;
|
|
3013
|
+
if (host.hand() === null) return false;
|
|
3014
|
+
if (needed.some((item) => item.where === "hand")) return true;
|
|
3015
|
+
return use.dishes !== void 0 && host.itemAt?.(use.dishes.ids)?.where === "hand";
|
|
3016
|
+
}
|
|
3017
|
+
function drinkVerdict(use, host) {
|
|
3018
|
+
if (use.from === "hands") {
|
|
3019
|
+
const body2 = handsBody(host);
|
|
3020
|
+
if (!body2) return NO_BODY;
|
|
3021
|
+
if (body2.handsFree()) return YES;
|
|
3022
|
+
return host.vesselAt?.()?.where === "hand" ? { available: false, reason: "drink_from_vessel" } : NEEDS_FREE_HAND;
|
|
3023
|
+
}
|
|
3024
|
+
const body = vesselBody(host);
|
|
3025
|
+
if (!body) return NO_BODY;
|
|
3026
|
+
const vessel = body.vesselAt();
|
|
3027
|
+
if (!vessel) return { available: false, reason: "needs_vessel" };
|
|
3028
|
+
if (vessel.where !== "hand") return { available: false, reason: "needs_in_hand", vars: { item: vessel.name } };
|
|
3029
|
+
const other = vessel.liquid?.kind !== void 0 && vessel.liquid.kind !== "water" && vessel.liquid.litres > 1e-3;
|
|
3030
|
+
return other ? { available: false, reason: "vessel_not_empty", vars: { item: vessel.name } } : YES;
|
|
3031
|
+
}
|
|
2554
3032
|
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2555
3033
|
function runPhases(phases) {
|
|
2556
3034
|
let index = 0;
|
|
@@ -2574,6 +3052,10 @@ function createSinkRoutines(options) {
|
|
|
2574
3052
|
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2575
3053
|
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2576
3054
|
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
3055
|
+
const underStream = (use) => {
|
|
3056
|
+
const outlet = fixtureOf(use.fixture)?.outlet;
|
|
3057
|
+
return outlet ? [outlet[0], outlet[1] - UNDER_STREAM, outlet[2]] : void 0;
|
|
3058
|
+
};
|
|
2577
3059
|
const waterOf = (use) => {
|
|
2578
3060
|
let dry = 0;
|
|
2579
3061
|
return (dt) => {
|
|
@@ -2582,6 +3064,14 @@ function createSinkRoutines(options) {
|
|
|
2582
3064
|
return dry > DRY_SECONDS ? null : flow;
|
|
2583
3065
|
};
|
|
2584
3066
|
};
|
|
3067
|
+
const approachPhase = (use, host) => {
|
|
3068
|
+
let walked = 0;
|
|
3069
|
+
const at = underStream(use);
|
|
3070
|
+
return (dt) => {
|
|
3071
|
+
walked += dt;
|
|
3072
|
+
return !at || !host.approach || walked > REACH_SECONDS * 3 || host.approach(at, dt);
|
|
3073
|
+
};
|
|
3074
|
+
};
|
|
2585
3075
|
const tapPhases = (use) => {
|
|
2586
3076
|
let opened = false;
|
|
2587
3077
|
const reach = wait(REACH_SECONDS);
|
|
@@ -2598,7 +3088,7 @@ function createSinkRoutines(options) {
|
|
|
2598
3088
|
}
|
|
2599
3089
|
};
|
|
2600
3090
|
};
|
|
2601
|
-
const scrubAndRinse = (use,
|
|
3091
|
+
const scrubAndRinse = (use, body, target, fail) => {
|
|
2602
3092
|
const item = typeof target === "string" ? void 0 : target;
|
|
2603
3093
|
const id = item?.objectId ?? target;
|
|
2604
3094
|
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
@@ -2607,11 +3097,14 @@ function createSinkRoutines(options) {
|
|
|
2607
3097
|
const scrub = (dt) => {
|
|
2608
3098
|
if (scrubbed < 0) {
|
|
2609
3099
|
scrubbed = 0;
|
|
2610
|
-
|
|
3100
|
+
if (!body.playUse(use.clip, item?.objectId, underStream(use))) {
|
|
3101
|
+
fail({ key: "hands_busy", ok: false });
|
|
3102
|
+
return true;
|
|
3103
|
+
}
|
|
2611
3104
|
}
|
|
2612
3105
|
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2613
|
-
|
|
2614
|
-
if (dirt > 0)
|
|
3106
|
+
body.lather(id, dt / seconds);
|
|
3107
|
+
if (dirt > 0) body.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2615
3108
|
return scrubbed >= seconds;
|
|
2616
3109
|
};
|
|
2617
3110
|
const running = waterOf(use);
|
|
@@ -2621,13 +3114,13 @@ function createSinkRoutines(options) {
|
|
|
2621
3114
|
fail({ key: "no_water", ok: false });
|
|
2622
3115
|
return true;
|
|
2623
3116
|
}
|
|
2624
|
-
if (flow <= 0 ||
|
|
2625
|
-
if (dirt > 0)
|
|
3117
|
+
if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
|
|
3118
|
+
if (dirt > 0) body.setDirt?.(id, 0);
|
|
2626
3119
|
return true;
|
|
2627
3120
|
};
|
|
2628
3121
|
return [scrub, rinse];
|
|
2629
3122
|
};
|
|
2630
|
-
const startWash = (use, host) => {
|
|
3123
|
+
const startWash = (use, host, body) => {
|
|
2631
3124
|
const { items } = findNeeds(use.needs ?? [], host);
|
|
2632
3125
|
let end = null;
|
|
2633
3126
|
const fail = (reason) => {
|
|
@@ -2635,60 +3128,144 @@ function createSinkRoutines(options) {
|
|
|
2635
3128
|
};
|
|
2636
3129
|
const tap = tapPhases(use);
|
|
2637
3130
|
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2638
|
-
const
|
|
2639
|
-
|
|
3131
|
+
const waterForDose = waterOf(use);
|
|
3132
|
+
const dose = (dt) => {
|
|
3133
|
+
const flow = waterForDose(dt);
|
|
3134
|
+
if (flow === null) {
|
|
3135
|
+
fail({ key: "no_water", ok: false });
|
|
3136
|
+
return true;
|
|
3137
|
+
}
|
|
3138
|
+
if (flow <= 0) return false;
|
|
3139
|
+
if (dosed && body.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2640
3140
|
return true;
|
|
2641
3141
|
};
|
|
2642
3142
|
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2643
3143
|
const rack = use.dishes?.rack ?? [];
|
|
2644
|
-
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use,
|
|
3144
|
+
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use, body, dish, fail), placePhase(host, dish, rack[Math.min(index, rack.length - 1)])]) : scrubAndRinse(use, body, use.surface, fail);
|
|
2645
3145
|
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2646
|
-
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
3146
|
+
const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close]);
|
|
2647
3147
|
const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
|
|
2648
3148
|
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2649
3149
|
};
|
|
2650
|
-
const startDrink = (use, host, vessel) => {
|
|
3150
|
+
const startDrink = (use, host, body, vessel) => {
|
|
2651
3151
|
const tap = tapPhases(use);
|
|
2652
3152
|
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2653
3153
|
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2654
3154
|
let drunk = 0;
|
|
2655
3155
|
let end = null;
|
|
2656
|
-
const take = () => {
|
|
2657
|
-
if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
|
|
2658
|
-
else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
|
|
2659
|
-
return true;
|
|
2660
|
-
};
|
|
2661
3156
|
const running = waterOf(use);
|
|
3157
|
+
const played = (clip, at) => {
|
|
3158
|
+
if (body.playUse(clip, vessel.objectId, at)) return true;
|
|
3159
|
+
end ?? (end = { key: "hands_busy", ok: false });
|
|
3160
|
+
return false;
|
|
3161
|
+
};
|
|
3162
|
+
let filling = false;
|
|
2662
3163
|
const fill = (dt) => {
|
|
2663
3164
|
if (end) return true;
|
|
3165
|
+
if (!filling && !(filling = played(use.fillClip ?? "fill_cup", underStream(use)))) return true;
|
|
2664
3166
|
const flow = running(dt);
|
|
2665
3167
|
if (flow === null) {
|
|
2666
3168
|
end = { key: "no_water", ok: false };
|
|
2667
3169
|
return true;
|
|
2668
3170
|
}
|
|
2669
3171
|
if (flow <= 0) return false;
|
|
2670
|
-
const took =
|
|
3172
|
+
const took = body.fillItem(vessel.objectId, "water", Math.min(flow * dt, want - filled));
|
|
2671
3173
|
filled += took;
|
|
2672
3174
|
return filled >= want - 1e-6 || took <= 0;
|
|
2673
3175
|
};
|
|
2674
3176
|
let sipping = false;
|
|
2675
3177
|
const drink = (dt) => {
|
|
2676
3178
|
if (end) return true;
|
|
2677
|
-
if (!sipping
|
|
2678
|
-
const sip =
|
|
3179
|
+
if (!sipping && !(sipping = played(use.clip))) return true;
|
|
3180
|
+
const sip = body.drinkItem(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk));
|
|
2679
3181
|
drunk += sip;
|
|
2680
3182
|
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2681
3183
|
};
|
|
2682
|
-
const
|
|
2683
|
-
const
|
|
2684
|
-
return { use: use.id, step: (dt) => run(dt) ? end ??
|
|
3184
|
+
const run = runPhases([approachPhase(use, host), tap.open, fill, tap.close, drink]);
|
|
3185
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3186
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
2685
3187
|
};
|
|
3188
|
+
const startDrinkHands = (use, host, body) => {
|
|
3189
|
+
const tap = tapPhases(use);
|
|
3190
|
+
const want = use.litres ?? DRINK_HANDS_LITRES;
|
|
3191
|
+
let drunk = 0;
|
|
3192
|
+
let end = null;
|
|
3193
|
+
const running = waterOf(use);
|
|
3194
|
+
let bent = false;
|
|
3195
|
+
const drink = (dt) => {
|
|
3196
|
+
if (!bent) {
|
|
3197
|
+
bent = body.playUse(use.clip, void 0, underStream(use));
|
|
3198
|
+
if (!bent) {
|
|
3199
|
+
end = { key: "hands_busy", ok: false };
|
|
3200
|
+
return true;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
const flow = running(dt);
|
|
3204
|
+
if (flow === null) {
|
|
3205
|
+
end = { key: "no_water", ok: false };
|
|
3206
|
+
return true;
|
|
3207
|
+
}
|
|
3208
|
+
if (flow <= 0) return false;
|
|
3209
|
+
const sip = body.drinkFromHands("water", Math.min(DRINK_HANDS_LPS * dt, flow * dt, want - drunk));
|
|
3210
|
+
drunk += sip;
|
|
3211
|
+
return drunk >= want - 1e-6 || sip <= 0;
|
|
3212
|
+
};
|
|
3213
|
+
const run = runPhases([approachPhase(use, host), tap.open, drink, tap.close]);
|
|
3214
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink_hands", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3215
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
3216
|
+
};
|
|
3217
|
+
const refused = (use, key) => ({ use: use.id, step: () => ({ key, ok: false }) });
|
|
2686
3218
|
return {
|
|
2687
3219
|
start(use, host) {
|
|
2688
|
-
if (use.do === "wash")
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
3220
|
+
if (use.do === "wash") {
|
|
3221
|
+
const body2 = washBody(use, host);
|
|
3222
|
+
return body2 ? startWash(use, host, body2) : refused(use, "no_animation");
|
|
3223
|
+
}
|
|
3224
|
+
if (use.from === "hands") {
|
|
3225
|
+
const body2 = handsBody(host);
|
|
3226
|
+
return body2 ? startDrinkHands(use, host, body2) : refused(use, "no_animation");
|
|
3227
|
+
}
|
|
3228
|
+
const body = vesselBody(host);
|
|
3229
|
+
const vessel = body?.vesselAt();
|
|
3230
|
+
if (!body) return refused(use, "no_animation");
|
|
3231
|
+
return vessel ? startDrink(use, host, body, vessel) : refused(use, "needs_vessel");
|
|
3232
|
+
}
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
|
|
3236
|
+
// src/use-body.ts
|
|
3237
|
+
function createUseBody() {
|
|
3238
|
+
let running = null;
|
|
3239
|
+
const end = () => {
|
|
3240
|
+
const was = running;
|
|
3241
|
+
running = null;
|
|
3242
|
+
was?.body.end();
|
|
3243
|
+
};
|
|
3244
|
+
return {
|
|
3245
|
+
blocked(action, host) {
|
|
3246
|
+
const body = host.body?.();
|
|
3247
|
+
if (!body) return "needs_body";
|
|
3248
|
+
const why = body.blocked(action);
|
|
3249
|
+
return why ? `body_${why}` : null;
|
|
3250
|
+
},
|
|
3251
|
+
begin(action, host) {
|
|
3252
|
+
const body = host.body?.();
|
|
3253
|
+
if (!body) return false;
|
|
3254
|
+
end();
|
|
3255
|
+
if (!body.begin(action)) return false;
|
|
3256
|
+
running = { action, body, time: 0 };
|
|
3257
|
+
return true;
|
|
3258
|
+
},
|
|
3259
|
+
update(dt) {
|
|
3260
|
+
if (!running) return;
|
|
3261
|
+
running.time += dt;
|
|
3262
|
+
const { action, body, time } = running;
|
|
3263
|
+
if (!body.step(time, Math.min(1, time / action.seconds))) running = null;
|
|
3264
|
+
else if (time >= action.seconds) end();
|
|
3265
|
+
},
|
|
3266
|
+
end,
|
|
3267
|
+
get pose() {
|
|
3268
|
+
return running ? { pose: running.action.pose, time: running.time, progress: Math.min(1, running.time / running.action.seconds) } : null;
|
|
2692
3269
|
}
|
|
2693
3270
|
};
|
|
2694
3271
|
}
|
|
@@ -2711,7 +3288,7 @@ var clock = (seconds) => {
|
|
|
2711
3288
|
};
|
|
2712
3289
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2713
3290
|
var YES2 = { available: true };
|
|
2714
|
-
var no = (reason) => ({ available: false, reason });
|
|
3291
|
+
var no = (reason, vars) => ({ available: false, reason, ...vars ? { vars } : {} });
|
|
2715
3292
|
function createUses(options) {
|
|
2716
3293
|
const { spec, world, objectId } = options;
|
|
2717
3294
|
const all = spec.uses ?? [];
|
|
@@ -2724,6 +3301,8 @@ function createUses(options) {
|
|
|
2724
3301
|
let lastHost = null;
|
|
2725
3302
|
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2726
3303
|
let routine = null;
|
|
3304
|
+
const drains = createDrainUses({ spec, world, objectId, t: (key, vars) => world.t(key, vars) });
|
|
3305
|
+
const useBody = createUseBody();
|
|
2727
3306
|
const typeKey = `type.${spec.type}`;
|
|
2728
3307
|
const name = () => {
|
|
2729
3308
|
const text = world.t(typeKey);
|
|
@@ -2754,12 +3333,28 @@ function createUses(options) {
|
|
|
2754
3333
|
return fits ? YES2 : no("not_accepted");
|
|
2755
3334
|
}
|
|
2756
3335
|
case "relieve":
|
|
2757
|
-
return YES2;
|
|
3336
|
+
return drains.has(use.basin) ? drainVerdict(host, () => handsAreFree(host) ? null : "needs_free_hand", () => drains.relieveBody(use, host)) : YES2;
|
|
2758
3337
|
case "wash":
|
|
2759
3338
|
case "drink":
|
|
2760
3339
|
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
3340
|
+
case "plunge":
|
|
3341
|
+
return drainVerdict(host, () => drains.plungeBlocked(use, host), () => drains.plungeBody(use));
|
|
2761
3342
|
}
|
|
2762
3343
|
};
|
|
3344
|
+
const drainVerdict = (host, rule, body) => {
|
|
3345
|
+
const missing = drains.hostBlocked(host);
|
|
3346
|
+
if (missing) return no("host_lacks", { capability: missing });
|
|
3347
|
+
const broken = rule();
|
|
3348
|
+
if (broken) return no(broken);
|
|
3349
|
+
const action = body();
|
|
3350
|
+
if (!action) return no("needs_body");
|
|
3351
|
+
const why = useBody.blocked(action, host);
|
|
3352
|
+
return why ? no(why) : YES2;
|
|
3353
|
+
};
|
|
3354
|
+
const withBody = (action, host, vars, run) => {
|
|
3355
|
+
if (!action) return { ok: false, text: world.t("needs_body", vars) };
|
|
3356
|
+
return useBody.begin(action, host) ? run(action) : { ok: false, text: world.t("body_busy", vars) };
|
|
3357
|
+
};
|
|
2763
3358
|
const itemName = (id) => {
|
|
2764
3359
|
const text = world.t(`item.${id}`);
|
|
2765
3360
|
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
@@ -2795,7 +3390,10 @@ function createUses(options) {
|
|
|
2795
3390
|
}
|
|
2796
3391
|
case "fill":
|
|
2797
3392
|
return fill(bowls.get(use.bowl), host, vars);
|
|
3393
|
+
case "plunge":
|
|
3394
|
+
return withBody(drains.plungeBody(use), host, vars, (action) => drains.plunge(use, action));
|
|
2798
3395
|
case "relieve": {
|
|
3396
|
+
if (drains.has(use.basin)) return withBody(drains.relieveBody(use, host), host, vars, (action) => drains.relieve(use, host, action));
|
|
2799
3397
|
const now = soil.get(use.basin) ?? "clean";
|
|
2800
3398
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2801
3399
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
@@ -2853,7 +3451,10 @@ function createUses(options) {
|
|
|
2853
3451
|
const v = verdict(use, host);
|
|
2854
3452
|
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2855
3453
|
},
|
|
2856
|
-
update(dt) {
|
|
3454
|
+
update(dt, host) {
|
|
3455
|
+
if (host) lastHost = host;
|
|
3456
|
+
drains.update(dt, lastHost);
|
|
3457
|
+
useBody.update(dt);
|
|
2857
3458
|
stepRoutine(dt);
|
|
2858
3459
|
if (!program) return;
|
|
2859
3460
|
program.left -= dt;
|
|
@@ -2863,17 +3464,25 @@ function createUses(options) {
|
|
|
2863
3464
|
program = null;
|
|
2864
3465
|
lastHost?.say(done);
|
|
2865
3466
|
},
|
|
2866
|
-
flushed(fixture) {
|
|
3467
|
+
flushed(fixture, host) {
|
|
3468
|
+
if (host) lastHost = host;
|
|
3469
|
+
if (drains.flushed(fixture, lastHost)) return;
|
|
2867
3470
|
const basin = cleans.get(fixture);
|
|
2868
3471
|
if (!basin || soil.get(basin) === "clean") return;
|
|
2869
3472
|
soil.set(basin, "clean");
|
|
2870
3473
|
lastHost?.say(world.t("done_clean", { name: name() }));
|
|
2871
3474
|
},
|
|
3475
|
+
dispose(host) {
|
|
3476
|
+
drains.dispose(host ?? lastHost);
|
|
3477
|
+
useBody.end();
|
|
3478
|
+
},
|
|
2872
3479
|
state: () => ({
|
|
2873
3480
|
bowls: Object.fromEntries(level),
|
|
2874
|
-
soil: Object.fromEntries(soil),
|
|
3481
|
+
soil: Object.fromEntries([...soil].map(([id, now]) => [id, drains.has(id) ? drains.soil(id) : now])),
|
|
3482
|
+
drains: drains.state(),
|
|
2875
3483
|
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2876
|
-
routine: routine?.use ?? null
|
|
3484
|
+
routine: routine?.use ?? null,
|
|
3485
|
+
body: useBody.pose
|
|
2877
3486
|
})
|
|
2878
3487
|
};
|
|
2879
3488
|
}
|
|
@@ -2901,7 +3510,7 @@ function createObjectControls(options) {
|
|
|
2901
3510
|
onEvent: (event) => {
|
|
2902
3511
|
if (event.type === "message") said.push(event.text);
|
|
2903
3512
|
if (event.type === "part" && event.object === CONTROLLED_OBJECT) forwardPart(event.part, event.target >= 0.5);
|
|
2904
|
-
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture);
|
|
3513
|
+
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture, host ?? void 0);
|
|
2905
3514
|
}
|
|
2906
3515
|
});
|
|
2907
3516
|
const forwardPart = (part, open) => {
|
|
@@ -2946,14 +3555,17 @@ function createObjectControls(options) {
|
|
|
2946
3555
|
update(dt, lent) {
|
|
2947
3556
|
lend(lent);
|
|
2948
3557
|
world.update(dt);
|
|
2949
|
-
uses.update(dt);
|
|
3558
|
+
uses.update(dt, lent);
|
|
2950
3559
|
},
|
|
2951
3560
|
state() {
|
|
2952
3561
|
const screens = (spec.devices ?? []).filter((d) => d.kind === "screen" && world.power.isOn(CONTROLLED_OBJECT, d.id) && world.power.isPowered(CONTROLLED_OBJECT, d.id)).map((d) => ({ device: d.id, channel: world.power.channel(CONTROLLED_OBJECT, d.id) }));
|
|
2953
3562
|
const emitters = world.emitters().filter((e) => e.object === CONTROLLED_OBJECT && e.kind !== "water");
|
|
2954
3563
|
return { ...uses.state(), screens, emitters };
|
|
2955
3564
|
},
|
|
3565
|
+
serialize: () => world.serialize(),
|
|
3566
|
+
load: (state) => world.load(state),
|
|
2956
3567
|
dispose() {
|
|
3568
|
+
uses.dispose(host ?? void 0);
|
|
2957
3569
|
host = null;
|
|
2958
3570
|
world.remove(CONTROLLED_OBJECT);
|
|
2959
3571
|
world.remove(MAINS);
|
|
@@ -2961,14 +3573,18 @@ function createObjectControls(options) {
|
|
|
2961
3573
|
};
|
|
2962
3574
|
}
|
|
2963
3575
|
export {
|
|
3576
|
+
CLOGGED,
|
|
2964
3577
|
COLLAR_REACH,
|
|
2965
3578
|
CONTROLLED_OBJECT,
|
|
3579
|
+
DRINK_HANDS_LITRES,
|
|
3580
|
+
DRINK_HANDS_LPS,
|
|
2966
3581
|
DRINK_LITRES,
|
|
2967
3582
|
DRINK_LPS,
|
|
2968
3583
|
DRY_SECONDS,
|
|
2969
3584
|
END_GAP,
|
|
2970
3585
|
FILL_SHARE,
|
|
2971
3586
|
FLOW_DEFAULTS,
|
|
3587
|
+
FLUSH_POUR_SECONDS,
|
|
2972
3588
|
FLUSH_RUN_SECONDS,
|
|
2973
3589
|
GESTURE_OF_ACTION,
|
|
2974
3590
|
GESTURE_OF_USE,
|
|
@@ -2978,10 +3594,13 @@ export {
|
|
|
2978
3594
|
buildChain,
|
|
2979
3595
|
castWithMember,
|
|
2980
3596
|
chainPoints,
|
|
3597
|
+
createBasinDrain,
|
|
3598
|
+
createDrainUses,
|
|
2981
3599
|
createEnginePartPhysics,
|
|
2982
3600
|
createFixtureEmitters,
|
|
2983
3601
|
createObjectControls,
|
|
2984
3602
|
createSinkRoutines,
|
|
3603
|
+
createUseBody,
|
|
2985
3604
|
createWorld,
|
|
2986
3605
|
devicePointOf,
|
|
2987
3606
|
dirtyDishes,
|
|
@@ -2996,6 +3615,7 @@ export {
|
|
|
2996
3615
|
generateLoot,
|
|
2997
3616
|
hangTail,
|
|
2998
3617
|
hashString,
|
|
3618
|
+
laidSize,
|
|
2999
3619
|
localToWorld,
|
|
3000
3620
|
locales,
|
|
3001
3621
|
mergeColliders,
|