@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.global.js
CHANGED
|
@@ -21,14 +21,18 @@ var GameInteractables = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
CLOGGED: () => CLOGGED,
|
|
24
25
|
COLLAR_REACH: () => COLLAR_REACH,
|
|
25
26
|
CONTROLLED_OBJECT: () => CONTROLLED_OBJECT,
|
|
27
|
+
DRINK_HANDS_LITRES: () => DRINK_HANDS_LITRES,
|
|
28
|
+
DRINK_HANDS_LPS: () => DRINK_HANDS_LPS,
|
|
26
29
|
DRINK_LITRES: () => DRINK_LITRES,
|
|
27
30
|
DRINK_LPS: () => DRINK_LPS,
|
|
28
31
|
DRY_SECONDS: () => DRY_SECONDS,
|
|
29
32
|
END_GAP: () => END_GAP,
|
|
30
33
|
FILL_SHARE: () => FILL_SHARE,
|
|
31
34
|
FLOW_DEFAULTS: () => FLOW_DEFAULTS,
|
|
35
|
+
FLUSH_POUR_SECONDS: () => FLUSH_POUR_SECONDS,
|
|
32
36
|
FLUSH_RUN_SECONDS: () => FLUSH_RUN_SECONDS,
|
|
33
37
|
GESTURE_OF_ACTION: () => GESTURE_OF_ACTION,
|
|
34
38
|
GESTURE_OF_USE: () => GESTURE_OF_USE,
|
|
@@ -38,10 +42,13 @@ var GameInteractables = (() => {
|
|
|
38
42
|
buildChain: () => buildChain,
|
|
39
43
|
castWithMember: () => castWithMember,
|
|
40
44
|
chainPoints: () => chainPoints,
|
|
45
|
+
createBasinDrain: () => createBasinDrain,
|
|
46
|
+
createDrainUses: () => createDrainUses,
|
|
41
47
|
createEnginePartPhysics: () => createEnginePartPhysics,
|
|
42
48
|
createFixtureEmitters: () => createFixtureEmitters,
|
|
43
49
|
createObjectControls: () => createObjectControls,
|
|
44
50
|
createSinkRoutines: () => createSinkRoutines,
|
|
51
|
+
createUseBody: () => createUseBody,
|
|
45
52
|
createWorld: () => createWorld,
|
|
46
53
|
devicePointOf: () => devicePointOf,
|
|
47
54
|
dirtyDishes: () => dirtyDishes,
|
|
@@ -56,6 +63,7 @@ var GameInteractables = (() => {
|
|
|
56
63
|
generateLoot: () => generateLoot,
|
|
57
64
|
hangTail: () => hangTail,
|
|
58
65
|
hashString: () => hashString,
|
|
66
|
+
laidSize: () => laidSize,
|
|
59
67
|
localToWorld: () => localToWorld,
|
|
60
68
|
locales: () => locales,
|
|
61
69
|
mergeColliders: () => mergeColliders,
|
|
@@ -74,6 +82,199 @@ var GameInteractables = (() => {
|
|
|
74
82
|
wrapsMember: () => wrapsMember
|
|
75
83
|
});
|
|
76
84
|
|
|
85
|
+
// src/basin-drain.ts
|
|
86
|
+
var FLUSH_POUR_SECONDS = 3;
|
|
87
|
+
var CLOGGED = 0.5;
|
|
88
|
+
var REFILL_RATE = 0.12;
|
|
89
|
+
var BREAK_DEPTH = 0.035;
|
|
90
|
+
var WEIR_SHARE = 0.25;
|
|
91
|
+
var SEEP = 0.04;
|
|
92
|
+
var TURN_PER_LITRE = 2.4;
|
|
93
|
+
var TRAP_LITRES = 3.5;
|
|
94
|
+
var PLUNGE_PACKED = 0.34;
|
|
95
|
+
var PLUNGE_LODGED = 0.2;
|
|
96
|
+
var PLUNGER_WATER = 0.03;
|
|
97
|
+
var SOFT_SQUEEZE = 1.6;
|
|
98
|
+
var SWIRL_SETTLED = 1e-4;
|
|
99
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
100
|
+
var passingSize = (size) => [...size].sort((a, b) => b - a)[1] ?? 0;
|
|
101
|
+
function createBasinDrain(basin, drain) {
|
|
102
|
+
const width = basin.to[0] - basin.from[0];
|
|
103
|
+
const deep = basin.to[2] - basin.from[2];
|
|
104
|
+
const radius = Math.min(width, deep) / 2;
|
|
105
|
+
const area = basin.shape === "round" ? Math.PI * radius * radius : width * deep;
|
|
106
|
+
const litresAt = (level) => area * level * 1e3;
|
|
107
|
+
const levelOf = (litres) => litres / (area * 1e3);
|
|
108
|
+
const capacity = litresAt(basin.to[1] - basin.from[1]);
|
|
109
|
+
const still = litresAt(drain.weir);
|
|
110
|
+
const water = { litres: still, phase: "still", swirl: 0, turned: 0, clog: 0, cause: "none", cistern: 1, pouring: 0, pourRate: 0, carried: 0 };
|
|
111
|
+
let serial = 0;
|
|
112
|
+
let contents = [];
|
|
113
|
+
let shown = null;
|
|
114
|
+
const step = { spilled: 0, swallowed: [] };
|
|
115
|
+
const open = () => Math.max(SEEP, 1 - water.clog);
|
|
116
|
+
const lodge = (c, packed) => {
|
|
117
|
+
c.stage = "lodged";
|
|
118
|
+
c.depth = 1;
|
|
119
|
+
c.radius = 0;
|
|
120
|
+
water.clog = packed ? Math.max(water.clog, Math.min(0.95, water.clog + 0.55 + 0.3 * (c.kg / drain.carries))) : 0.97;
|
|
121
|
+
water.cause = water.cause === "object" || !packed ? "object" : "packed";
|
|
122
|
+
};
|
|
123
|
+
const reachTrap = (c, swallowed) => {
|
|
124
|
+
const hard = c.kind === "object";
|
|
125
|
+
if (passingSize(c.size) > drain.trap * (hard ? 1 : SOFT_SQUEEZE) || !hard && water.carried + c.kg > drain.carries) {
|
|
126
|
+
lodge(c, !hard);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (!hard) water.carried += c.kg;
|
|
130
|
+
c.stage = "gone";
|
|
131
|
+
if (c.objectId) swallowed.push(c.objectId);
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
const stepContents = (moved, pulled, swallowed) => {
|
|
135
|
+
water.turned += moved * TURN_PER_LITRE;
|
|
136
|
+
const takesUrine = water.phase === "siphon" && water.swirl > 0.3;
|
|
137
|
+
let leaving = false;
|
|
138
|
+
for (const c of contents) {
|
|
139
|
+
if (c.kind === "urine" && takesUrine) leaving = true;
|
|
140
|
+
if (c.stage === "gone" || c.stage === "lodged") continue;
|
|
141
|
+
c.angle = c.start + water.turned;
|
|
142
|
+
if (water.phase !== "siphon" || c.kind === "urine") continue;
|
|
143
|
+
c.stage = "going";
|
|
144
|
+
c.travel = clamp01(c.travel + pulled / TRAP_LITRES);
|
|
145
|
+
c.depth = Math.max(c.depth, c.travel);
|
|
146
|
+
c.radius = c.startRadius * (1 - c.travel);
|
|
147
|
+
if (c.travel >= 1 && reachTrap(c, swallowed)) leaving = true;
|
|
148
|
+
}
|
|
149
|
+
if (leaving) contents = contents.filter((c) => c.stage !== "gone" && !(c.kind === "urine" && takesUrine));
|
|
150
|
+
};
|
|
151
|
+
const outflow = (dt) => {
|
|
152
|
+
const level = levelOf(water.litres);
|
|
153
|
+
if (water.phase === "siphon") return drain.siphon * open() * dt * Math.sqrt(clamp01(level / Math.max(1e-3, drain.weir)));
|
|
154
|
+
const head = level - drain.weir;
|
|
155
|
+
if (head <= 0) return 0;
|
|
156
|
+
return drain.siphon * WEIR_SHARE * open() * dt * Math.sqrt(clamp01(head / drain.prime));
|
|
157
|
+
};
|
|
158
|
+
const stepPhase = () => {
|
|
159
|
+
const head = levelOf(water.litres) - drain.weir;
|
|
160
|
+
if (water.phase !== "siphon" && head >= drain.prime && open() > CLOGGED) {
|
|
161
|
+
water.phase = "siphon";
|
|
162
|
+
water.carried = 0;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (water.phase === "siphon" && (head <= -BREAK_DEPTH || open() <= CLOGGED)) water.phase = "refill";
|
|
166
|
+
if (water.phase === "refill" && water.litres >= still - 1e-6 && water.pouring <= 0) water.phase = "still";
|
|
167
|
+
if (water.phase === "still" && water.pouring > 0) water.phase = "filling";
|
|
168
|
+
if (water.phase === "filling" && water.pouring <= 0 && head <= 1e-4) water.phase = "still";
|
|
169
|
+
};
|
|
170
|
+
const stepInflow = (dt) => {
|
|
171
|
+
const poured = water.pouring > 0 ? water.pourRate * Math.min(dt, water.pouring) : 0;
|
|
172
|
+
water.pouring = Math.max(0, water.pouring - dt);
|
|
173
|
+
water.litres += poured;
|
|
174
|
+
if ((water.phase === "refill" || water.phase === "still") && water.litres < still && water.clog < CLOGGED) water.litres = Math.min(still, water.litres + REFILL_RATE * dt);
|
|
175
|
+
return poured;
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
flush(asked) {
|
|
179
|
+
shown = null;
|
|
180
|
+
const litresIn = asked * water.cistern;
|
|
181
|
+
water.cistern = 0;
|
|
182
|
+
if (litresIn <= 0) return 0;
|
|
183
|
+
water.pouring = FLUSH_POUR_SECONDS;
|
|
184
|
+
water.pourRate = litresIn / FLUSH_POUR_SECONDS;
|
|
185
|
+
if (water.phase === "still") water.phase = "filling";
|
|
186
|
+
return litresIn;
|
|
187
|
+
},
|
|
188
|
+
add(content) {
|
|
189
|
+
shown = null;
|
|
190
|
+
water.litres += content.litres ?? 0;
|
|
191
|
+
const k = serial++;
|
|
192
|
+
const start = k * 2.39996;
|
|
193
|
+
const startRadius = 0.25 + k * 0.37 % 0.45;
|
|
194
|
+
contents.push({
|
|
195
|
+
start,
|
|
196
|
+
startRadius,
|
|
197
|
+
travel: 0,
|
|
198
|
+
id: `c${k}`,
|
|
199
|
+
kind: content.kind,
|
|
200
|
+
kg: content.kg,
|
|
201
|
+
size: content.size,
|
|
202
|
+
...content.objectId ? { objectId: content.objectId } : {},
|
|
203
|
+
stage: "afloat",
|
|
204
|
+
angle: start + water.turned,
|
|
205
|
+
radius: startRadius,
|
|
206
|
+
depth: content.kind === "object" ? 0.5 : 0
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
plunge() {
|
|
210
|
+
shown = null;
|
|
211
|
+
if (levelOf(water.litres) < PLUNGER_WATER) return false;
|
|
212
|
+
if (water.clog <= 0) return true;
|
|
213
|
+
const lodged = contents.filter((c) => c.stage === "lodged");
|
|
214
|
+
const hard = lodged.some((c) => c.kind === "object");
|
|
215
|
+
water.clog = Math.max(0, water.clog - (hard ? PLUNGE_LODGED : PLUNGE_PACKED));
|
|
216
|
+
if (water.clog > CLOGGED * 0.4) return true;
|
|
217
|
+
water.clog = 0;
|
|
218
|
+
water.cause = "none";
|
|
219
|
+
for (const c of lodged) {
|
|
220
|
+
if (c.kind === "object") Object.assign(c, { stage: "afloat", depth: 0.6, radius: 0.3, startRadius: 0.3, travel: 0 });
|
|
221
|
+
else c.stage = "gone";
|
|
222
|
+
}
|
|
223
|
+
contents = contents.filter((c) => c.stage !== "gone");
|
|
224
|
+
return true;
|
|
225
|
+
},
|
|
226
|
+
update(dt) {
|
|
227
|
+
step.spilled = 0;
|
|
228
|
+
step.swallowed.length = 0;
|
|
229
|
+
if (dt <= 0) return step;
|
|
230
|
+
const { litres, swirl, cistern, phase, clog } = water;
|
|
231
|
+
const count = contents.length;
|
|
232
|
+
water.cistern = clamp01(water.cistern + dt / drain.refill);
|
|
233
|
+
const poured = stepInflow(dt);
|
|
234
|
+
const out = Math.min(water.litres, outflow(dt));
|
|
235
|
+
water.litres -= out;
|
|
236
|
+
stepPhase();
|
|
237
|
+
const pull = water.phase === "siphon" ? clamp01(out / (drain.siphon * dt)) : 0;
|
|
238
|
+
const jets = poured > 0 ? 0.35 : 0;
|
|
239
|
+
const swirlTo = Math.max(pull, jets);
|
|
240
|
+
water.swirl = Math.abs(swirlTo - water.swirl) < SWIRL_SETTLED ? swirlTo : water.swirl + (swirlTo - water.swirl) * clamp01(dt * 6);
|
|
241
|
+
const moved = poured + out;
|
|
242
|
+
stepContents(moved, water.phase === "siphon" ? out : 0, step.swallowed);
|
|
243
|
+
step.spilled = Math.max(0, water.litres - capacity);
|
|
244
|
+
water.litres -= step.spilled;
|
|
245
|
+
const changed = moved > 0 || water.litres !== litres || water.swirl !== swirl || water.cistern !== cistern || water.phase !== phase || water.clog !== clog || contents.length !== count;
|
|
246
|
+
if (changed) shown = null;
|
|
247
|
+
return step;
|
|
248
|
+
},
|
|
249
|
+
state() {
|
|
250
|
+
shown ?? (shown = {
|
|
251
|
+
litres: water.litres,
|
|
252
|
+
level: levelOf(water.litres),
|
|
253
|
+
phase: water.phase,
|
|
254
|
+
swirl: water.swirl,
|
|
255
|
+
turned: water.turned,
|
|
256
|
+
clog: water.clog,
|
|
257
|
+
cause: water.cause,
|
|
258
|
+
cistern: water.cistern,
|
|
259
|
+
contents: contents.map(({ start: _start, startRadius: _startRadius, travel: _travel, ...c }) => c)
|
|
260
|
+
});
|
|
261
|
+
return shown;
|
|
262
|
+
},
|
|
263
|
+
litres: () => water.litres,
|
|
264
|
+
level: () => levelOf(water.litres),
|
|
265
|
+
clog: () => water.clog,
|
|
266
|
+
cause: () => water.cause,
|
|
267
|
+
dirty: () => contents.some((c) => c.kind !== "object"),
|
|
268
|
+
save: () => ({ water: { ...water }, serial, contents: contents.map((c) => ({ ...c })) }),
|
|
269
|
+
restore(saved) {
|
|
270
|
+
shown = null;
|
|
271
|
+
Object.assign(water, saved.water);
|
|
272
|
+
serial = saved.serial;
|
|
273
|
+
contents = saved.contents.map((c) => ({ ...c }));
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
77
278
|
// src/gestures.ts
|
|
78
279
|
var GESTURE_OF_ACTION = {
|
|
79
280
|
toggle_part: null,
|
|
@@ -97,6 +298,7 @@ var GameInteractables = (() => {
|
|
|
97
298
|
empty: "tip",
|
|
98
299
|
fill: "pour",
|
|
99
300
|
relieve: null,
|
|
301
|
+
plunge: null,
|
|
100
302
|
wash: null,
|
|
101
303
|
drink: null
|
|
102
304
|
};
|
|
@@ -235,9 +437,14 @@ var GameInteractables = (() => {
|
|
|
235
437
|
if (size[1] > max[1] + eps) return false;
|
|
236
438
|
return size[0] <= max[0] + eps && size[2] <= max[2] + eps || size[2] <= max[0] + eps && size[0] <= max[2] + eps;
|
|
237
439
|
}
|
|
440
|
+
function laidSize(size, lay) {
|
|
441
|
+
if (lay === "x") return [size[1], size[0], size[2]];
|
|
442
|
+
if (lay === "z") return [size[0], size[2], size[1]];
|
|
443
|
+
return size;
|
|
444
|
+
}
|
|
238
445
|
function fitsSlot(type, slot, items) {
|
|
239
446
|
const def = items?.[type];
|
|
240
|
-
return def ? fitsSize(def.size, slot.max) : true;
|
|
447
|
+
return def ? fitsSize(laidSize(def.size, slot.lay), slot.max) : true;
|
|
241
448
|
}
|
|
242
449
|
function generateLoot(tables, tableId, slots, seed, items) {
|
|
243
450
|
const table = tables?.[tableId];
|
|
@@ -325,7 +532,21 @@ var GameInteractables = (() => {
|
|
|
325
532
|
done_relieve_feces: "You pooed in {name}",
|
|
326
533
|
done_clean: "{name} flushed clean",
|
|
327
534
|
"use.wash_dishes": "Wash the dishes",
|
|
328
|
-
"use.drink_water": "Drink water",
|
|
535
|
+
"use.drink_water": "Drink water from the glass",
|
|
536
|
+
"use.drink_from_hands": "Drink water from your hands",
|
|
537
|
+
"use.lather_body": "Soap yourself",
|
|
538
|
+
"use.shampoo_hair": "Shampoo your hair",
|
|
539
|
+
"use.wash_hands": "Wash your hands",
|
|
540
|
+
"use.brush_teeth": "Brush your teeth",
|
|
541
|
+
needs_in_hand: "Pick up {item} first",
|
|
542
|
+
needs_vessel: "You need a glass",
|
|
543
|
+
vessel_not_empty: "Empty {item} first",
|
|
544
|
+
hands_busy: "Your hands are busy",
|
|
545
|
+
no_animation: "Cannot be done here: the body has no movement for it",
|
|
546
|
+
needs_free_hand: "You need your hands free",
|
|
547
|
+
not_drunk: "No water was drunk",
|
|
548
|
+
drink_from_vessel: "You have a glass in your hand: drink from it",
|
|
549
|
+
done_drink_hands: "You drank {litres} l of water from your hands",
|
|
329
550
|
busy: "Already in use",
|
|
330
551
|
needs_running: "Turn the water on first",
|
|
331
552
|
needs_item: "You need {need}",
|
|
@@ -335,7 +556,21 @@ var GameInteractables = (() => {
|
|
|
335
556
|
started_drink: "{label}\u2026",
|
|
336
557
|
done_wash: "Washed and rinsed",
|
|
337
558
|
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
338
|
-
done_drink: "You drank {litres} l of water"
|
|
559
|
+
done_drink: "You drank {litres} l of water",
|
|
560
|
+
"use.plunge": "Unclog {name} with the plunger",
|
|
561
|
+
needs_plunger: "Hold a plunger",
|
|
562
|
+
plunge_no_water: "No water over the trap for the plunger",
|
|
563
|
+
done_plunge: "You work the plunger in {name}",
|
|
564
|
+
plunge_cleared: "{name} unclogged: the water goes down",
|
|
565
|
+
plunge_object: "{name} unclogged: something came back up the trap",
|
|
566
|
+
plunge_still: "{name} is still clogged",
|
|
567
|
+
clogged: "{name} is clogged",
|
|
568
|
+
overflow: "{name} is overflowing",
|
|
569
|
+
needs_body: "There is no body here to use {name}",
|
|
570
|
+
host_lacks: "This place cannot run {name} (it lacks {capability})",
|
|
571
|
+
body_no_seat: "{name} has no seat to sit on",
|
|
572
|
+
body_object_gone: "{name} is not here",
|
|
573
|
+
body_busy: "You are busy with something else"
|
|
339
574
|
},
|
|
340
575
|
"pt-BR": {
|
|
341
576
|
"prompt.open": "Abrir {name}",
|
|
@@ -390,7 +625,21 @@ var GameInteractables = (() => {
|
|
|
390
625
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
391
626
|
done_clean: "Descarga dada: {name} limpo",
|
|
392
627
|
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
393
|
-
"use.drink_water": "Beber \xE1gua",
|
|
628
|
+
"use.drink_water": "Beber \xE1gua no copo",
|
|
629
|
+
"use.drink_from_hands": "Beber \xE1gua com a m\xE3o",
|
|
630
|
+
"use.lather_body": "Ensaboar-se",
|
|
631
|
+
"use.shampoo_hair": "Passar shampoo",
|
|
632
|
+
"use.wash_hands": "Lavar as m\xE3os",
|
|
633
|
+
"use.brush_teeth": "Escovar os dentes",
|
|
634
|
+
needs_in_hand: "Pegue {item} antes",
|
|
635
|
+
needs_vessel: "Precisa de um copo",
|
|
636
|
+
vessel_not_empty: "Esvazie {item} antes",
|
|
637
|
+
hands_busy: "As m\xE3os est\xE3o ocupadas",
|
|
638
|
+
no_animation: "N\xE3o d\xE1 para fazer isso aqui: o corpo n\xE3o tem o movimento",
|
|
639
|
+
needs_free_hand: "Precisa das m\xE3os livres",
|
|
640
|
+
not_drunk: "Nenhuma \xE1gua foi bebida",
|
|
641
|
+
drink_from_vessel: "Voc\xEA est\xE1 com um copo na m\xE3o: beba nele",
|
|
642
|
+
done_drink_hands: "Voc\xEA bebeu {litres} l de \xE1gua com a m\xE3o",
|
|
394
643
|
busy: "J\xE1 est\xE1 em uso",
|
|
395
644
|
needs_running: "Abra a \xE1gua primeiro",
|
|
396
645
|
needs_item: "Precisa de {need}",
|
|
@@ -400,7 +649,21 @@ var GameInteractables = (() => {
|
|
|
400
649
|
started_drink: "{label}\u2026",
|
|
401
650
|
done_wash: "Lavado e enxaguado",
|
|
402
651
|
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
403
|
-
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
652
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua",
|
|
653
|
+
"use.plunge": "Desentupir {name} com o desentupidor",
|
|
654
|
+
needs_plunger: "Segure um desentupidor",
|
|
655
|
+
plunge_no_water: "Sem \xE1gua sobre o sif\xE3o para o desentupidor",
|
|
656
|
+
done_plunge: "Voc\xEA bombeia o desentupidor em {name}",
|
|
657
|
+
plunge_cleared: "{name} desentupido: a \xE1gua desce",
|
|
658
|
+
plunge_object: "{name} desentupido: uma coisa voltou do sif\xE3o",
|
|
659
|
+
plunge_still: "{name} ainda est\xE1 entupido",
|
|
660
|
+
clogged: "{name} entupiu",
|
|
661
|
+
overflow: "{name} est\xE1 transbordando",
|
|
662
|
+
needs_body: "N\xE3o h\xE1 corpo aqui para usar {name}",
|
|
663
|
+
host_lacks: "Este lugar n\xE3o sabe usar {name} (falta {capability})",
|
|
664
|
+
body_no_seat: "{name} n\xE3o tem assento para sentar",
|
|
665
|
+
body_object_gone: "{name} n\xE3o est\xE1 aqui",
|
|
666
|
+
body_busy: "Voc\xEA est\xE1 ocupado com outra coisa"
|
|
404
667
|
}
|
|
405
668
|
};
|
|
406
669
|
function pickLocale(locale) {
|
|
@@ -1807,6 +2070,7 @@ var GameInteractables = (() => {
|
|
|
1807
2070
|
burners: /* @__PURE__ */ new Map(),
|
|
1808
2071
|
tanks: /* @__PURE__ */ new Map(),
|
|
1809
2072
|
fixtures: /* @__PURE__ */ new Map(),
|
|
2073
|
+
drains: /* @__PURE__ */ new Map(),
|
|
1810
2074
|
soft: /* @__PURE__ */ new Map(),
|
|
1811
2075
|
hp: /* @__PURE__ */ new Map(),
|
|
1812
2076
|
interactions: spec.interactions ?? deriveInteractions(spec)
|
|
@@ -1839,6 +2103,7 @@ var GameInteractables = (() => {
|
|
|
1839
2103
|
for (const b of spec.burners ?? []) o.burners.set(b.id, { spec: b, on: false, lit: false, smoke: 0 });
|
|
1840
2104
|
for (const tk of spec.tanks ?? []) o.tanks.set(tk.id, { spec: tk, level: clamp(tk.level ?? tk.capacity, 0, tk.capacity) });
|
|
1841
2105
|
for (const f of spec.fixtures ?? []) o.fixtures.set(f.id, { spec: f, on: false, flowing: false, frac: 0, timer: 0 });
|
|
2106
|
+
for (const b of spec.basins ?? []) if (b.drain) o.drains.set(b.id, createBasinDrain(b, b.drain));
|
|
1842
2107
|
let n = 0;
|
|
1843
2108
|
for (const s of spec.soft ?? []) {
|
|
1844
2109
|
const driver = options.partPhysics?.attachSoft?.(id, s, pub.transform);
|
|
@@ -1871,7 +2136,8 @@ var GameInteractables = (() => {
|
|
|
1871
2136
|
burners: Object.fromEntries([...o.burners].map(([k, b]) => [k, { on: b.on, lit: b.lit }])),
|
|
1872
2137
|
tanks: Object.fromEntries([...o.tanks].map(([k, tk]) => [k, tk.level])),
|
|
1873
2138
|
fixtures: Object.fromEntries([...o.fixtures].map(([k, f]) => [k, f.on])),
|
|
1874
|
-
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp]))
|
|
2139
|
+
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp])),
|
|
2140
|
+
drains: Object.fromEntries([...o.drains].map(([k, d]) => [k, d.save()]))
|
|
1875
2141
|
};
|
|
1876
2142
|
}
|
|
1877
2143
|
return {
|
|
@@ -1937,6 +2203,7 @@ var GameInteractables = (() => {
|
|
|
1937
2203
|
const h = o.hp.get(k);
|
|
1938
2204
|
if (h) h.hp = v;
|
|
1939
2205
|
}
|
|
2206
|
+
for (const [k, v] of Object.entries(st.drains ?? {})) o.drains.get(k)?.restore(v);
|
|
1940
2207
|
}
|
|
1941
2208
|
grid = state.grid;
|
|
1942
2209
|
main = state.main ?? true;
|
|
@@ -2061,6 +2328,7 @@ var GameInteractables = (() => {
|
|
|
2061
2328
|
locale = l;
|
|
2062
2329
|
table = resolveStrings(locale, options.strings);
|
|
2063
2330
|
},
|
|
2331
|
+
drain: (objectId, basin) => objs.get(objectId)?.drains.get(basin),
|
|
2064
2332
|
serialize,
|
|
2065
2333
|
load
|
|
2066
2334
|
};
|
|
@@ -2585,6 +2853,272 @@ var GameInteractables = (() => {
|
|
|
2585
2853
|
return wrapsMember(member, other) || endsMember(member, other);
|
|
2586
2854
|
}
|
|
2587
2855
|
|
|
2856
|
+
// ../game-contracts/dist/index.js
|
|
2857
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
2858
|
+
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
2859
|
+
var DEFERRED_QUEUE_ID = {
|
|
2860
|
+
DESTRUCTION_EVENTS: "destruction.events",
|
|
2861
|
+
BREACH_PAINT: "floorplan.breach-paint",
|
|
2862
|
+
BREACH_CUT: "floorplan.breach-cut",
|
|
2863
|
+
AUDIO_VOICES: "audio.voices",
|
|
2864
|
+
VEHICLE_CREASE: "vehicles.crease",
|
|
2865
|
+
AUDIO_OCCLUSION: "audio.occlusion",
|
|
2866
|
+
FLUID_FILM: "fluids.film",
|
|
2867
|
+
VEHICLE_LOD_BATCH: "vehicles.lod-batch",
|
|
2868
|
+
SETTLED_BATCH: "destruction.settled-batch",
|
|
2869
|
+
STATIC_BATCH: "render.static-batch",
|
|
2870
|
+
ANIMALS_STATIC_BATCH: "animals.static-batch",
|
|
2871
|
+
CHARACTERS_STATIC_BATCH: "characters.static-batch",
|
|
2872
|
+
HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
|
|
2873
|
+
DESTRUCTION_PREFIT: "destruction.prefit"
|
|
2874
|
+
};
|
|
2875
|
+
var DEFERRED_PRIORITY = {
|
|
2876
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
|
|
2877
|
+
// every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
|
|
2878
|
+
[DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
|
|
2879
|
+
[DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
|
|
2880
|
+
[DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
|
|
2881
|
+
[DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
|
|
2882
|
+
[DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
|
|
2883
|
+
[DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
|
|
2884
|
+
[DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
|
|
2885
|
+
[DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
|
|
2886
|
+
[DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2887
|
+
[DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2888
|
+
[DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2889
|
+
[DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
|
|
2890
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
|
|
2891
|
+
};
|
|
2892
|
+
var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
|
|
2893
|
+
var PLUNGE_STROKE_SECONDS = 0.8;
|
|
2894
|
+
var BODY_FOAM_SURFACES = ["hands", "arms", "torso", "hair", "mouth"];
|
|
2895
|
+
var WASH_SURFACES = [...BODY_FOAM_SURFACES, "brush"];
|
|
2896
|
+
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
2897
|
+
var GAIT_IDS = ["walk", "run"];
|
|
2898
|
+
var LANDING_IDS = ["light", "heavy"];
|
|
2899
|
+
var BODY_SOUND_IDS = [
|
|
2900
|
+
"jump",
|
|
2901
|
+
"cloth_rustle",
|
|
2902
|
+
"body_fall",
|
|
2903
|
+
"fall_damage",
|
|
2904
|
+
"player_hurt",
|
|
2905
|
+
"player_breath_run",
|
|
2906
|
+
"player_death",
|
|
2907
|
+
"bite",
|
|
2908
|
+
"grab",
|
|
2909
|
+
"punch_swing",
|
|
2910
|
+
"punch_hit_body",
|
|
2911
|
+
"punch_hit_face",
|
|
2912
|
+
"punch_hit_object",
|
|
2913
|
+
"kick_swing",
|
|
2914
|
+
"kick_hit",
|
|
2915
|
+
"kick_hit_object",
|
|
2916
|
+
"shove_two_hands",
|
|
2917
|
+
"knife_swing",
|
|
2918
|
+
"knife_stab",
|
|
2919
|
+
"knife_slash",
|
|
2920
|
+
"knife_hit_object",
|
|
2921
|
+
"blunt_swing",
|
|
2922
|
+
"blunt_hit",
|
|
2923
|
+
"blunt_hit_object",
|
|
2924
|
+
"axe_swing",
|
|
2925
|
+
"axe_chop",
|
|
2926
|
+
"axe_hit_object"
|
|
2927
|
+
];
|
|
2928
|
+
var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
|
|
2929
|
+
var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
|
|
2930
|
+
var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
|
|
2931
|
+
var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
|
|
2932
|
+
var WORKER_KIND_ID = {
|
|
2933
|
+
GROUND_TILES: "destruction.ground-tiles",
|
|
2934
|
+
CROWD_PHYSICS: "crowd.physics",
|
|
2935
|
+
PIECE_BOXES: "destruction.piece-boxes",
|
|
2936
|
+
STATIC_COLLIDERS: "destruction.static-colliders",
|
|
2937
|
+
SHAPES_GENERATE: "shapes.generate",
|
|
2938
|
+
WORLD_REGION: "world.region",
|
|
2939
|
+
VEHICLE_HULL_PLAN: "vehicles.hull-plan"
|
|
2940
|
+
};
|
|
2941
|
+
var WORKER_KIND_DEFAULTS = {
|
|
2942
|
+
[WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
|
|
2943
|
+
[WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
|
|
2944
|
+
[WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
|
|
2945
|
+
[WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
|
|
2946
|
+
[WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
|
|
2947
|
+
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
|
|
2948
|
+
[WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
|
|
2949
|
+
};
|
|
2950
|
+
|
|
2951
|
+
// src/drain-uses.ts
|
|
2952
|
+
var RELIEVE_SECONDS = 8;
|
|
2953
|
+
var LANDS_AT = 0.7;
|
|
2954
|
+
var FLUSH_LITRES = 6;
|
|
2955
|
+
var SWALLOW_SECONDS = 0.5;
|
|
2956
|
+
var SPILL_GATHER_SECONDS = 0.25;
|
|
2957
|
+
var URINE = { kind: "urine", kg: 0.3, litres: 0.3, size: [0.02, 0.02, 0.02] };
|
|
2958
|
+
var FECES = { kind: "feces", kg: 0.2, size: [0.12, 0.035, 0.035] };
|
|
2959
|
+
var PAPER = { kind: "paper", kg: 8e-3, size: [0.06, 0.03, 0.03] };
|
|
2960
|
+
var PEE = [URINE];
|
|
2961
|
+
var POO = [FECES, PAPER, PAPER];
|
|
2962
|
+
var HOST_NEEDS = ["setBasin", "spill", "looseInside", "swallow"];
|
|
2963
|
+
function createDrainUses(options) {
|
|
2964
|
+
const { spec, t, world, objectId } = options;
|
|
2965
|
+
const basins = /* @__PURE__ */ new Map();
|
|
2966
|
+
for (const b of spec.basins ?? []) {
|
|
2967
|
+
const drain = world.drain(objectId, b.id);
|
|
2968
|
+
if (!drain) continue;
|
|
2969
|
+
const centre = [(b.from[0] + b.to[0]) / 2, b.from[1], (b.from[2] + b.to[2]) / 2];
|
|
2970
|
+
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 });
|
|
2971
|
+
}
|
|
2972
|
+
const flushes = new Map(
|
|
2973
|
+
(spec.fixtures ?? []).flatMap((f) => f.cleans && basins.has(f.cleans) ? [[f.id, { basin: f.cleans, litres: f.volume ?? FLUSH_LITRES }]] : [])
|
|
2974
|
+
);
|
|
2975
|
+
const list = [...basins.values()];
|
|
2976
|
+
let states = {};
|
|
2977
|
+
const pending = [];
|
|
2978
|
+
const swallowing = [];
|
|
2979
|
+
let plunging = null;
|
|
2980
|
+
const typeKey = `type.${spec.type}`;
|
|
2981
|
+
const name = () => {
|
|
2982
|
+
const text = t(typeKey);
|
|
2983
|
+
return text === typeKey ? spec.type.replace(/_/g, " ") : text.charAt(0).toLowerCase() + text.slice(1);
|
|
2984
|
+
};
|
|
2985
|
+
const takeLoose = (b, host) => {
|
|
2986
|
+
const top = [b.spec.to[0], b.spec.to[1] + 0.08, b.spec.to[2]];
|
|
2987
|
+
const inWater = new Set(b.drain.state().contents.flatMap((c) => c.objectId ? [c.objectId] : []));
|
|
2988
|
+
for (const thing of host?.looseInside?.(b.spec.from, top) ?? []) {
|
|
2989
|
+
if (inWater.has(thing.id)) continue;
|
|
2990
|
+
b.drain.add({ kind: "object", kg: thing.kg, size: thing.size, objectId: thing.id });
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
const report = (b, host) => {
|
|
2994
|
+
const clogged = b.drain.clog() >= CLOGGED;
|
|
2995
|
+
if (clogged && !b.clogged) host?.say(t("clogged", { name: name() }));
|
|
2996
|
+
b.clogged = clogged;
|
|
2997
|
+
};
|
|
2998
|
+
const stepPending = (dt) => {
|
|
2999
|
+
let kept = 0;
|
|
3000
|
+
for (const p of pending) {
|
|
3001
|
+
p.left -= dt;
|
|
3002
|
+
if (p.left > 0) {
|
|
3003
|
+
pending[kept++] = p;
|
|
3004
|
+
continue;
|
|
3005
|
+
}
|
|
3006
|
+
for (const content of p.lands) basins.get(p.basin)?.drain.add(content);
|
|
3007
|
+
}
|
|
3008
|
+
pending.length = kept;
|
|
3009
|
+
};
|
|
3010
|
+
const stepPlunge = (dt, host) => {
|
|
3011
|
+
if (!plunging) return;
|
|
3012
|
+
const b = basins.get(plunging.basin);
|
|
3013
|
+
plunging.left -= dt;
|
|
3014
|
+
plunging.stroke += dt;
|
|
3015
|
+
if (b && plunging.stroke >= PLUNGE_STROKE_SECONDS) {
|
|
3016
|
+
plunging.stroke -= PLUNGE_STROKE_SECONDS;
|
|
3017
|
+
const cause = b.drain.cause();
|
|
3018
|
+
b.drain.plunge();
|
|
3019
|
+
if (cause !== "none" && b.drain.cause() === "none") {
|
|
3020
|
+
host?.say(t(cause === "object" ? "plunge_object" : "plunge_cleared", { name: name() }));
|
|
3021
|
+
b.clogged = false;
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
if (plunging.left > 0) return;
|
|
3025
|
+
if (b && b.drain.clog() >= CLOGGED) host?.say(t("plunge_still", { name: name() }));
|
|
3026
|
+
plunging = null;
|
|
3027
|
+
};
|
|
3028
|
+
const stepSwallowing = (dt, host) => {
|
|
3029
|
+
let kept = 0;
|
|
3030
|
+
for (const s of swallowing) {
|
|
3031
|
+
s.time += dt;
|
|
3032
|
+
const progress = Math.min(1, s.time / SWALLOW_SECONDS);
|
|
3033
|
+
host?.swallow?.(s.id, s.point, progress);
|
|
3034
|
+
if (progress < 1) swallowing[kept++] = s;
|
|
3035
|
+
}
|
|
3036
|
+
swallowing.length = kept;
|
|
3037
|
+
};
|
|
3038
|
+
const stepSpill = (b, spilled, dt, host) => {
|
|
3039
|
+
if (spilled > 0 && !b.overflowing) host?.say(t("overflow", { name: name() }));
|
|
3040
|
+
b.overflowing = spilled > 0;
|
|
3041
|
+
b.spill += spilled;
|
|
3042
|
+
if (b.spill <= 0) return;
|
|
3043
|
+
b.spillTime += dt;
|
|
3044
|
+
if (b.spillTime < SPILL_GATHER_SECONDS) return;
|
|
3045
|
+
host?.spill?.(b.frontRim, b.spill, b.drain.dirty() ? "sewage" : "water");
|
|
3046
|
+
b.spill = 0;
|
|
3047
|
+
b.spillTime = 0;
|
|
3048
|
+
};
|
|
3049
|
+
const stepBasin = (b, dt, host) => {
|
|
3050
|
+
const step = b.drain.update(dt);
|
|
3051
|
+
for (const id of step.swallowed) swallowing.push({ id, point: b.centre, time: 0 });
|
|
3052
|
+
stepSpill(b, step.spilled, dt, host);
|
|
3053
|
+
host?.setBasin?.(b.spec.id, b.drain.litres());
|
|
3054
|
+
report(b, host);
|
|
3055
|
+
};
|
|
3056
|
+
return {
|
|
3057
|
+
has: (basin) => basins.has(basin),
|
|
3058
|
+
hostBlocked: (host) => HOST_NEEDS.find((need) => host[need] === void 0) ?? null,
|
|
3059
|
+
relieveBody(use, host) {
|
|
3060
|
+
const body = host.body?.();
|
|
3061
|
+
if (!body) return null;
|
|
3062
|
+
const seconds = use.seconds ?? RELIEVE_SECONDS;
|
|
3063
|
+
const b = basins.get(use.basin);
|
|
3064
|
+
if (use.kind === "urine" && use.stand && body.sex === "male") return { pose: "relieve_stand", seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
3065
|
+
return { pose: "relieve_sit", seconds, ...use.seat ? { seat: use.seat } : {} };
|
|
3066
|
+
},
|
|
3067
|
+
relieve(use, host, body) {
|
|
3068
|
+
if (use.cover) host.setPart(use.cover, true);
|
|
3069
|
+
if (use.ring) host.setPart(use.ring, body.pose === "relieve_stand");
|
|
3070
|
+
pending.push({ basin: use.basin, lands: use.kind === "urine" ? PEE : POO, left: body.seconds * LANDS_AT });
|
|
3071
|
+
return { ok: true, text: t(`done_relieve_${use.kind}`, { name: name() }), body };
|
|
3072
|
+
},
|
|
3073
|
+
plungeBlocked(use, host) {
|
|
3074
|
+
if (!host.hand()?.tools?.includes(use.tool)) return "needs_plunger";
|
|
3075
|
+
const b = basins.get(use.basin);
|
|
3076
|
+
return b && b.drain.level() < PLUNGER_WATER ? "plunge_no_water" : null;
|
|
3077
|
+
},
|
|
3078
|
+
plungeBody(use) {
|
|
3079
|
+
const b = basins.get(use.basin);
|
|
3080
|
+
return { pose: "plunge", seconds: use.seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
3081
|
+
},
|
|
3082
|
+
plunge(use, body) {
|
|
3083
|
+
plunging = { basin: use.basin, left: use.seconds, stroke: 0 };
|
|
3084
|
+
return { ok: true, text: t("done_plunge", { name: name() }), body };
|
|
3085
|
+
},
|
|
3086
|
+
flushed(fixture, host) {
|
|
3087
|
+
const flush = flushes.get(fixture);
|
|
3088
|
+
const b = flush ? basins.get(flush.basin) : void 0;
|
|
3089
|
+
if (!flush || !b) return false;
|
|
3090
|
+
takeLoose(b, host);
|
|
3091
|
+
b.drain.flush(flush.litres);
|
|
3092
|
+
return true;
|
|
3093
|
+
},
|
|
3094
|
+
update(dt, host) {
|
|
3095
|
+
stepPending(dt);
|
|
3096
|
+
stepPlunge(dt, host);
|
|
3097
|
+
stepSwallowing(dt, host);
|
|
3098
|
+
for (const b of list) stepBasin(b, dt, host);
|
|
3099
|
+
},
|
|
3100
|
+
dispose(host) {
|
|
3101
|
+
for (const s of swallowing) host?.swallow?.(s.id, s.point, 1);
|
|
3102
|
+
swallowing.length = 0;
|
|
3103
|
+
pending.length = 0;
|
|
3104
|
+
plunging = null;
|
|
3105
|
+
},
|
|
3106
|
+
soil(basin) {
|
|
3107
|
+
const contents = basins.get(basin)?.drain.state().contents ?? [];
|
|
3108
|
+
if (contents.some((c) => c.kind === "feces" || c.kind === "paper")) return "feces";
|
|
3109
|
+
return contents.some((c) => c.kind === "urine") ? "urine" : "clean";
|
|
3110
|
+
},
|
|
3111
|
+
state() {
|
|
3112
|
+
for (const b of list) {
|
|
3113
|
+
if (states[b.spec.id] === b.drain.state()) continue;
|
|
3114
|
+
states = Object.fromEntries(list.map((each) => [each.spec.id, each.drain.state()]));
|
|
3115
|
+
break;
|
|
3116
|
+
}
|
|
3117
|
+
return states;
|
|
3118
|
+
}
|
|
3119
|
+
};
|
|
3120
|
+
}
|
|
3121
|
+
|
|
2588
3122
|
// src/fits-volume.ts
|
|
2589
3123
|
function fitsInVolume(size, half) {
|
|
2590
3124
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2597,8 +3131,11 @@ var GameInteractables = (() => {
|
|
|
2597
3131
|
var DRINK_LITRES = 0.25;
|
|
2598
3132
|
var FILL_SHARE = 0.85;
|
|
2599
3133
|
var DRINK_LPS = 0.06;
|
|
3134
|
+
var DRINK_HANDS_LITRES = 0.12;
|
|
3135
|
+
var DRINK_HANDS_LPS = 0.03;
|
|
2600
3136
|
var REACH_SECONDS = 0.6;
|
|
2601
3137
|
var DRY_SECONDS = 0.5;
|
|
3138
|
+
var UNDER_STREAM = 0.14;
|
|
2602
3139
|
var SCRUBBED_DIRT = 0.15;
|
|
2603
3140
|
var YES = { available: true };
|
|
2604
3141
|
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
@@ -2617,16 +3154,59 @@ var GameInteractables = (() => {
|
|
|
2617
3154
|
if (!dishes || !basin) return [];
|
|
2618
3155
|
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2619
3156
|
}
|
|
3157
|
+
function washBody(use, host) {
|
|
3158
|
+
const { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose } = host;
|
|
3159
|
+
if (!playUse || !lather || !rinse) return null;
|
|
3160
|
+
if (use.dishes && (!itemsInside || !placeItem || !setDirt)) return null;
|
|
3161
|
+
if (use.dose && !takeDose) return null;
|
|
3162
|
+
return { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose };
|
|
3163
|
+
}
|
|
3164
|
+
function vesselBody(host) {
|
|
3165
|
+
const { playUse, vesselAt, fillItem, drinkItem } = host;
|
|
3166
|
+
return playUse && vesselAt && fillItem && drinkItem ? { playUse, vesselAt, fillItem, drinkItem } : null;
|
|
3167
|
+
}
|
|
3168
|
+
function handsBody(host) {
|
|
3169
|
+
const { playUse, handsFree, drinkFromHands } = host;
|
|
3170
|
+
return playUse && handsFree && drinkFromHands ? { playUse, handsFree, drinkFromHands } : null;
|
|
3171
|
+
}
|
|
3172
|
+
var NO_BODY = { available: false, reason: "no_animation" };
|
|
3173
|
+
var NEEDS_FREE_HAND = { available: false, reason: "needs_free_hand" };
|
|
2620
3174
|
function sinkVerdict(use, spec, host, flowing) {
|
|
2621
|
-
if (use.do === "
|
|
3175
|
+
if (use.do === "drink") return drinkVerdict(use, host);
|
|
3176
|
+
if (!washBody(use, host)) return NO_BODY;
|
|
3177
|
+
if (use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2622
3178
|
const found = findNeeds(use.needs ?? [], host);
|
|
3179
|
+
if (!handsFreeFor(use, found.items, host)) return NEEDS_FREE_HAND;
|
|
2623
3180
|
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2624
|
-
if (use.do === "drink") return YES;
|
|
2625
3181
|
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2626
3182
|
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2627
3183
|
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2628
3184
|
return YES;
|
|
2629
3185
|
}
|
|
3186
|
+
function handsAreFree(host) {
|
|
3187
|
+
return host.handsFree?.() ?? host.hand() === null;
|
|
3188
|
+
}
|
|
3189
|
+
function handsFreeFor(use, needed, host) {
|
|
3190
|
+
if (handsAreFree(host)) return true;
|
|
3191
|
+
if (host.hand() === null) return false;
|
|
3192
|
+
if (needed.some((item) => item.where === "hand")) return true;
|
|
3193
|
+
return use.dishes !== void 0 && host.itemAt?.(use.dishes.ids)?.where === "hand";
|
|
3194
|
+
}
|
|
3195
|
+
function drinkVerdict(use, host) {
|
|
3196
|
+
if (use.from === "hands") {
|
|
3197
|
+
const body2 = handsBody(host);
|
|
3198
|
+
if (!body2) return NO_BODY;
|
|
3199
|
+
if (body2.handsFree()) return YES;
|
|
3200
|
+
return host.vesselAt?.()?.where === "hand" ? { available: false, reason: "drink_from_vessel" } : NEEDS_FREE_HAND;
|
|
3201
|
+
}
|
|
3202
|
+
const body = vesselBody(host);
|
|
3203
|
+
if (!body) return NO_BODY;
|
|
3204
|
+
const vessel = body.vesselAt();
|
|
3205
|
+
if (!vessel) return { available: false, reason: "needs_vessel" };
|
|
3206
|
+
if (vessel.where !== "hand") return { available: false, reason: "needs_in_hand", vars: { item: vessel.name } };
|
|
3207
|
+
const other = vessel.liquid?.kind !== void 0 && vessel.liquid.kind !== "water" && vessel.liquid.litres > 1e-3;
|
|
3208
|
+
return other ? { available: false, reason: "vessel_not_empty", vars: { item: vessel.name } } : YES;
|
|
3209
|
+
}
|
|
2630
3210
|
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2631
3211
|
function runPhases(phases) {
|
|
2632
3212
|
let index = 0;
|
|
@@ -2650,6 +3230,10 @@ var GameInteractables = (() => {
|
|
|
2650
3230
|
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2651
3231
|
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2652
3232
|
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
3233
|
+
const underStream = (use) => {
|
|
3234
|
+
const outlet = fixtureOf(use.fixture)?.outlet;
|
|
3235
|
+
return outlet ? [outlet[0], outlet[1] - UNDER_STREAM, outlet[2]] : void 0;
|
|
3236
|
+
};
|
|
2653
3237
|
const waterOf = (use) => {
|
|
2654
3238
|
let dry = 0;
|
|
2655
3239
|
return (dt) => {
|
|
@@ -2658,6 +3242,14 @@ var GameInteractables = (() => {
|
|
|
2658
3242
|
return dry > DRY_SECONDS ? null : flow;
|
|
2659
3243
|
};
|
|
2660
3244
|
};
|
|
3245
|
+
const approachPhase = (use, host) => {
|
|
3246
|
+
let walked = 0;
|
|
3247
|
+
const at = underStream(use);
|
|
3248
|
+
return (dt) => {
|
|
3249
|
+
walked += dt;
|
|
3250
|
+
return !at || !host.approach || walked > REACH_SECONDS * 3 || host.approach(at, dt);
|
|
3251
|
+
};
|
|
3252
|
+
};
|
|
2661
3253
|
const tapPhases = (use) => {
|
|
2662
3254
|
let opened = false;
|
|
2663
3255
|
const reach = wait(REACH_SECONDS);
|
|
@@ -2674,7 +3266,7 @@ var GameInteractables = (() => {
|
|
|
2674
3266
|
}
|
|
2675
3267
|
};
|
|
2676
3268
|
};
|
|
2677
|
-
const scrubAndRinse = (use,
|
|
3269
|
+
const scrubAndRinse = (use, body, target, fail) => {
|
|
2678
3270
|
const item = typeof target === "string" ? void 0 : target;
|
|
2679
3271
|
const id = item?.objectId ?? target;
|
|
2680
3272
|
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
@@ -2683,11 +3275,14 @@ var GameInteractables = (() => {
|
|
|
2683
3275
|
const scrub = (dt) => {
|
|
2684
3276
|
if (scrubbed < 0) {
|
|
2685
3277
|
scrubbed = 0;
|
|
2686
|
-
|
|
3278
|
+
if (!body.playUse(use.clip, item?.objectId, underStream(use))) {
|
|
3279
|
+
fail({ key: "hands_busy", ok: false });
|
|
3280
|
+
return true;
|
|
3281
|
+
}
|
|
2687
3282
|
}
|
|
2688
3283
|
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2689
|
-
|
|
2690
|
-
if (dirt > 0)
|
|
3284
|
+
body.lather(id, dt / seconds);
|
|
3285
|
+
if (dirt > 0) body.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2691
3286
|
return scrubbed >= seconds;
|
|
2692
3287
|
};
|
|
2693
3288
|
const running = waterOf(use);
|
|
@@ -2697,13 +3292,13 @@ var GameInteractables = (() => {
|
|
|
2697
3292
|
fail({ key: "no_water", ok: false });
|
|
2698
3293
|
return true;
|
|
2699
3294
|
}
|
|
2700
|
-
if (flow <= 0 ||
|
|
2701
|
-
if (dirt > 0)
|
|
3295
|
+
if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
|
|
3296
|
+
if (dirt > 0) body.setDirt?.(id, 0);
|
|
2702
3297
|
return true;
|
|
2703
3298
|
};
|
|
2704
3299
|
return [scrub, rinse];
|
|
2705
3300
|
};
|
|
2706
|
-
const startWash = (use, host) => {
|
|
3301
|
+
const startWash = (use, host, body) => {
|
|
2707
3302
|
const { items } = findNeeds(use.needs ?? [], host);
|
|
2708
3303
|
let end = null;
|
|
2709
3304
|
const fail = (reason) => {
|
|
@@ -2711,60 +3306,144 @@ var GameInteractables = (() => {
|
|
|
2711
3306
|
};
|
|
2712
3307
|
const tap = tapPhases(use);
|
|
2713
3308
|
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2714
|
-
const
|
|
2715
|
-
|
|
3309
|
+
const waterForDose = waterOf(use);
|
|
3310
|
+
const dose = (dt) => {
|
|
3311
|
+
const flow = waterForDose(dt);
|
|
3312
|
+
if (flow === null) {
|
|
3313
|
+
fail({ key: "no_water", ok: false });
|
|
3314
|
+
return true;
|
|
3315
|
+
}
|
|
3316
|
+
if (flow <= 0) return false;
|
|
3317
|
+
if (dosed && body.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2716
3318
|
return true;
|
|
2717
3319
|
};
|
|
2718
3320
|
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2719
3321
|
const rack = use.dishes?.rack ?? [];
|
|
2720
|
-
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use,
|
|
3322
|
+
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);
|
|
2721
3323
|
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2722
|
-
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
3324
|
+
const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close]);
|
|
2723
3325
|
const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
|
|
2724
3326
|
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2725
3327
|
};
|
|
2726
|
-
const startDrink = (use, host, vessel) => {
|
|
3328
|
+
const startDrink = (use, host, body, vessel) => {
|
|
2727
3329
|
const tap = tapPhases(use);
|
|
2728
3330
|
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2729
3331
|
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2730
3332
|
let drunk = 0;
|
|
2731
3333
|
let end = null;
|
|
2732
|
-
const take = () => {
|
|
2733
|
-
if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
|
|
2734
|
-
else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
|
|
2735
|
-
return true;
|
|
2736
|
-
};
|
|
2737
3334
|
const running = waterOf(use);
|
|
3335
|
+
const played = (clip, at) => {
|
|
3336
|
+
if (body.playUse(clip, vessel.objectId, at)) return true;
|
|
3337
|
+
end ?? (end = { key: "hands_busy", ok: false });
|
|
3338
|
+
return false;
|
|
3339
|
+
};
|
|
3340
|
+
let filling = false;
|
|
2738
3341
|
const fill = (dt) => {
|
|
2739
3342
|
if (end) return true;
|
|
3343
|
+
if (!filling && !(filling = played(use.fillClip ?? "fill_cup", underStream(use)))) return true;
|
|
2740
3344
|
const flow = running(dt);
|
|
2741
3345
|
if (flow === null) {
|
|
2742
3346
|
end = { key: "no_water", ok: false };
|
|
2743
3347
|
return true;
|
|
2744
3348
|
}
|
|
2745
3349
|
if (flow <= 0) return false;
|
|
2746
|
-
const took =
|
|
3350
|
+
const took = body.fillItem(vessel.objectId, "water", Math.min(flow * dt, want - filled));
|
|
2747
3351
|
filled += took;
|
|
2748
3352
|
return filled >= want - 1e-6 || took <= 0;
|
|
2749
3353
|
};
|
|
2750
3354
|
let sipping = false;
|
|
2751
3355
|
const drink = (dt) => {
|
|
2752
3356
|
if (end) return true;
|
|
2753
|
-
if (!sipping
|
|
2754
|
-
const sip =
|
|
3357
|
+
if (!sipping && !(sipping = played(use.clip))) return true;
|
|
3358
|
+
const sip = body.drinkItem(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk));
|
|
2755
3359
|
drunk += sip;
|
|
2756
3360
|
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2757
3361
|
};
|
|
2758
|
-
const
|
|
2759
|
-
const
|
|
2760
|
-
return { use: use.id, step: (dt) => run(dt) ? end ??
|
|
3362
|
+
const run = runPhases([approachPhase(use, host), tap.open, fill, tap.close, drink]);
|
|
3363
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3364
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
3365
|
+
};
|
|
3366
|
+
const startDrinkHands = (use, host, body) => {
|
|
3367
|
+
const tap = tapPhases(use);
|
|
3368
|
+
const want = use.litres ?? DRINK_HANDS_LITRES;
|
|
3369
|
+
let drunk = 0;
|
|
3370
|
+
let end = null;
|
|
3371
|
+
const running = waterOf(use);
|
|
3372
|
+
let bent = false;
|
|
3373
|
+
const drink = (dt) => {
|
|
3374
|
+
if (!bent) {
|
|
3375
|
+
bent = body.playUse(use.clip, void 0, underStream(use));
|
|
3376
|
+
if (!bent) {
|
|
3377
|
+
end = { key: "hands_busy", ok: false };
|
|
3378
|
+
return true;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
const flow = running(dt);
|
|
3382
|
+
if (flow === null) {
|
|
3383
|
+
end = { key: "no_water", ok: false };
|
|
3384
|
+
return true;
|
|
3385
|
+
}
|
|
3386
|
+
if (flow <= 0) return false;
|
|
3387
|
+
const sip = body.drinkFromHands("water", Math.min(DRINK_HANDS_LPS * dt, flow * dt, want - drunk));
|
|
3388
|
+
drunk += sip;
|
|
3389
|
+
return drunk >= want - 1e-6 || sip <= 0;
|
|
3390
|
+
};
|
|
3391
|
+
const run = runPhases([approachPhase(use, host), tap.open, drink, tap.close]);
|
|
3392
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink_hands", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3393
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
2761
3394
|
};
|
|
3395
|
+
const refused = (use, key) => ({ use: use.id, step: () => ({ key, ok: false }) });
|
|
2762
3396
|
return {
|
|
2763
3397
|
start(use, host) {
|
|
2764
|
-
if (use.do === "wash")
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
3398
|
+
if (use.do === "wash") {
|
|
3399
|
+
const body2 = washBody(use, host);
|
|
3400
|
+
return body2 ? startWash(use, host, body2) : refused(use, "no_animation");
|
|
3401
|
+
}
|
|
3402
|
+
if (use.from === "hands") {
|
|
3403
|
+
const body2 = handsBody(host);
|
|
3404
|
+
return body2 ? startDrinkHands(use, host, body2) : refused(use, "no_animation");
|
|
3405
|
+
}
|
|
3406
|
+
const body = vesselBody(host);
|
|
3407
|
+
const vessel = body?.vesselAt();
|
|
3408
|
+
if (!body) return refused(use, "no_animation");
|
|
3409
|
+
return vessel ? startDrink(use, host, body, vessel) : refused(use, "needs_vessel");
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
// src/use-body.ts
|
|
3415
|
+
function createUseBody() {
|
|
3416
|
+
let running = null;
|
|
3417
|
+
const end = () => {
|
|
3418
|
+
const was = running;
|
|
3419
|
+
running = null;
|
|
3420
|
+
was?.body.end();
|
|
3421
|
+
};
|
|
3422
|
+
return {
|
|
3423
|
+
blocked(action, host) {
|
|
3424
|
+
const body = host.body?.();
|
|
3425
|
+
if (!body) return "needs_body";
|
|
3426
|
+
const why = body.blocked(action);
|
|
3427
|
+
return why ? `body_${why}` : null;
|
|
3428
|
+
},
|
|
3429
|
+
begin(action, host) {
|
|
3430
|
+
const body = host.body?.();
|
|
3431
|
+
if (!body) return false;
|
|
3432
|
+
end();
|
|
3433
|
+
if (!body.begin(action)) return false;
|
|
3434
|
+
running = { action, body, time: 0 };
|
|
3435
|
+
return true;
|
|
3436
|
+
},
|
|
3437
|
+
update(dt) {
|
|
3438
|
+
if (!running) return;
|
|
3439
|
+
running.time += dt;
|
|
3440
|
+
const { action, body, time } = running;
|
|
3441
|
+
if (!body.step(time, Math.min(1, time / action.seconds))) running = null;
|
|
3442
|
+
else if (time >= action.seconds) end();
|
|
3443
|
+
},
|
|
3444
|
+
end,
|
|
3445
|
+
get pose() {
|
|
3446
|
+
return running ? { pose: running.action.pose, time: running.time, progress: Math.min(1, running.time / running.action.seconds) } : null;
|
|
2768
3447
|
}
|
|
2769
3448
|
};
|
|
2770
3449
|
}
|
|
@@ -2787,7 +3466,7 @@ var GameInteractables = (() => {
|
|
|
2787
3466
|
};
|
|
2788
3467
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2789
3468
|
var YES2 = { available: true };
|
|
2790
|
-
var no = (reason) => ({ available: false, reason });
|
|
3469
|
+
var no = (reason, vars) => ({ available: false, reason, ...vars ? { vars } : {} });
|
|
2791
3470
|
function createUses(options) {
|
|
2792
3471
|
const { spec, world, objectId } = options;
|
|
2793
3472
|
const all = spec.uses ?? [];
|
|
@@ -2800,6 +3479,8 @@ var GameInteractables = (() => {
|
|
|
2800
3479
|
let lastHost = null;
|
|
2801
3480
|
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2802
3481
|
let routine = null;
|
|
3482
|
+
const drains = createDrainUses({ spec, world, objectId, t: (key, vars) => world.t(key, vars) });
|
|
3483
|
+
const useBody = createUseBody();
|
|
2803
3484
|
const typeKey = `type.${spec.type}`;
|
|
2804
3485
|
const name = () => {
|
|
2805
3486
|
const text = world.t(typeKey);
|
|
@@ -2830,12 +3511,28 @@ var GameInteractables = (() => {
|
|
|
2830
3511
|
return fits ? YES2 : no("not_accepted");
|
|
2831
3512
|
}
|
|
2832
3513
|
case "relieve":
|
|
2833
|
-
return YES2;
|
|
3514
|
+
return drains.has(use.basin) ? drainVerdict(host, () => handsAreFree(host) ? null : "needs_free_hand", () => drains.relieveBody(use, host)) : YES2;
|
|
2834
3515
|
case "wash":
|
|
2835
3516
|
case "drink":
|
|
2836
3517
|
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
3518
|
+
case "plunge":
|
|
3519
|
+
return drainVerdict(host, () => drains.plungeBlocked(use, host), () => drains.plungeBody(use));
|
|
2837
3520
|
}
|
|
2838
3521
|
};
|
|
3522
|
+
const drainVerdict = (host, rule, body) => {
|
|
3523
|
+
const missing = drains.hostBlocked(host);
|
|
3524
|
+
if (missing) return no("host_lacks", { capability: missing });
|
|
3525
|
+
const broken = rule();
|
|
3526
|
+
if (broken) return no(broken);
|
|
3527
|
+
const action = body();
|
|
3528
|
+
if (!action) return no("needs_body");
|
|
3529
|
+
const why = useBody.blocked(action, host);
|
|
3530
|
+
return why ? no(why) : YES2;
|
|
3531
|
+
};
|
|
3532
|
+
const withBody = (action, host, vars, run) => {
|
|
3533
|
+
if (!action) return { ok: false, text: world.t("needs_body", vars) };
|
|
3534
|
+
return useBody.begin(action, host) ? run(action) : { ok: false, text: world.t("body_busy", vars) };
|
|
3535
|
+
};
|
|
2839
3536
|
const itemName = (id) => {
|
|
2840
3537
|
const text = world.t(`item.${id}`);
|
|
2841
3538
|
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
@@ -2871,7 +3568,10 @@ var GameInteractables = (() => {
|
|
|
2871
3568
|
}
|
|
2872
3569
|
case "fill":
|
|
2873
3570
|
return fill(bowls.get(use.bowl), host, vars);
|
|
3571
|
+
case "plunge":
|
|
3572
|
+
return withBody(drains.plungeBody(use), host, vars, (action) => drains.plunge(use, action));
|
|
2874
3573
|
case "relieve": {
|
|
3574
|
+
if (drains.has(use.basin)) return withBody(drains.relieveBody(use, host), host, vars, (action) => drains.relieve(use, host, action));
|
|
2875
3575
|
const now = soil.get(use.basin) ?? "clean";
|
|
2876
3576
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2877
3577
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
@@ -2929,7 +3629,10 @@ var GameInteractables = (() => {
|
|
|
2929
3629
|
const v = verdict(use, host);
|
|
2930
3630
|
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2931
3631
|
},
|
|
2932
|
-
update(dt) {
|
|
3632
|
+
update(dt, host) {
|
|
3633
|
+
if (host) lastHost = host;
|
|
3634
|
+
drains.update(dt, lastHost);
|
|
3635
|
+
useBody.update(dt);
|
|
2933
3636
|
stepRoutine(dt);
|
|
2934
3637
|
if (!program) return;
|
|
2935
3638
|
program.left -= dt;
|
|
@@ -2939,17 +3642,25 @@ var GameInteractables = (() => {
|
|
|
2939
3642
|
program = null;
|
|
2940
3643
|
lastHost?.say(done);
|
|
2941
3644
|
},
|
|
2942
|
-
flushed(fixture) {
|
|
3645
|
+
flushed(fixture, host) {
|
|
3646
|
+
if (host) lastHost = host;
|
|
3647
|
+
if (drains.flushed(fixture, lastHost)) return;
|
|
2943
3648
|
const basin = cleans.get(fixture);
|
|
2944
3649
|
if (!basin || soil.get(basin) === "clean") return;
|
|
2945
3650
|
soil.set(basin, "clean");
|
|
2946
3651
|
lastHost?.say(world.t("done_clean", { name: name() }));
|
|
2947
3652
|
},
|
|
3653
|
+
dispose(host) {
|
|
3654
|
+
drains.dispose(host ?? lastHost);
|
|
3655
|
+
useBody.end();
|
|
3656
|
+
},
|
|
2948
3657
|
state: () => ({
|
|
2949
3658
|
bowls: Object.fromEntries(level),
|
|
2950
|
-
soil: Object.fromEntries(soil),
|
|
3659
|
+
soil: Object.fromEntries([...soil].map(([id, now]) => [id, drains.has(id) ? drains.soil(id) : now])),
|
|
3660
|
+
drains: drains.state(),
|
|
2951
3661
|
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2952
|
-
routine: routine?.use ?? null
|
|
3662
|
+
routine: routine?.use ?? null,
|
|
3663
|
+
body: useBody.pose
|
|
2953
3664
|
})
|
|
2954
3665
|
};
|
|
2955
3666
|
}
|
|
@@ -2977,7 +3688,7 @@ var GameInteractables = (() => {
|
|
|
2977
3688
|
onEvent: (event) => {
|
|
2978
3689
|
if (event.type === "message") said.push(event.text);
|
|
2979
3690
|
if (event.type === "part" && event.object === CONTROLLED_OBJECT) forwardPart(event.part, event.target >= 0.5);
|
|
2980
|
-
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture);
|
|
3691
|
+
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture, host ?? void 0);
|
|
2981
3692
|
}
|
|
2982
3693
|
});
|
|
2983
3694
|
const forwardPart = (part, open) => {
|
|
@@ -3022,14 +3733,17 @@ var GameInteractables = (() => {
|
|
|
3022
3733
|
update(dt, lent) {
|
|
3023
3734
|
lend(lent);
|
|
3024
3735
|
world.update(dt);
|
|
3025
|
-
uses.update(dt);
|
|
3736
|
+
uses.update(dt, lent);
|
|
3026
3737
|
},
|
|
3027
3738
|
state() {
|
|
3028
3739
|
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) }));
|
|
3029
3740
|
const emitters = world.emitters().filter((e) => e.object === CONTROLLED_OBJECT && e.kind !== "water");
|
|
3030
3741
|
return { ...uses.state(), screens, emitters };
|
|
3031
3742
|
},
|
|
3743
|
+
serialize: () => world.serialize(),
|
|
3744
|
+
load: (state) => world.load(state),
|
|
3032
3745
|
dispose() {
|
|
3746
|
+
uses.dispose(host ?? void 0);
|
|
3033
3747
|
host = null;
|
|
3034
3748
|
world.remove(CONTROLLED_OBJECT);
|
|
3035
3749
|
world.remove(MAINS);
|