@korial29/tiny-fps 0.141.0 → 0.142.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 +13 -13
- package/dist/local.js +1 -1
- package/dist/server.js +33 -15
- package/dist/types/client/gait.d.ts +9 -0
- package/dist/types/shared/gun.d.ts +2 -0
- package/dist/types/shared/room.d.ts +4 -2
- package/dist/types/shared/types.d.ts +12 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -441,6 +441,16 @@ var LIMB = {
|
|
|
441
441
|
LEG_L: 4,
|
|
442
442
|
LEG_R: 5
|
|
443
443
|
};
|
|
444
|
+
/**
|
|
445
|
+
* How a player went down (bits 5-6 of PlayerState.fell), for the clients' fall: PLAIN as before,
|
|
446
|
+
* SHOT thrown the way the hit went (a gun, a blast, a rover), STRUCK by a blade or the fists: on
|
|
447
|
+
* his knees, then over on his side.
|
|
448
|
+
*/
|
|
449
|
+
var FALL$1 = {
|
|
450
|
+
PLAIN: 0,
|
|
451
|
+
SHOT: 1,
|
|
452
|
+
STRUCK: 2
|
|
453
|
+
};
|
|
444
454
|
/** The movement state of a player: what the body is doing, one of these. */
|
|
445
455
|
var MODE = {
|
|
446
456
|
/** Standing or running on a floor. */
|
|
@@ -5946,6 +5956,8 @@ var within = (p, at, r) => {
|
|
|
5946
5956
|
const [dx, dz] = [p.x - at[0], p.z - at[2]];
|
|
5947
5957
|
return dx * dx + dz * dz < r * r && Math.abs(p.y - at[1]) < 1;
|
|
5948
5958
|
};
|
|
5959
|
+
/** PlayerState.fell of one put down the FALL `kind` by a hit going (dx, dz) on the floor. */
|
|
5960
|
+
var felled = (kind, dx, dz) => kind << 5 | Math.round(Math.atan2(-dx, -dz) * 16 / Math.PI) & 31;
|
|
5949
5961
|
/**
|
|
5950
5962
|
* The start of a cut that moves the body, from a floor only: the lunge throws him along the look at
|
|
5951
5963
|
* LUNGE_SPEED for the burst of a dash, and spends the dash; the leap jumps him LEAP_SPEED up.
|
|
@@ -6290,7 +6302,7 @@ var encodeSnapshot = (s) => {
|
|
|
6290
6302
|
v.setUint8(o + 44, p.hits);
|
|
6291
6303
|
v.setUint8(o + 45, (p.swing ?? 0) & 63 | ((p.cut ?? 0) & 3) << 6);
|
|
6292
6304
|
v.setUint8(o + 46, (p.lost ?? 0) & 7 | ((p.cut ?? 0) & 4) << 1 | (p.fried ? 16 : 0) | (p.heavy ? 32 : 0));
|
|
6293
|
-
v.setUint8(o + 47, p.charge ?? 0);
|
|
6305
|
+
v.setUint8(o + 47, p.down ? p.fell ?? 0 : p.charge ?? 0);
|
|
6294
6306
|
v.setUint8(o + 48, p.lock ?? 0);
|
|
6295
6307
|
v.setUint8(o + 49, (p.foe ?? 0) & 15 | (p.dashes & 2) << 3 | (p.pressed ? 128 : 0));
|
|
6296
6308
|
v.setUint8(o + 50, p.pushes ?? 0);
|
|
@@ -8065,19 +8077,21 @@ var Room = class {
|
|
|
8065
8077
|
}
|
|
8066
8078
|
/**
|
|
8067
8079
|
* `hp` of a gun's damage to `foe` from `by`: as his class deals it (Kit.damage, a ninja's half), the
|
|
8068
|
-
* half points kept on `foe` toward the next. True when he went down; `how`
|
|
8080
|
+
* half points kept on `foe` toward the next, the hit going (dx, dz). True when he went down; `how`
|
|
8081
|
+
* is the FRAG then.
|
|
8069
8082
|
*/
|
|
8070
|
-
shot(foe, hp, by, how = FRAG.GUN) {
|
|
8083
|
+
shot(foe, hp, by, dx, dz, how = FRAG.GUN) {
|
|
8071
8084
|
const bank = (foe.halves ?? 0) + hp * 2 * (by ? kitOf(by.info.role, this.world.def).damage : 1);
|
|
8072
8085
|
foe.halves = bank % 2;
|
|
8073
|
-
return bank >= 2 && this.harm(foe, Math.floor(bank / 2), by, how);
|
|
8086
|
+
return bank >= 2 && this.harm(foe, Math.floor(bank / 2), by, how, felled(FALL$1.SHOT, dx, dz));
|
|
8074
8087
|
}
|
|
8075
8088
|
/**
|
|
8076
8089
|
* `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
|
|
8077
8090
|
* the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
|
|
8078
|
-
* True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone.
|
|
8091
|
+
* True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone. `fell`
|
|
8092
|
+
* is how he falls (felled()).
|
|
8079
8093
|
*/
|
|
8080
|
-
harm(foe, hp, by, how = FRAG.GUN) {
|
|
8094
|
+
harm(foe, hp, by, how = FRAG.GUN, fell = 0) {
|
|
8081
8095
|
if ((foe.state.hp -= hp) > 0) return false;
|
|
8082
8096
|
[foe.graze, foe.bruise, foe.blows, foe.halves] = [
|
|
8083
8097
|
0,
|
|
@@ -8099,6 +8113,7 @@ var Room = class {
|
|
|
8099
8113
|
wield: false,
|
|
8100
8114
|
swing: 0,
|
|
8101
8115
|
lost: LIMB.NONE,
|
|
8116
|
+
fell,
|
|
8102
8117
|
rail: -1,
|
|
8103
8118
|
railed: false,
|
|
8104
8119
|
rifle: -1,
|
|
@@ -8182,9 +8197,9 @@ var Room = class {
|
|
|
8182
8197
|
if (by) by.state.hits = by.state.hits + 1 & 255;
|
|
8183
8198
|
if (b.power === 0 || b.power === 6) {
|
|
8184
8199
|
foe.graze = ((foe.graze ?? 0) + 1) % 2;
|
|
8185
|
-
if (!foe.graze) this.shot(foe, 1, by);
|
|
8186
|
-
} else if (!b.arc) this.shot(foe, b.power ?? 1, by);
|
|
8187
|
-
else if (this.harm(foe, CUTS[b.arc].hp, by, FRAG.BLADE)) {
|
|
8200
|
+
if (!foe.graze) this.shot(foe, 1, by, b.dx, b.dz);
|
|
8201
|
+
} else if (!b.arc) this.shot(foe, b.power ?? 1, by, b.dx, b.dz);
|
|
8202
|
+
else if (this.harm(foe, CUTS[b.arc].hp, by, FRAG.BLADE, felled(FALL$1.STRUCK, b.dx, b.dz))) {
|
|
8188
8203
|
const from = by && {
|
|
8189
8204
|
...by.state,
|
|
8190
8205
|
cut: b.arc,
|
|
@@ -8253,7 +8268,7 @@ var Room = class {
|
|
|
8253
8268
|
for (const [, k] of cars) this.hurt(this.rovers[k], swingOf(p.state).hp, p.info.id, p.info.team);
|
|
8254
8269
|
for (const foe of foes) {
|
|
8255
8270
|
const drawn = seen.find((s) => s.id === foe.info.id);
|
|
8256
|
-
if (this.harm(foe, swingOf(p.state).hp, p, FRAG.BLADE)) foe.state.lost = limbOf(p.state, drawn);
|
|
8271
|
+
if (this.harm(foe, swingOf(p.state).hp, p, FRAG.BLADE, felled(FALL$1.STRUCK, ...knock(p.state)))) foe.state.lost = limbOf(p.state, drawn);
|
|
8257
8272
|
else {
|
|
8258
8273
|
const [dx, dz] = knock(p.state);
|
|
8259
8274
|
stumble(foe.state, dx, dz, 24, 4 * (p.state.heavy ? HEAVY : 1));
|
|
@@ -8278,7 +8293,7 @@ var Room = class {
|
|
|
8278
8293
|
foe.blows = (this.ticks - (foe.punched ?? -Infinity) <= PUNCH_MEMORY ? foe.blows ?? 0 : 0) + 1;
|
|
8279
8294
|
foe.punched = this.ticks;
|
|
8280
8295
|
foe.bruise = ((foe.bruise ?? 0) + 1) % PUNCH_HITS;
|
|
8281
|
-
if (!foe.bruise && this.harm(foe, 1, p, FRAG.FIST)) continue;
|
|
8296
|
+
if (!foe.bruise && this.harm(foe, 1, p, FRAG.FIST, felled(FALL$1.STRUCK, ...forward(p.state.yaw)))) continue;
|
|
8282
8297
|
if (foe.blows >= PUNCH_STUN) {
|
|
8283
8298
|
foe.blows = 0;
|
|
8284
8299
|
this.drop(foe.info.id);
|
|
@@ -8328,7 +8343,8 @@ var Room = class {
|
|
|
8328
8343
|
}
|
|
8329
8344
|
/** 1 hp of the bolt's drain to `foe`, as his railer deals it; if it puts him down he is disintegrated (`fried`). */
|
|
8330
8345
|
fry(foe) {
|
|
8331
|
-
|
|
8346
|
+
const r = foe.railer?.state ?? foe.state;
|
|
8347
|
+
foe.state.fried = this.shot(foe, 1, foe.railer, foe.state.x - r.x, foe.state.z - r.z, FRAG.RAIL);
|
|
8332
8348
|
}
|
|
8333
8349
|
/**
|
|
8334
8350
|
* A saber lock of `p`, after his input: it ends when a side leads by LOCK_WIN presses (the other
|
|
@@ -8352,7 +8368,7 @@ var Room = class {
|
|
|
8352
8368
|
if (Math.abs(lead) >= 8) {
|
|
8353
8369
|
const [w, l] = lead > 0 ? [p, o] : [o, p];
|
|
8354
8370
|
w.state.hits = w.state.hits + 1 & 255;
|
|
8355
|
-
if (!this.harm(l, 3, w, FRAG.BLADE)) {
|
|
8371
|
+
if (!this.harm(l, 3, w, FRAG.BLADE, felled(FALL$1.STRUCK, ...forward(w.state.yaw)))) {
|
|
8356
8372
|
const [dx, dz] = forward(w.state.yaw);
|
|
8357
8373
|
stumble(l.state, dx, dz, 24, 4);
|
|
8358
8374
|
l.state.zap = true;
|
|
@@ -8640,7 +8656,7 @@ var Room = class {
|
|
|
8640
8656
|
const own = q.info.id === by;
|
|
8641
8657
|
const hp = !q.state.down && q.state.mode !== MODE.RIDE && (own || q.info.team !== team) ? blast(this.world, c, q.state) : 0;
|
|
8642
8658
|
if (hp) {
|
|
8643
|
-
this.shot(q, hp, this.players().find((o) => o.info.id === by), FRAG.NADE);
|
|
8659
|
+
this.shot(q, hp, this.players().find((o) => o.info.id === by), q.state.x - c[0], q.state.z - c[2], FRAG.NADE);
|
|
8644
8660
|
hit ||= !own;
|
|
8645
8661
|
}
|
|
8646
8662
|
}
|
|
@@ -8659,7 +8675,9 @@ var Room = class {
|
|
|
8659
8675
|
if (closing < ROVER.SPLAT_MIN) continue;
|
|
8660
8676
|
foe.run = this.ticks;
|
|
8661
8677
|
p.state.hits = p.state.hits + 1 & 255;
|
|
8662
|
-
|
|
8678
|
+
const fell = felled(FALL$1.SHOT, r.vx, r.vz);
|
|
8679
|
+
const hp = closing < ROVER.SPLAT_KILL ? 1 : foe.state.hp;
|
|
8680
|
+
if (!this.harm(foe, hp, p, FRAG.VEHICLE, fell)) {
|
|
8663
8681
|
const v = len(r.vx, r.vz);
|
|
8664
8682
|
stumble(foe.state, r.vx / v, r.vz / v);
|
|
8665
8683
|
foe.state.zap = false;
|
|
@@ -69,6 +69,15 @@ export declare const SIT: {
|
|
|
69
69
|
* trunk and the legs follow the knock.
|
|
70
70
|
*/
|
|
71
71
|
export declare const MOVES: number[][];
|
|
72
|
+
/**
|
|
73
|
+
* The falls of one put down shot or struck (FALL, less one), keys of the seconds since he went
|
|
74
|
+
* down: the pelvis's tip (forward or back) and roll to the side, its height over the floor and how
|
|
75
|
+
* far it has gone along the throw (metres), the bend of the hips and the knees, the arms' lift
|
|
76
|
+
* forward and out, the elbows' bend, the spine's slump. Shot: thrown off his feet along the hit,
|
|
77
|
+
* flat on his back or his face, the arms flung out; struck: down on his knees, a sway, then over
|
|
78
|
+
* on his side, curled.
|
|
79
|
+
*/
|
|
80
|
+
export declare const FALLS: number[][][];
|
|
72
81
|
/**
|
|
73
82
|
* An arm's pose, the upper arm then the forearm, as the gait builds them: `s` 1 the right, -1 the
|
|
74
83
|
* left; the upper arm's lift forward, out to the side and turn inward, and the elbow's bend.
|
|
@@ -5,6 +5,8 @@ import type { World } from './world';
|
|
|
5
5
|
type Vec3 = [number, number, number];
|
|
6
6
|
/** Whether the feet of `p` are within `r` of the point `at` on the floor plane and within PICK_H of its height. */
|
|
7
7
|
export declare const within: (p: PlayerState, at: Vec3, r: number) => boolean;
|
|
8
|
+
/** PlayerState.fell of one put down the FALL `kind` by a hit going (dx, dz) on the floor. */
|
|
9
|
+
export declare const felled: (kind: number, dx: number, dz: number) => number;
|
|
8
10
|
/** What a step struck, for the host to resolve: nothing, a shot (a plasma ball), the katana's cut, a rail gun's beam, a laser rifle's shot, or a grenade from its launcher. */
|
|
9
11
|
export declare const STRIKE: {
|
|
10
12
|
readonly NONE: 0;
|
|
@@ -102,13 +102,15 @@ export declare class Room {
|
|
|
102
102
|
private enemies;
|
|
103
103
|
/**
|
|
104
104
|
* `hp` of a gun's damage to `foe` from `by`: as his class deals it (Kit.damage, a ninja's half), the
|
|
105
|
-
* half points kept on `foe` toward the next. True when he went down; `how`
|
|
105
|
+
* half points kept on `foe` toward the next, the hit going (dx, dz). True when he went down; `how`
|
|
106
|
+
* is the FRAG then.
|
|
106
107
|
*/
|
|
107
108
|
private shot;
|
|
108
109
|
/**
|
|
109
110
|
* `hp` of damage to `foe`; the last one puts him down: he lies where he fell, without the gun or
|
|
110
111
|
* the katana, a flag he carries drops with the lock, and `lost` is NONE (a cut sets it after).
|
|
111
|
-
* True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone.
|
|
112
|
+
* True when he went down: an enemy `by` scores a frag made `how` (FRAG), told to everyone. `fell`
|
|
113
|
+
* is how he falls (felled()).
|
|
112
114
|
*/
|
|
113
115
|
private harm;
|
|
114
116
|
/**
|
|
@@ -107,6 +107,16 @@ export declare const LIMB: {
|
|
|
107
107
|
readonly LEG_L: 4;
|
|
108
108
|
readonly LEG_R: 5;
|
|
109
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* How a player went down (bits 5-6 of PlayerState.fell), for the clients' fall: PLAIN as before,
|
|
112
|
+
* SHOT thrown the way the hit went (a gun, a blast, a rover), STRUCK by a blade or the fists: on
|
|
113
|
+
* his knees, then over on his side.
|
|
114
|
+
*/
|
|
115
|
+
export declare const FALL: {
|
|
116
|
+
readonly PLAIN: 0;
|
|
117
|
+
readonly SHOT: 1;
|
|
118
|
+
readonly STRUCK: 2;
|
|
119
|
+
};
|
|
110
120
|
/** The movement state of a player: what the body is doing, one of these. */
|
|
111
121
|
export declare const MODE: {
|
|
112
122
|
/** Standing or running on a floor. */
|
|
@@ -285,6 +295,8 @@ export interface PlayerState {
|
|
|
285
295
|
heavy?: boolean;
|
|
286
296
|
/** While down after a katana's cut put him down: the LIMB it took off, for the clients to draw. NONE once up. Absent reads NONE. */
|
|
287
297
|
lost?: number;
|
|
298
|
+
/** While down: bits 5-6 the FALL, bits 0-4 the way the hit went, a yaw in 32nds of a turn (felled() in gun.ts). Absent reads 0. */
|
|
299
|
+
fell?: number;
|
|
288
300
|
/** For the animation, not sent: the EV bits of the last step, and the speed of a landing. */
|
|
289
301
|
ev: number;
|
|
290
302
|
fall: number;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@korial29/tiny-fps",
|
|
3
3
|
"description": "Tiny multiplayer first-person rooftop game for the browser: raw WebGL, zero runtime dependencies, WebSocket or same-browser multi-tab play.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.142.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|