@adatechnology/game-player 0.12.3 → 0.13.1
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 +27 -2
- package/dist/{chunk-EN2Z57NX.js → chunk-BQJMHKW5.js} +116 -7
- package/dist/chunk-BQJMHKW5.js.map +1 -0
- package/dist/hud.d.ts +29 -6
- package/dist/hud.js +58 -22
- package/dist/hud.js.map +1 -1
- package/dist/index.d.ts +40 -4
- package/dist/index.global.js +134 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/dist/{player-B-CNsXV5.d.ts → player-D2QiWWBg.d.ts} +125 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-EN2Z57NX.js.map +0 -1
package/dist/index.global.js
CHANGED
|
@@ -21,6 +21,7 @@ var GamePlayer = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
BELT_SLOT: () => BELT_SLOT,
|
|
24
25
|
DOOR_ARM_REACH: () => DOOR_ARM_REACH,
|
|
25
26
|
DOOR_SHOULDER_HEIGHT: () => DOOR_SHOULDER_HEIGHT,
|
|
26
27
|
DOOR_USE_DEFAULTS: () => DOOR_USE_DEFAULTS,
|
|
@@ -28,6 +29,8 @@ var GamePlayer = (() => {
|
|
|
28
29
|
HANDS_DEFAULTS: () => HANDS_DEFAULTS,
|
|
29
30
|
HANDS_TIMING: () => HANDS_TIMING,
|
|
30
31
|
ITEM_GRIP: () => ITEM_GRIP,
|
|
32
|
+
LIFT_DEFAULTS: () => LIFT_DEFAULTS,
|
|
33
|
+
NEEDS_DEFAULTS: () => NEEDS_DEFAULTS,
|
|
31
34
|
PLAYER_DEFAULTS: () => PLAYER_DEFAULTS,
|
|
32
35
|
PLAYER_MASS_KG: () => PLAYER_MASS_KG,
|
|
33
36
|
PLAYER_PUSH_STRENGTH_NEWTONS: () => PLAYER_PUSH_STRENGTH_NEWTONS,
|
|
@@ -37,12 +40,16 @@ var GamePlayer = (() => {
|
|
|
37
40
|
SLOT_FALLBACKS: () => SLOT_FALLBACKS,
|
|
38
41
|
STEP_POSE_DEFAULTS: () => STEP_POSE_DEFAULTS,
|
|
39
42
|
WALKER_JUMP_SPEED: () => WALKER_JUMP_SPEED,
|
|
43
|
+
advanceNeeds: () => advanceNeeds,
|
|
44
|
+
applyItemEffect: () => applyItemEffect,
|
|
40
45
|
blendPoses: () => blendPoses,
|
|
41
46
|
canPush: () => canPush,
|
|
42
47
|
composePose: () => composePose,
|
|
43
48
|
conjugateQuaternion: () => conjugateQuaternion,
|
|
49
|
+
createBodyVitals: () => createBodyVitals,
|
|
44
50
|
createDoorUse: () => createDoorUse,
|
|
45
51
|
createFurniturePush: () => createFurniturePush,
|
|
52
|
+
createNeedsState: () => createNeedsState,
|
|
46
53
|
createPhysicsController: () => createPhysicsController,
|
|
47
54
|
createPlayer: () => createPlayer,
|
|
48
55
|
createPlayerTestModule: () => createPlayerTestModule,
|
|
@@ -61,8 +68,12 @@ var GamePlayer = (() => {
|
|
|
61
68
|
gripSecondsFor: () => gripSecondsFor,
|
|
62
69
|
handPoseOnItem: () => handPoseOnItem,
|
|
63
70
|
interactionHandsFor: () => interactionHandsFor,
|
|
71
|
+
isStarving: () => isStarving,
|
|
64
72
|
itemPoseInHand: () => itemPoseInHand,
|
|
73
|
+
liftCheckFor: () => liftCheckFor,
|
|
65
74
|
multiplyQuaternions: () => multiplyQuaternions,
|
|
75
|
+
needsHoursOf: () => needsHoursOf,
|
|
76
|
+
nourish: () => nourish,
|
|
66
77
|
planDrawSequence: () => planDrawSequence,
|
|
67
78
|
planHands: () => planHands,
|
|
68
79
|
planTakeSequence: () => planTakeSequence,
|
|
@@ -247,7 +258,20 @@ var GamePlayer = (() => {
|
|
|
247
258
|
derived: "G 62005-62012 DERIV",
|
|
248
259
|
wounds: "G 62016 FERIDA (Personagens 3.7): share of each wound kind, and its infection chance (used only when an infection rule is on)",
|
|
249
260
|
infection: "G 62015 INFEC (the slice's accelerated clock: fever 30 s, delirium 70 s, death 120 s, reanimation 8 s after); G 68509 fever noise",
|
|
250
|
-
numbers: "G 68427-68640 player, playerUpdate, frontZombies, shove, knife; G 68678-68681 the aim spread modifiers; G 65507 walkCad"
|
|
261
|
+
numbers: "G 68427-68640 player, playerUpdate, frontZombies, shove, knife; G 68678-68681 the aim spread modifiers; G 65507 walkCad",
|
|
262
|
+
needs: "G 57255 needs (fome 20, sede 20 at the start; 0 is fed, 100 starving), G 57271 useItem (food takes off its f, drink its s), G 57341-57344 (1 game hour = 50 s of the slice; hunger 2.5/h, 4/h running, thirst 4/h, times 1.1 - 0.02 x vigor; over 90 the body loses 0.2 health a second)"
|
|
263
|
+
},
|
|
264
|
+
needs: {
|
|
265
|
+
start: { hunger: 20, thirst: 20 },
|
|
266
|
+
max: 100,
|
|
267
|
+
gameHourSeconds: 50,
|
|
268
|
+
hungerPerHour: 2.5,
|
|
269
|
+
hungerRunningPerHour: 4,
|
|
270
|
+
thirstPerHour: 4,
|
|
271
|
+
vigorBase: 1.1,
|
|
272
|
+
vigorPerPoint: -0.02,
|
|
273
|
+
starvingAt: 90,
|
|
274
|
+
starvingDamagePerSecond: 0.2
|
|
251
275
|
},
|
|
252
276
|
attributes: { strength: 5, vigor: 5, agility: 5, perception: 5, intellect: 5, presence: 5 },
|
|
253
277
|
derived: {
|
|
@@ -374,6 +398,26 @@ var GamePlayer = (() => {
|
|
|
374
398
|
fist: { damage: 8, crit: 0, reach: 0.5, noise: 1 }
|
|
375
399
|
};
|
|
376
400
|
|
|
401
|
+
// src/needs.ts
|
|
402
|
+
var NEEDS_DEFAULTS = defaults_default.needs;
|
|
403
|
+
var createNeedsState = (rules = NEEDS_DEFAULTS) => ({ hunger: rules.start.hunger, thirst: rules.start.thirst });
|
|
404
|
+
var clamp = (value, max) => value < 0 ? 0 : value > max ? max : value;
|
|
405
|
+
var needsHoursOf = (dt, vigor, rules = NEEDS_DEFAULTS) => Math.max(0, dt) / rules.gameHourSeconds * Math.max(0, rules.vigorBase + rules.vigorPerPoint * vigor);
|
|
406
|
+
var isStarving = (state, rules = NEEDS_DEFAULTS) => state.hunger > rules.starvingAt || state.thirst > rules.starvingAt;
|
|
407
|
+
function advanceNeeds(state, dt, body, rules = NEEDS_DEFAULTS) {
|
|
408
|
+
const hours = needsHoursOf(dt, body.vigor, rules);
|
|
409
|
+
state.hunger = clamp(state.hunger + (body.running ? rules.hungerRunningPerHour : rules.hungerPerHour) * hours, rules.max);
|
|
410
|
+
state.thirst = clamp(state.thirst + rules.thirstPerHour * hours, rules.max);
|
|
411
|
+
return isStarving(state, rules) ? rules.starvingDamagePerSecond * Math.max(0, dt) : 0;
|
|
412
|
+
}
|
|
413
|
+
function nourish(state, food, rules = NEEDS_DEFAULTS) {
|
|
414
|
+
const hunger = state.hunger;
|
|
415
|
+
const thirst = state.thirst;
|
|
416
|
+
state.hunger = clamp(hunger - (food.satiety ?? 0), rules.max);
|
|
417
|
+
state.thirst = clamp(thirst - (food.hydration ?? 0), rules.max);
|
|
418
|
+
return { hunger: state.hunger - hunger, thirst: state.thirst - thirst };
|
|
419
|
+
}
|
|
420
|
+
|
|
377
421
|
// src/rng.ts
|
|
378
422
|
function createRng(seed) {
|
|
379
423
|
let state = seed >>> 0;
|
|
@@ -385,6 +429,66 @@ var GamePlayer = (() => {
|
|
|
385
429
|
};
|
|
386
430
|
}
|
|
387
431
|
|
|
432
|
+
// src/vitals.ts
|
|
433
|
+
var NOTHING = { applied: false, health: 0, hunger: 0, thirst: 0, stoppedBleeding: false, calmed: false };
|
|
434
|
+
var numberOf = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
435
|
+
function applyItemEffect(body, effect, limits) {
|
|
436
|
+
switch (effect.id) {
|
|
437
|
+
case "consume_nutrition": {
|
|
438
|
+
const moved = nourish(body, { satiety: numberOf(effect.satiety), hydration: numberOf(effect.hydration) }, limits.needs ?? NEEDS_DEFAULTS);
|
|
439
|
+
return { ...NOTHING, applied: true, hunger: moved.hunger, thirst: moved.thirst };
|
|
440
|
+
}
|
|
441
|
+
case "heal": {
|
|
442
|
+
const before = body.health;
|
|
443
|
+
body.health = Math.min(limits.maxHealth, before + Math.max(0, numberOf(effect.params?.amount)));
|
|
444
|
+
return { ...NOTHING, applied: true, health: body.health - before };
|
|
445
|
+
}
|
|
446
|
+
case "stop_bleeding": {
|
|
447
|
+
const stopped = body.bleeding > 0;
|
|
448
|
+
body.bleeding = 0;
|
|
449
|
+
return { ...NOTHING, applied: true, stoppedBleeding: stopped };
|
|
450
|
+
}
|
|
451
|
+
case "clean_wound": {
|
|
452
|
+
const cleaned = body.wounds.pop();
|
|
453
|
+
return cleaned === void 0 ? NOTHING : { ...NOTHING, applied: true, cleaned };
|
|
454
|
+
}
|
|
455
|
+
case "calm": {
|
|
456
|
+
const calmed = body.panic > 0;
|
|
457
|
+
body.panic = 0;
|
|
458
|
+
return { ...NOTHING, applied: true, calmed };
|
|
459
|
+
}
|
|
460
|
+
default:
|
|
461
|
+
return NOTHING;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function createBodyVitals(options = {}) {
|
|
465
|
+
const maxHealth = options.maxHealth ?? 100;
|
|
466
|
+
const bleedPerSecond = options.bleedPerSecond ?? 0.15;
|
|
467
|
+
const vigor = options.vigor ?? 5;
|
|
468
|
+
const rules = { ...NEEDS_DEFAULTS, ...options.needs, start: { ...NEEDS_DEFAULTS.start, ...options.needs?.start } };
|
|
469
|
+
const fresh = () => ({ ...createNeedsState(rules), health: maxHealth, bleeding: 0, panic: 0, wounds: [], alive: true, cause: "" });
|
|
470
|
+
const state = fresh();
|
|
471
|
+
return {
|
|
472
|
+
state,
|
|
473
|
+
maxHealth,
|
|
474
|
+
rules,
|
|
475
|
+
update(dt, input = {}) {
|
|
476
|
+
if (!state.alive || dt <= 0) return;
|
|
477
|
+
state.health -= advanceNeeds(state, dt, { running: input.running ?? false, vigor }, rules);
|
|
478
|
+
if (state.bleeding > 0) state.health -= bleedPerSecond * dt;
|
|
479
|
+
if (state.health <= 0) {
|
|
480
|
+
state.health = 0;
|
|
481
|
+
state.alive = false;
|
|
482
|
+
state.cause = state.bleeding > 0 ? "bled_out" : "hunger_thirst";
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
apply: (effect) => state.alive ? applyItemEffect(state, effect, { maxHealth, needs: rules }) : NOTHING,
|
|
486
|
+
reset() {
|
|
487
|
+
Object.assign(state, fresh());
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
388
492
|
// src/player.ts
|
|
389
493
|
var PLAYER_DEFAULTS = defaults_default;
|
|
390
494
|
var TAU_APPROX = 6.2832;
|
|
@@ -408,9 +512,9 @@ var GamePlayer = (() => {
|
|
|
408
512
|
}
|
|
409
513
|
return kinds[kinds.length - 1];
|
|
410
514
|
};
|
|
411
|
-
var
|
|
515
|
+
var clamp2 = (v, a, b) => v < a ? a : v > b ? b : v;
|
|
412
516
|
var lerp = (a, b, t) => a + (b - a) * t;
|
|
413
|
-
var freshState = (derived, position) => ({
|
|
517
|
+
var freshState = (derived, position, needs) => ({
|
|
414
518
|
x: position?.x ?? 0,
|
|
415
519
|
z: position?.z ?? 0,
|
|
416
520
|
y: 0,
|
|
@@ -422,6 +526,8 @@ var GamePlayer = (() => {
|
|
|
422
526
|
turned: false,
|
|
423
527
|
health: derived.maxHealth,
|
|
424
528
|
stamina: derived.maxStamina,
|
|
529
|
+
hunger: needs?.start.hunger ?? 0,
|
|
530
|
+
thirst: needs?.start.thirst ?? 0,
|
|
425
531
|
crouch: false,
|
|
426
532
|
running: false,
|
|
427
533
|
stepTimer: 0,
|
|
@@ -462,9 +568,10 @@ var GamePlayer = (() => {
|
|
|
462
568
|
const heightScale = heightMetres / numbers.heightMetres;
|
|
463
569
|
const wounds = options.wounds ?? PLAYER_DEFAULTS.wounds;
|
|
464
570
|
const infection = options.infection === void 0 || options.infection === false ? null : options.infection === true ? PLAYER_DEFAULTS.infection : { ...PLAYER_DEFAULTS.infection, ...options.infection };
|
|
571
|
+
const needs = options.needs === false ? null : options.needs === void 0 || options.needs === true ? NEEDS_DEFAULTS : { ...NEEDS_DEFAULTS, ...options.needs, start: { ...NEEDS_DEFAULTS.start, ...options.needs.start } };
|
|
465
572
|
const fist = options.fist ?? PLAYER_DEFAULTS.fist;
|
|
466
573
|
const listeners = /* @__PURE__ */ new Map();
|
|
467
|
-
let P = freshState(derived, options.position);
|
|
574
|
+
let P = freshState(derived, options.position, needs);
|
|
468
575
|
const feet = new Float64Array(3);
|
|
469
576
|
let defaultWorld = options.world ?? {};
|
|
470
577
|
let world = defaultWorld;
|
|
@@ -635,6 +742,7 @@ var GamePlayer = (() => {
|
|
|
635
742
|
message("bandaged", 2);
|
|
636
743
|
}
|
|
637
744
|
}
|
|
745
|
+
if (needs) P.health -= advanceNeeds(P, dt, { running: P.running, vigor: attributes.vigor }, needs);
|
|
638
746
|
if (P.health <= 0) {
|
|
639
747
|
die(P.infected ? "infected" : P.bleeding ? "bled_out" : "hunger_thirst");
|
|
640
748
|
return;
|
|
@@ -794,7 +902,7 @@ var GamePlayer = (() => {
|
|
|
794
902
|
const lx = P.vx * cy - P.vz * sy;
|
|
795
903
|
const lz = P.vx * sy + P.vz * cy;
|
|
796
904
|
const back = lz < numbers.backwardsBelow ? -1 : 1;
|
|
797
|
-
const hip = spd > numbers.hipMinSpeed ?
|
|
905
|
+
const hip = spd > numbers.hipMinSpeed ? clamp2(Math.atan2(lx * back, lz * back), -numbers.hipLimit, numbers.hipLimit) : 0;
|
|
798
906
|
P.hip = P.hip + (hip - P.hip) * Math.min(1, dt * numbers.hipFollow);
|
|
799
907
|
P.phase += dt * (spd < numbers.cadenceMinSpeed ? 0 : numbers.cadenceBase + numbers.cadencePerSpeed * spd) * back;
|
|
800
908
|
}
|
|
@@ -829,7 +937,7 @@ var GamePlayer = (() => {
|
|
|
829
937
|
const n = crowd.count();
|
|
830
938
|
for (let i = 0; i < n; i++) if (crowd.active(i) && crowd.chasing(i)) near += crowd.panicWeight?.(i) ?? 1;
|
|
831
939
|
}
|
|
832
|
-
P.panic =
|
|
940
|
+
P.panic = clamp2(P.panic + (near * numbers.panicGain - (near ? 0 : numbers.panicDecay)) * dt, 0, numbers.panicMax);
|
|
833
941
|
};
|
|
834
942
|
return {
|
|
835
943
|
get state() {
|
|
@@ -844,6 +952,8 @@ var GamePlayer = (() => {
|
|
|
844
952
|
derived,
|
|
845
953
|
numbers,
|
|
846
954
|
infection,
|
|
955
|
+
needs,
|
|
956
|
+
use: (effect) => P.alive ? applyItemEffect(P, effect, { maxHealth: derived.maxHealth, ...needs ? { needs } : {} }) : { applied: false, health: 0, hunger: 0, thirst: 0, stoppedBleeding: false, calmed: false },
|
|
847
957
|
update,
|
|
848
958
|
hurt: (amount) => hurt(amount),
|
|
849
959
|
bite: () => bite(),
|
|
@@ -876,6 +986,8 @@ var GamePlayer = (() => {
|
|
|
876
986
|
save: () => ({ state: structuredClone(P), attributes }),
|
|
877
987
|
load(save) {
|
|
878
988
|
P = structuredClone(save.state);
|
|
989
|
+
P.hunger ?? (P.hunger = needs?.start.hunger ?? 0);
|
|
990
|
+
P.thirst ?? (P.thirst = needs?.start.thirst ?? 0);
|
|
879
991
|
world.controller?.teleport(P.x, P.y, P.z);
|
|
880
992
|
},
|
|
881
993
|
setWorld(next) {
|
|
@@ -1766,7 +1878,8 @@ var GamePlayer = (() => {
|
|
|
1766
1878
|
|
|
1767
1879
|
// src/hands.ts
|
|
1768
1880
|
var HANDS_DEFAULTS = { oneHand: { maxKg: 4, maxLength: 0.7 } };
|
|
1769
|
-
var SLOT_FALLBACKS = { sling: ["back"] };
|
|
1881
|
+
var SLOT_FALLBACKS = { sling: ["back"], hip: ["belt"] };
|
|
1882
|
+
var BELT_SLOT = "belt";
|
|
1770
1883
|
var SLING_SLOT = "sling";
|
|
1771
1884
|
function interactionHandsFor(thing, rules = HANDS_DEFAULTS) {
|
|
1772
1885
|
const longest = Math.max(0, ...thing.size ?? []);
|
|
@@ -1778,7 +1891,8 @@ var GamePlayer = (() => {
|
|
|
1778
1891
|
const free = [...params.slots];
|
|
1779
1892
|
const fallbacks = params.fallbacks ?? SLOT_FALLBACKS;
|
|
1780
1893
|
const stow = (hand, weapon) => {
|
|
1781
|
-
const
|
|
1894
|
+
const own = weapon.slot === null ? [] : [weapon.slot, ...fallbacks[weapon.slot] ?? []];
|
|
1895
|
+
const tried = weapon.hands === 1 && !own.includes(BELT_SLOT) ? [...own, BELT_SLOT] : own;
|
|
1782
1896
|
const slot = tried.find((name) => free.includes(name));
|
|
1783
1897
|
if (slot === void 0) return { hand, weapon: weapon.id, move: "drop" };
|
|
1784
1898
|
free.splice(free.indexOf(slot), 1);
|
|
@@ -1796,6 +1910,18 @@ var GamePlayer = (() => {
|
|
|
1796
1910
|
return plan.moves.filter((move) => move.move === "holster").map((move) => ({ hand: move.hand, weapon: move.weapon }));
|
|
1797
1911
|
}
|
|
1798
1912
|
|
|
1913
|
+
// src/lift.ts
|
|
1914
|
+
var LIFT_DEFAULTS = { maxKg: 60, closeReach: 0.25, bodyDepth: 0.15, maxSpan: 1.3 };
|
|
1915
|
+
function liftCheckFor(thing, rules = {}) {
|
|
1916
|
+
const r = { ...LIFT_DEFAULTS, ...rules };
|
|
1917
|
+
const [, middle = 0, thinnest = 0] = [...thing.size ?? []].sort((a, b) => b - a);
|
|
1918
|
+
const reach = r.bodyDepth + Math.max(0, thinnest) / 2;
|
|
1919
|
+
const liftableKg = r.maxKg * Math.min(1, r.closeReach / Math.max(reach, 1e-6));
|
|
1920
|
+
if (thing.massKg > r.maxKg) return { verdict: "too_heavy", liftableKg };
|
|
1921
|
+
if (middle > r.maxSpan || thing.massKg > liftableKg) return { verdict: "too_bulky", liftableKg };
|
|
1922
|
+
return { verdict: "ok", liftableKg };
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1799
1925
|
// src/hand-math.ts
|
|
1800
1926
|
function quaternionOfBasis(x, y, z) {
|
|
1801
1927
|
const [m00, m10, m20] = [x[0] ?? 0, x[1] ?? 0, x[2] ?? 0];
|