@adatechnology/game-contracts 0.22.0 → 0.23.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/dist/index.js CHANGED
@@ -16,6 +16,59 @@ function blastShove(blast, target, options = {}) {
16
16
  return { speed, direction: [direction[0] / length, direction[1] / length, direction[2] / length], distance, falloff };
17
17
  }
18
18
 
19
+ // src/blast-knock.ts
20
+ var KNOCK_DOWN_SPEED = 2.5;
21
+ var KNOCKED_DOWN_ANGLE = 1.35;
22
+ var LIE_SECONDS = 1.6;
23
+ var STAND_UP_PER_SPEED = 0.25;
24
+ var FALL_SECONDS = 0.25;
25
+ var RISE_SECONDS = 0.6;
26
+ var GROUND_FRICTION = 7;
27
+ var GRAVITY = 9.81;
28
+ var KNOCK_CHEST = 1.1;
29
+ var CHEST = KNOCK_CHEST;
30
+ var bodyMass = (height, build = 1) => 70 * (height / 1.75) ** 2 * build;
31
+ function knockOf(blast, feet, mass, options) {
32
+ const hit = blastShove(blast, { position: [feet[0], feet[1] + CHEST, feet[2]], mass }, options);
33
+ if (!hit) return void 0;
34
+ const [dx, dy, dz] = hit.direction;
35
+ return { velocity: [dx * hit.speed, Math.max(0, dy * hit.speed), dz * hit.speed], airborne: dy > 0, lying: 0, lieLeft: 0, down: hit.speed >= KNOCK_DOWN_SPEED };
36
+ }
37
+ function stepKnock(knock, position, dt, groundAt, alive) {
38
+ const v = knock.velocity;
39
+ position.x += v[0] * dt;
40
+ position.z += v[2] * dt;
41
+ const ground = groundAt(position.x, position.z);
42
+ if (knock.airborne || position.y > ground + 1e-4) {
43
+ v[1] -= GRAVITY * dt;
44
+ position.y += v[1] * dt;
45
+ if (position.y <= ground) {
46
+ position.y = ground;
47
+ v[1] = 0;
48
+ knock.airborne = false;
49
+ }
50
+ } else position.y = ground;
51
+ const horizontal = Math.hypot(v[0], v[2]);
52
+ if (!knock.airborne && horizontal > 0) {
53
+ const slowed = Math.max(0, horizontal - GROUND_FRICTION * dt);
54
+ v[0] *= slowed / horizontal;
55
+ v[2] *= slowed / horizontal;
56
+ }
57
+ const moving = horizontal > 0.05 || knock.airborne;
58
+ if (knock.down) {
59
+ if (moving) knock.lying = Math.min(1, knock.lying + dt / FALL_SECONDS);
60
+ else {
61
+ knock.lying = 1;
62
+ if (alive) {
63
+ knock.lieLeft = knock.lieLeft > 0 ? knock.lieLeft : LIE_SECONDS + Math.hypot(v[0], v[2]) * STAND_UP_PER_SPEED;
64
+ knock.lieLeft -= dt;
65
+ if (knock.lieLeft <= 0) knock.down = false;
66
+ }
67
+ }
68
+ } else if (knock.lying > 0) knock.lying = Math.max(0, knock.lying - dt / RISE_SECONDS);
69
+ return !moving && !knock.down && knock.lying === 0;
70
+ }
71
+
19
72
  // src/impact-cost.ts
20
73
  var DEFAULT_COST_READS = 1e4;
21
74
  var DEFAULT_COST_CEILING_MS = 50;
@@ -559,6 +612,21 @@ var checkToolClips = (clips, partIds) => {
559
612
  }
560
613
  return { ok: problems.length === 0, problems };
561
614
  };
615
+ var leadClipEvents = (clip) => {
616
+ const events = clip.events ?? [];
617
+ if (!events.some((event) => (event.lead ?? 0) > 0)) return clip;
618
+ let floor = 0;
619
+ const led = events.map((event) => {
620
+ const lead = Math.max(0, Math.min(event.t - floor, event.lead ?? 0));
621
+ const t = event.t - lead;
622
+ floor = Math.max(floor, t);
623
+ if (event.lead === void 0) return event;
624
+ const moved = { ...event, t, data: lead > 0 ? { ...event.data, lead } : { ...event.data } };
625
+ delete moved.lead;
626
+ return moved;
627
+ });
628
+ return { ...clip, events: led };
629
+ };
562
630
  var createToolClipPlayer = (options) => {
563
631
  const { clips, rig, onEvent } = options;
564
632
  let instances = [];
@@ -601,7 +669,7 @@ var createToolClipPlayer = (options) => {
601
669
  }
602
670
  const found = find(step.clip, step.variant);
603
671
  if (!found) return;
604
- const clip = step.duration && step.duration > 0 ? scaleClip(found.clip, step.duration) : found.clip;
672
+ const clip = leadClipEvents(step.duration && step.duration > 0 ? scaleClip(found.clip, step.duration) : found.clip);
605
673
  const interval = options.repeatInterval?.() ?? 0.1;
606
674
  instances = instances.filter((existing) => existing.name !== found.name || existing.delay > 0);
607
675
  for (let round = 0; round < (step.repeat ?? 1); round++) {
@@ -1079,6 +1147,9 @@ export {
1079
1147
  HEAVY_LANDING_SPEED,
1080
1148
  IMPACT_CONTRACT,
1081
1149
  KIT_ORIGIN_KEY,
1150
+ KNOCKED_DOWN_ANGLE,
1151
+ KNOCK_CHEST,
1152
+ KNOCK_DOWN_SPEED,
1082
1153
  LANDING_IDS,
1083
1154
  LAND_SOUND_IDS,
1084
1155
  MATERIAL_SURFACES,
@@ -1090,6 +1161,7 @@ export {
1090
1161
  TWIST_LIFT,
1091
1162
  applyPatches,
1092
1163
  blastShove,
1164
+ bodyMass,
1093
1165
  checkAnimation,
1094
1166
  checkBench,
1095
1167
  checkCategorized,
@@ -1109,7 +1181,9 @@ export {
1109
1181
  ignitionChance,
1110
1182
  isSurfaceId,
1111
1183
  kitOriginOf,
1184
+ knockOf,
1112
1185
  landSoundId,
1186
+ leadClipEvents,
1113
1187
  markKitOrigin,
1114
1188
  mergeById,
1115
1189
  removeIds,
@@ -1123,6 +1197,7 @@ export {
1123
1197
  shotExtras,
1124
1198
  shotToHit,
1125
1199
  sparkTargetFactor,
1200
+ stepKnock,
1126
1201
  surfaceOfMaterial,
1127
1202
  swingSoundId,
1128
1203
  toolAnimationStep,