@adatechnology/game-contracts 0.23.0 → 0.24.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.d.ts +67 -4
- package/dist/index.global.js +65 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +65 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16,10 +16,33 @@ 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-impulse.ts
|
|
20
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
21
|
+
var NEAREST = 0.3;
|
|
22
|
+
function sideOnImpulse(tnt, distance) {
|
|
23
|
+
if (!(tnt > 0)) return 0;
|
|
24
|
+
const w3 = Math.cbrt(tnt);
|
|
25
|
+
const z = Math.max(distance, NEAREST) / w3;
|
|
26
|
+
const scaled = 0.067 * Math.sqrt(1 + (z / 0.23) ** 4) / (z * z * Math.cbrt(1 + (z / 1.55) ** 3));
|
|
27
|
+
return scaled * w3 * 100;
|
|
28
|
+
}
|
|
29
|
+
function bodyImpulse(tnt, distance) {
|
|
30
|
+
if (!(tnt > 0)) return 0;
|
|
31
|
+
const z = Math.max(distance, NEAREST) / Math.cbrt(tnt);
|
|
32
|
+
return sideOnImpulse(tnt, distance) * (2 + 4 / (1 + z * z));
|
|
33
|
+
}
|
|
34
|
+
function blastBodySpeed(tnt, distance, mass, reach = 1, options = {}) {
|
|
35
|
+
const area = options.bodyArea ?? DEFAULT_BLAST_IMPULSE.bodyArea;
|
|
36
|
+
return bodyImpulse(tnt, distance) * area * Math.max(0, reach) / Math.max(mass, 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
// src/blast-knock.ts
|
|
20
40
|
var KNOCK_DOWN_SPEED = 2.5;
|
|
21
41
|
var KNOCKED_DOWN_ANGLE = 1.35;
|
|
22
42
|
var LIE_SECONDS = 1.6;
|
|
43
|
+
var WOUNDED_LIE_SECONDS = 6;
|
|
44
|
+
var FRAGMENT_COVER = 0.5;
|
|
45
|
+
var STUN_SECONDS = 4;
|
|
23
46
|
var STAND_UP_PER_SPEED = 0.25;
|
|
24
47
|
var FALL_SECONDS = 0.25;
|
|
25
48
|
var RISE_SECONDS = 0.6;
|
|
@@ -28,11 +51,38 @@ var GRAVITY = 9.81;
|
|
|
28
51
|
var KNOCK_CHEST = 1.1;
|
|
29
52
|
var CHEST = KNOCK_CHEST;
|
|
30
53
|
var bodyMass = (height, build = 1) => 70 * (height / 1.75) ** 2 * build;
|
|
31
|
-
function knockOf(blast, feet, mass, options) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
54
|
+
function knockOf(blast, feet, mass, options, impulse = {}) {
|
|
55
|
+
const o = { ...DEFAULT_BLAST_IMPULSE, ...impulse };
|
|
56
|
+
const chest = [feet[0], feet[1] + CHEST, feet[2]];
|
|
57
|
+
const dx = chest[0] - blast.point[0];
|
|
58
|
+
const dy = chest[1] - blast.point[1];
|
|
59
|
+
const dz = chest[2] - blast.point[2];
|
|
60
|
+
const distance = Math.hypot(dx, dy, dz);
|
|
61
|
+
if (!(blast.radius > 0) || distance > blast.radius) return void 0;
|
|
62
|
+
const reach = Math.max(0, Math.min(1, blast.reach ?? 1));
|
|
63
|
+
const tnt = blast.tnt ?? blast.energy * o.tntPerJoule;
|
|
64
|
+
let speed = blastBodySpeed(tnt, distance, mass, reach, o);
|
|
65
|
+
const minSpeed = impulse.minSpeed ?? options?.minSpeed ?? o.minSpeed;
|
|
66
|
+
if (speed < minSpeed) speed = 0;
|
|
67
|
+
const struck = reach >= FRAGMENT_COVER;
|
|
68
|
+
const wounded = struck && blast.lethalRadius !== void 0 && distance <= blast.lethalRadius;
|
|
69
|
+
const edge = 1 - distance / blast.radius;
|
|
70
|
+
const stunSeconds = struck ? STUN_SECONDS * edge * edge * reach : 0;
|
|
71
|
+
if (speed === 0 && !wounded && stunSeconds < 0.25) return void 0;
|
|
72
|
+
const horizontal = Math.hypot(dx, dz);
|
|
73
|
+
const away = horizontal > 1e-4 ? [dx / horizontal, o.lift, dz / horizontal] : [0, 1, 0];
|
|
74
|
+
const length = Math.hypot(away[0], away[1], away[2]);
|
|
75
|
+
const velocity = [away[0] / length * speed, away[1] / length * speed, away[2] / length * speed];
|
|
76
|
+
return {
|
|
77
|
+
velocity,
|
|
78
|
+
airborne: velocity[1] > 0.5,
|
|
79
|
+
lying: 0,
|
|
80
|
+
lieLeft: wounded ? WOUNDED_LIE_SECONDS : 0,
|
|
81
|
+
away: horizontal > 1e-4 ? [dx / horizontal, 0, dz / horizontal] : [0, 0, 0],
|
|
82
|
+
down: speed >= KNOCK_DOWN_SPEED || wounded,
|
|
83
|
+
...wounded ? { wounded } : {},
|
|
84
|
+
...stunSeconds >= 0.25 ? { stunSeconds } : {}
|
|
85
|
+
};
|
|
36
86
|
}
|
|
37
87
|
function stepKnock(knock, position, dt, groundAt, alive) {
|
|
38
88
|
const v = knock.velocity;
|
|
@@ -56,14 +106,11 @@ function stepKnock(knock, position, dt, groundAt, alive) {
|
|
|
56
106
|
}
|
|
57
107
|
const moving = horizontal > 0.05 || knock.airborne;
|
|
58
108
|
if (knock.down) {
|
|
59
|
-
if (moving) knock.lying = Math.min(1, knock.lying + dt / FALL_SECONDS);
|
|
60
|
-
else {
|
|
61
|
-
knock.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
knock.lieLeft -= dt;
|
|
65
|
-
if (knock.lieLeft <= 0) knock.down = false;
|
|
66
|
-
}
|
|
109
|
+
if (moving || knock.lying < 1) knock.lying = Math.min(1, knock.lying + dt / FALL_SECONDS);
|
|
110
|
+
else if (alive) {
|
|
111
|
+
knock.lieLeft = knock.lieLeft > 0 ? knock.lieLeft : LIE_SECONDS + Math.hypot(v[0], v[2]) * STAND_UP_PER_SPEED;
|
|
112
|
+
knock.lieLeft -= dt;
|
|
113
|
+
if (knock.lieLeft <= 0) knock.down = false;
|
|
67
114
|
}
|
|
68
115
|
} else if (knock.lying > 0) knock.lying = Math.max(0, knock.lying - dt / RISE_SECONDS);
|
|
69
116
|
return !moving && !knock.down && knock.lying === 0;
|
|
@@ -1135,6 +1182,7 @@ export {
|
|
|
1135
1182
|
BLOW_IDS,
|
|
1136
1183
|
BODY_FOLEY_IDS,
|
|
1137
1184
|
BODY_SOUND_IDS,
|
|
1185
|
+
DEFAULT_BLAST_IMPULSE,
|
|
1138
1186
|
DEFAULT_BLAST_SHOVE,
|
|
1139
1187
|
DEFAULT_ENVIRONMENT,
|
|
1140
1188
|
DEFAULT_IGNITION_RULES,
|
|
@@ -1142,6 +1190,7 @@ export {
|
|
|
1142
1190
|
DEFERRED_PRIORITY,
|
|
1143
1191
|
DEFERRED_QUEUE_ID,
|
|
1144
1192
|
FOOTSTEP_SOUND_IDS,
|
|
1193
|
+
FRAGMENT_COVER,
|
|
1145
1194
|
FRAME_PHASES,
|
|
1146
1195
|
GAIT_IDS,
|
|
1147
1196
|
HEAVY_LANDING_SPEED,
|
|
@@ -1160,7 +1209,9 @@ export {
|
|
|
1160
1209
|
TOOL_CLIP,
|
|
1161
1210
|
TWIST_LIFT,
|
|
1162
1211
|
applyPatches,
|
|
1212
|
+
blastBodySpeed,
|
|
1163
1213
|
blastShove,
|
|
1214
|
+
bodyImpulse,
|
|
1164
1215
|
bodyMass,
|
|
1165
1216
|
checkAnimation,
|
|
1166
1217
|
checkBench,
|
|
@@ -1196,6 +1247,7 @@ export {
|
|
|
1196
1247
|
sealOpener,
|
|
1197
1248
|
shotExtras,
|
|
1198
1249
|
shotToHit,
|
|
1250
|
+
sideOnImpulse,
|
|
1199
1251
|
sparkTargetFactor,
|
|
1200
1252
|
stepKnock,
|
|
1201
1253
|
surfaceOfMaterial,
|