@adatechnology/game-weapons 0.1.4 → 0.2.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 +78 -18
- package/dist/index.d.ts +549 -26
- package/dist/index.global.js +5847 -406
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5847 -406
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,307 @@
|
|
|
1
|
-
import { Vec3,
|
|
1
|
+
import { Vec3, Use, ExplosionChain, Shot } from '@adatechnology/game-contracts';
|
|
2
2
|
export { Shot, Use, Vec3 } from '@adatechnology/game-contracts';
|
|
3
3
|
|
|
4
|
+
/** Everything a host needs to apply a blast: where, how big, in which direction, and what else it does. */
|
|
5
|
+
interface Detonation {
|
|
6
|
+
readonly explosive: ExplosiveId;
|
|
7
|
+
readonly cause: ExplosiveTrigger;
|
|
8
|
+
readonly point: Vec3;
|
|
9
|
+
/** The way a directional charge faces; for everything else the direction the body was moving (or facing when placed). */
|
|
10
|
+
readonly direction: Vec3;
|
|
11
|
+
/** Seconds on the clock of the body. */
|
|
12
|
+
readonly at: number;
|
|
13
|
+
readonly energy: number;
|
|
14
|
+
readonly lethalRadius: number;
|
|
15
|
+
readonly injuryRadius: number;
|
|
16
|
+
readonly noise: number;
|
|
17
|
+
readonly destructionLevel: ExplosiveDef['destructionLevel'];
|
|
18
|
+
readonly cone?: ExplosiveDef['cone'];
|
|
19
|
+
readonly stunSeconds?: number;
|
|
20
|
+
readonly fire?: ExplosiveDef['fire'];
|
|
21
|
+
}
|
|
22
|
+
type ExplosiveEvent = {
|
|
23
|
+
type: 'armed';
|
|
24
|
+
at: number;
|
|
25
|
+
distance: number;
|
|
26
|
+
} | {
|
|
27
|
+
type: 'impact';
|
|
28
|
+
at: number;
|
|
29
|
+
point: Vec3;
|
|
30
|
+
armed: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Hit something before it was armed: it does not explode. */
|
|
33
|
+
| {
|
|
34
|
+
type: 'dud';
|
|
35
|
+
at: number;
|
|
36
|
+
point: Vec3;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'detonate';
|
|
39
|
+
at: number;
|
|
40
|
+
detonation: Detonation;
|
|
41
|
+
};
|
|
42
|
+
/** The first surface the segment `from` to `to` crosses: where, its normal and whether it is ground (default: normal pointing up). */
|
|
43
|
+
type SurfaceProbe = (from: Vec3, to: Vec3) => {
|
|
44
|
+
point: Vec3;
|
|
45
|
+
normal: Vec3;
|
|
46
|
+
ground?: boolean;
|
|
47
|
+
} | null;
|
|
48
|
+
interface ExplosiveBodyInit {
|
|
49
|
+
readonly explosive: ExplosiveDef;
|
|
50
|
+
readonly origin: Vec3;
|
|
51
|
+
/** Initial velocity in m/s; absent for something set down. */
|
|
52
|
+
readonly velocity?: Vec3;
|
|
53
|
+
/** Facing of a placed charge (the cone of a mine). */
|
|
54
|
+
readonly direction?: Vec3;
|
|
55
|
+
/** `timer`: explodes `fuse` seconds after it leaves the hand; `impact`: explodes on the first hit once armed; `wire`/`remote`: waits for `trigger()`. */
|
|
56
|
+
readonly triggers: readonly ExplosiveTrigger[];
|
|
57
|
+
readonly fuse?: number;
|
|
58
|
+
/** Metres to fly before an impact sets it off (rockets); 0 arms it at once. */
|
|
59
|
+
readonly armDistance?: number;
|
|
60
|
+
readonly rules: WeaponRules['explosives'];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One explosive in flight or set down. `step` flies it (gravity, bounces off what `probe` finds) and counts the fuse; `trigger` sets off what waits
|
|
64
|
+
* for a wire, a remote detonator, a bullet, fire or a nearby blast. Same inputs, same events: there is no randomness.
|
|
65
|
+
*/
|
|
66
|
+
declare class ExplosiveBody {
|
|
67
|
+
position: Vec3;
|
|
68
|
+
velocity: Vec3;
|
|
69
|
+
readonly explosive: ExplosiveDef;
|
|
70
|
+
private readonly triggers;
|
|
71
|
+
private readonly armDistance;
|
|
72
|
+
private readonly rules;
|
|
73
|
+
private facing;
|
|
74
|
+
private clock;
|
|
75
|
+
private flown;
|
|
76
|
+
private fuseLeft;
|
|
77
|
+
private isArmed;
|
|
78
|
+
private isDone;
|
|
79
|
+
private isDud;
|
|
80
|
+
constructor(init: ExplosiveBodyInit);
|
|
81
|
+
get age(): number;
|
|
82
|
+
/** Metres flown so far. */
|
|
83
|
+
get travelled(): number;
|
|
84
|
+
get armed(): boolean;
|
|
85
|
+
/** Exploded or turned out a dud: nothing more happens. */
|
|
86
|
+
get done(): boolean;
|
|
87
|
+
get dud(): boolean;
|
|
88
|
+
/** Seconds until the timer sets it off, or undefined without one. */
|
|
89
|
+
get fuseRemaining(): number | undefined;
|
|
90
|
+
step(dt: number, probe?: SurfaceProbe): ExplosiveEvent[];
|
|
91
|
+
/** Sets it off from outside; undefined when this explosive does not answer to `cause` or is already done. */
|
|
92
|
+
trigger(cause: ExplosiveTrigger): ExplosiveEvent | undefined;
|
|
93
|
+
private moves;
|
|
94
|
+
private fly;
|
|
95
|
+
private checkArmed;
|
|
96
|
+
private onImpact;
|
|
97
|
+
private detonate;
|
|
98
|
+
}
|
|
99
|
+
/** The body of the explosive a `throw` or `place` use carries; undefined for any other use or an unknown explosive id. */
|
|
100
|
+
declare const createExplosiveBody: (use: Use, explosives: ReadonlyMap<ExplosiveId, ExplosiveDef>, rules: WeaponRules["explosives"]) => ExplosiveBody | undefined;
|
|
101
|
+
|
|
102
|
+
type ExplosiveId = string;
|
|
103
|
+
/** What sets an explosive off: its own timer, hitting something, a bullet, fire, a trip wire, a remote detonator, or another blast nearby. */
|
|
104
|
+
type ExplosiveTrigger = 'timer' | 'impact' | 'shot' | 'fire' | 'wire' | 'remote' | 'explosion';
|
|
105
|
+
/** Chain reaction of an explosive that sits in the world (fuel barrel, car tank, gas pump); `game-destruction` reads it from `explodes.chain`. */
|
|
106
|
+
type ExplosiveChain = ExplosionChain;
|
|
107
|
+
/** The wire a placed charge stretches: from the charge, `length` metres out at `angleDeg` from the way it faces, `height` metres above where it sits. */
|
|
108
|
+
interface ExplosiveTripwire {
|
|
109
|
+
/** Metres. */
|
|
110
|
+
readonly length: number;
|
|
111
|
+
/** Degrees from the facing of the charge, counter-clockwise seen from above (default 0: straight ahead). */
|
|
112
|
+
readonly angleDeg?: number;
|
|
113
|
+
/** Metres above the charge (default 0.15: shin height). */
|
|
114
|
+
readonly height?: number;
|
|
115
|
+
}
|
|
116
|
+
interface ExplosiveDef {
|
|
117
|
+
readonly id: ExplosiveId;
|
|
118
|
+
readonly name?: string;
|
|
119
|
+
readonly kind: 'fragmentation' | 'blast' | 'incendiary' | 'directional' | 'flash' | 'shaped_charge' | 'fuel';
|
|
120
|
+
/** Radius in metres inside which everything dies. */
|
|
121
|
+
readonly lethalRadius: number;
|
|
122
|
+
/** Radius in metres of the wounding area (damage falls with distance). */
|
|
123
|
+
readonly injuryRadius: number;
|
|
124
|
+
readonly cone?: {
|
|
125
|
+
readonly halfAngleDeg: number;
|
|
126
|
+
readonly length: number;
|
|
127
|
+
};
|
|
128
|
+
/** Joules. */
|
|
129
|
+
readonly energy: number;
|
|
130
|
+
/** What the blast tears down: 0 nothing, 1 light, 2 walls, 3 structures. */
|
|
131
|
+
readonly destructionLevel: 0 | 1 | 2 | 3;
|
|
132
|
+
/** Audible distance in metres. */
|
|
133
|
+
readonly noise: number;
|
|
134
|
+
/** Seconds from arming to the blast; fixed. Overridden by `fuseLength` with `burnRate`, or by `fuseRange`. */
|
|
135
|
+
readonly fuse?: number;
|
|
136
|
+
/** Seconds from arming to the blast, sampled per throw between the two ends (a flashbang: 1.0 to 2.3 s from the lever). */
|
|
137
|
+
readonly fuseRange?: readonly [number, number];
|
|
138
|
+
/** Metres of safety fuse; with `burnRate` it gives the fuse in seconds, so a longer fuse builds a delayed trap. */
|
|
139
|
+
readonly fuseLength?: number;
|
|
140
|
+
/** Seconds the safety fuse takes to burn one metre (about 131 s/m). */
|
|
141
|
+
readonly burnRate?: number;
|
|
142
|
+
/** Scatter of the burn rate as a fraction, sampled per throw (0.1 = ±10%). */
|
|
143
|
+
readonly burnTolerance?: number;
|
|
144
|
+
readonly stunSeconds?: number;
|
|
145
|
+
readonly fire?: {
|
|
146
|
+
temperature: number;
|
|
147
|
+
radius: number;
|
|
148
|
+
seconds: number;
|
|
149
|
+
};
|
|
150
|
+
readonly triggers?: readonly ExplosiveTrigger[];
|
|
151
|
+
readonly chain?: ExplosiveChain;
|
|
152
|
+
/** The trip wire of an explosive with the `wire` trigger; without it the one in `rules.explosives.tripwire` is used. */
|
|
153
|
+
readonly tripwire?: ExplosiveTripwire;
|
|
154
|
+
/** Kilograms. */
|
|
155
|
+
readonly mass?: number;
|
|
156
|
+
readonly sources?: readonly DataSource[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Locales shipped with the package. Unknown locales fall back to `en`. */
|
|
160
|
+
type WeaponsLocale = 'en' | 'pt-BR';
|
|
161
|
+
interface WeaponsStrings {
|
|
162
|
+
/** Display name of each weapon id. */
|
|
163
|
+
weapons: Record<string, string>;
|
|
164
|
+
/** Display name of each fire mode. */
|
|
165
|
+
modes: Record<string, string>;
|
|
166
|
+
/** Display name of each weapon category. */
|
|
167
|
+
categories: Record<string, string>;
|
|
168
|
+
/** Display name of each explosive id. */
|
|
169
|
+
explosives: Record<string, string>;
|
|
170
|
+
/** Display name of each weapon fault. */
|
|
171
|
+
faults: Record<string, string>;
|
|
172
|
+
/** Display name of each weapon condition. */
|
|
173
|
+
conditions: Record<string, string>;
|
|
174
|
+
}
|
|
175
|
+
declare const locales: Record<WeaponsLocale, WeaponsStrings>;
|
|
176
|
+
declare const resolveStrings: (locale: string | undefined, overrides?: DeepPartial<WeaponsStrings>) => WeaponsStrings;
|
|
177
|
+
|
|
178
|
+
type FaultId = 'misfire' | 'stovepipe' | 'double_feed' | 'failure_to_extract';
|
|
179
|
+
/** Wear of a weapon and how likely it jams. */
|
|
180
|
+
interface ConditionDef {
|
|
181
|
+
readonly id: string;
|
|
182
|
+
/** Chance of a fault per round, 0 to 1. */
|
|
183
|
+
readonly faultChance: number;
|
|
184
|
+
}
|
|
185
|
+
/** Quality of the ammunition and how likely a round does not fire. */
|
|
186
|
+
interface AmmoQualityDef {
|
|
187
|
+
readonly id: string;
|
|
188
|
+
readonly faultChance: number;
|
|
189
|
+
}
|
|
190
|
+
interface FaultContext {
|
|
191
|
+
readonly def: WeaponDef;
|
|
192
|
+
readonly condition: ConditionDef;
|
|
193
|
+
/** Heat of the weapon, 0 to `rules.heat.cap`. */
|
|
194
|
+
readonly heat: number;
|
|
195
|
+
}
|
|
196
|
+
/** Numbers that rule how weapons behave in a game; override any of them with `ArsenalOptions.rules`. */
|
|
197
|
+
interface WeaponRules {
|
|
198
|
+
readonly faults: boolean;
|
|
199
|
+
readonly conditions: readonly ConditionDef[];
|
|
200
|
+
readonly defaultCondition: string;
|
|
201
|
+
readonly ammoQualities: readonly AmmoQualityDef[];
|
|
202
|
+
readonly defaultAmmoQuality: string;
|
|
203
|
+
readonly faultChance: (context: FaultContext) => number;
|
|
204
|
+
readonly heat: {
|
|
205
|
+
readonly cap: number;
|
|
206
|
+
readonly displayMax: number;
|
|
207
|
+
readonly decayBase: number;
|
|
208
|
+
readonly decayPerPoint: number;
|
|
209
|
+
readonly faultFrom: number;
|
|
210
|
+
readonly faultSpan: number;
|
|
211
|
+
readonly perShot: Readonly<Record<CaseType, number>>;
|
|
212
|
+
readonly perRocket: number;
|
|
213
|
+
};
|
|
214
|
+
/** Each shot in the last `window` seconds raises the noise radius by `step`, up to `cap`. */
|
|
215
|
+
readonly noiseBurst: {
|
|
216
|
+
readonly step: number;
|
|
217
|
+
readonly window: number;
|
|
218
|
+
readonly cap: number;
|
|
219
|
+
};
|
|
220
|
+
/** How thrown and launched explosives fly and bounce. */
|
|
221
|
+
readonly explosives: {
|
|
222
|
+
/** m/s². */
|
|
223
|
+
readonly gravity: number;
|
|
224
|
+
/** Fraction of the speed along the surface normal kept (and reversed) in a bounce off the ground. */
|
|
225
|
+
readonly groundRestitution: number;
|
|
226
|
+
/** Fraction of the speed along the ground kept after a bounce off the ground. */
|
|
227
|
+
readonly groundFriction: number;
|
|
228
|
+
/** Fraction of the speed kept (and reversed) in a bounce off a wall. */
|
|
229
|
+
readonly wallRestitution: number;
|
|
230
|
+
/** A timer explosive whose fuse is at least this many seconds is set down lit instead of thrown (a long safety fuse: a delayed trap). */
|
|
231
|
+
readonly placeFuseFrom: number;
|
|
232
|
+
/** The wire of a charge set down with the `wire` trigger that does not name one. */
|
|
233
|
+
readonly tripwire: Required<ExplosiveTripwire>;
|
|
234
|
+
};
|
|
235
|
+
readonly draw: number;
|
|
236
|
+
readonly clear: number;
|
|
237
|
+
readonly startSafe: boolean;
|
|
238
|
+
}
|
|
239
|
+
type ReloadKind = 'tactical' | 'empty' | 'one_by_one';
|
|
240
|
+
type ReloadStageId = 'magazine_out' | 'magazine_in' | 'charge' | 'bolt_open' | 'round_in' | 'bolt_close' | 'pump_cycle' | 'lever_cycle' | 'cylinder_open' | 'cylinder_eject' | 'cylinder_load' | 'cylinder_close' | 'barrels_open' | 'casings_eject' | 'rounds_in' | 'barrels_close' | 'cover_open' | 'belt_swap' | 'cover_close' | 'tank_swap' | 'tube_drop' | 'tube_seat' | 'rocket_seat' | 'breech_open' | 'breech_close';
|
|
241
|
+
/** `at` is a fraction (0 to 1) of the whole reload. */
|
|
242
|
+
interface ReloadStage {
|
|
243
|
+
readonly stage: ReloadStageId;
|
|
244
|
+
readonly at: number;
|
|
245
|
+
}
|
|
246
|
+
/** Events a weapon emits for a host to animate and play sounds; `at` is the weapon clock in seconds. */
|
|
247
|
+
type WeaponEvent = {
|
|
248
|
+
type: 'draw';
|
|
249
|
+
phase: 'start' | 'end';
|
|
250
|
+
at: number;
|
|
251
|
+
} | {
|
|
252
|
+
type: 'shot';
|
|
253
|
+
shots: number;
|
|
254
|
+
rounds: number;
|
|
255
|
+
mode: FireMode;
|
|
256
|
+
at: number;
|
|
257
|
+
} | {
|
|
258
|
+
type: 'misfire';
|
|
259
|
+
at: number;
|
|
260
|
+
} | {
|
|
261
|
+
type: 'cycle';
|
|
262
|
+
phase: 'start' | 'end';
|
|
263
|
+
at: number;
|
|
264
|
+
} | {
|
|
265
|
+
type: 'reload';
|
|
266
|
+
phase: 'start' | 'end';
|
|
267
|
+
kind: ReloadKind;
|
|
268
|
+
at: number;
|
|
269
|
+
} | {
|
|
270
|
+
type: 'reload_stage';
|
|
271
|
+
stage: ReloadStageId;
|
|
272
|
+
at: number;
|
|
273
|
+
} | {
|
|
274
|
+
type: 'feed';
|
|
275
|
+
at: number;
|
|
276
|
+
} | {
|
|
277
|
+
type: 'empty';
|
|
278
|
+
at: number;
|
|
279
|
+
} | {
|
|
280
|
+
type: 'mode';
|
|
281
|
+
mode: FireMode;
|
|
282
|
+
at: number;
|
|
283
|
+
} | {
|
|
284
|
+
type: 'fault';
|
|
285
|
+
fault: FaultId;
|
|
286
|
+
at: number;
|
|
287
|
+
} | {
|
|
288
|
+
type: 'clear';
|
|
289
|
+
fault: FaultId;
|
|
290
|
+
phase: 'start' | 'end';
|
|
291
|
+
at: number;
|
|
292
|
+
} | {
|
|
293
|
+
type: 'safety';
|
|
294
|
+
on: boolean;
|
|
295
|
+
at: number;
|
|
296
|
+
}
|
|
297
|
+
/** Cooking a throwable: `start` pulls the pin, `throw` releases it with `fuse` seconds left, `burst` is the fuse running out while held (`fuse` 0). */
|
|
298
|
+
| {
|
|
299
|
+
type: 'cook';
|
|
300
|
+
phase: 'start' | 'throw' | 'burst';
|
|
301
|
+
fuse: number;
|
|
302
|
+
at: number;
|
|
303
|
+
};
|
|
304
|
+
|
|
4
305
|
/**
|
|
5
306
|
* Public types of @adatechnology/game-weapons.
|
|
6
307
|
*
|
|
@@ -34,9 +335,52 @@ interface CaliberDef {
|
|
|
34
335
|
/** Armour-piercing or hollow-point flavour (a damage model may use it). */
|
|
35
336
|
kind?: 'fmj' | 'hp' | 'ap' | 'buck' | 'slug' | 'birdshot' | 'rimfire' | 'arrow' | 'bolt';
|
|
36
337
|
tags?: string[];
|
|
338
|
+
/** Audible distance of a shot in this calibre, metres. A weapon may override it (suppressor). */
|
|
339
|
+
noise?: number;
|
|
340
|
+
caseType?: CaseType;
|
|
341
|
+
rim?: RimType;
|
|
342
|
+
cartridge?: CartridgeDims;
|
|
343
|
+
/** Where the numbers come from (team deliveries, the SDK itself, a published reference, or derived from a sibling). */
|
|
344
|
+
sources?: readonly DataSource[];
|
|
345
|
+
}
|
|
346
|
+
type CaseType = 'pistol' | 'rifle' | 'shell' | 'big' | 'tiny';
|
|
347
|
+
type RimType = 'rimfire' | 'rimmed' | 'rimless' | 'shell';
|
|
348
|
+
type DataSource = 'gallery' | 'arsenal' | 'game' | 'lab' | 'sdk' | 'reference' | 'derived';
|
|
349
|
+
/** Real cartridge dimensions in mm. */
|
|
350
|
+
interface CartridgeDims {
|
|
351
|
+
readonly caseDiameter: number;
|
|
352
|
+
readonly overallLength: number;
|
|
353
|
+
readonly caseLength: number;
|
|
354
|
+
readonly projectileDiameter: number;
|
|
355
|
+
}
|
|
356
|
+
/** What a `firearm` action holds. */
|
|
357
|
+
type FirearmAction = Extract<WeaponAction, {
|
|
358
|
+
kind: 'firearm';
|
|
359
|
+
}>;
|
|
360
|
+
type FireMode = 'single' | 'semi' | 'burst' | 'auto' | 'pump' | 'bolt' | 'lever' | 'break' | 'volley';
|
|
361
|
+
type WeaponCategory = 'pistol' | 'revolver' | 'smg' | 'rifle' | 'carbine' | 'sniper' | 'dmr' | 'hunting' | 'machine_gun' | 'launcher' | 'shotgun' | 'bow' | 'crossbow' | 'melee_blunt' | 'melee_blade' | 'flame' | 'heat' | 'throwable' | 'tool' | 'extinguisher' | 'hand';
|
|
362
|
+
/** How a weapon is reloaded; it picks the animation set and the order of the reload stages. */
|
|
363
|
+
type ReloadFamily = 'pistol' | 'magazine' | 'top_magazine' | 'top_load_semi' | 'tube_semi' | 'pump' | 'lever' | 'bolt' | 'bolt_magazine' | 'belt' | 'revolver' | 'break' | 'rocket' | 'flame';
|
|
364
|
+
/** Seconds of each phase of handling a weapon. */
|
|
365
|
+
interface WeaponTimings {
|
|
366
|
+
readonly draw: number;
|
|
367
|
+
readonly reload: number;
|
|
368
|
+
readonly reloadEmpty?: number;
|
|
369
|
+
/** Seconds per round when the weapon loads one round at a time. */
|
|
370
|
+
readonly perRound?: number;
|
|
371
|
+
/** Seconds to cycle a manual action between shots. */
|
|
372
|
+
readonly cycle?: number;
|
|
373
|
+
/** Seconds to clear a fault. */
|
|
374
|
+
readonly clear: number;
|
|
375
|
+
readonly modeSwitch?: number;
|
|
376
|
+
}
|
|
377
|
+
/** Real dimensions: metres and kilograms. */
|
|
378
|
+
interface WeaponDimensions {
|
|
379
|
+
readonly length: number;
|
|
380
|
+
readonly barrel: number;
|
|
381
|
+
readonly emptyMass: number;
|
|
382
|
+
readonly lengthCollapsed?: number;
|
|
37
383
|
}
|
|
38
|
-
type FireMode = 'single' | 'semi' | 'burst' | 'auto' | 'pump' | 'bolt' | 'lever' | 'break';
|
|
39
|
-
type WeaponCategory = 'pistol' | 'revolver' | 'smg' | 'rifle' | 'carbine' | 'sniper' | 'shotgun' | 'bow' | 'crossbow' | 'melee_blunt' | 'melee_blade' | 'flame' | 'heat' | 'throwable' | 'tool' | 'extinguisher' | 'hand';
|
|
40
384
|
/** What using the item does. Firearms produce ballistic shots; the rest produce one `Use` of their kind. */
|
|
41
385
|
type WeaponAction = {
|
|
42
386
|
kind: 'firearm';
|
|
@@ -62,8 +406,43 @@ type WeaponAction = {
|
|
|
62
406
|
recoil: [number, number];
|
|
63
407
|
/** Effective range in metres (shots past it keep going with drag; the host may cut them). */
|
|
64
408
|
range: number;
|
|
65
|
-
/** Audible distance in metres (a horde game uses it to attract zombies). */
|
|
66
|
-
noise
|
|
409
|
+
/** Audible distance in metres (a horde game uses it to attract zombies). Defaults to the calibre's `noise`. */
|
|
410
|
+
noise?: number;
|
|
411
|
+
/** Muzzle speed of this weapon, m/s. Defaults to the calibre reference times `barrel`. */
|
|
412
|
+
muzzleSpeed?: number;
|
|
413
|
+
family?: ReloadFamily;
|
|
414
|
+
timings?: WeaponTimings;
|
|
415
|
+
/** Rounds that fit in the chamber on top of the magazine. */
|
|
416
|
+
chamber?: number;
|
|
417
|
+
/** Other magazine sizes the weapon accepts. */
|
|
418
|
+
magazineOptions?: readonly number[];
|
|
419
|
+
/** Magazine tubes (a bullpup shotgun has two). */
|
|
420
|
+
tubes?: number;
|
|
421
|
+
/** Multiplies the fault chance (1 = average, below 1 more reliable). */
|
|
422
|
+
faultFactor?: number;
|
|
423
|
+
/** Real accuracy in minutes of angle (data only). */
|
|
424
|
+
moa?: number;
|
|
425
|
+
/** Shotgun pattern width at 25 m in centimetres (data only). */
|
|
426
|
+
patternCm?: number;
|
|
427
|
+
/** Other calibres the weapon fires (a .357 revolver also fires .38 Special). */
|
|
428
|
+
acceptsCalibers?: readonly CaliberId[];
|
|
429
|
+
} | {
|
|
430
|
+
kind: 'launcher';
|
|
431
|
+
projectile: ExplosiveId;
|
|
432
|
+
magazine: number;
|
|
433
|
+
reload: number;
|
|
434
|
+
timings?: WeaponTimings;
|
|
435
|
+
family: 'rocket' | 'break';
|
|
436
|
+
disposable?: boolean;
|
|
437
|
+
speed: number;
|
|
438
|
+
/** Distance in metres below which the projectile hits without exploding. */
|
|
439
|
+
minArmDistance: number;
|
|
440
|
+
/** Radius in metres of the blast behind the launcher. */
|
|
441
|
+
backblast: number;
|
|
442
|
+
/** Half-angle in degrees of the cone behind the launcher where the blast is dangerous (default 180: the whole sphere of `backblast`). */
|
|
443
|
+
backblastHalfAngleDeg?: number;
|
|
444
|
+
recoil: [number, number];
|
|
445
|
+
noise?: number;
|
|
67
446
|
} | {
|
|
68
447
|
kind: 'melee';
|
|
69
448
|
damage: 'blunt' | 'slash';
|
|
@@ -82,6 +461,8 @@ type WeaponAction = {
|
|
|
82
461
|
fuel: number;
|
|
83
462
|
cone?: boolean;
|
|
84
463
|
noise: number;
|
|
464
|
+
family?: ReloadFamily;
|
|
465
|
+
timings?: WeaponTimings;
|
|
85
466
|
} | {
|
|
86
467
|
kind: 'heat';
|
|
87
468
|
temperature: number;
|
|
@@ -92,7 +473,8 @@ type WeaponAction = {
|
|
|
92
473
|
noise: number;
|
|
93
474
|
} | {
|
|
94
475
|
kind: 'throwable'; /** Throwables carried (default 3). */
|
|
95
|
-
count?: number;
|
|
476
|
+
count?: number; /** The explosive this throwable uses; `energy`, `radius` and `noise` come from it. */
|
|
477
|
+
explosive?: ExplosiveId;
|
|
96
478
|
energy: number;
|
|
97
479
|
radius: number;
|
|
98
480
|
fuse: number;
|
|
@@ -127,6 +509,14 @@ interface WeaponDef {
|
|
|
127
509
|
/** Mass in kg (carry weight, and thrown melee weapons). */
|
|
128
510
|
mass: number;
|
|
129
511
|
tags?: string[];
|
|
512
|
+
dimensions?: WeaponDimensions;
|
|
513
|
+
/** Maker of a real-world model, e.g. `Glock`. */
|
|
514
|
+
maker?: string;
|
|
515
|
+
/** The generic weapon whose handling numbers (spread, bloom, range, recoil) this model uses. */
|
|
516
|
+
archetype?: WeaponId;
|
|
517
|
+
/** The weapon this one is a variant of. */
|
|
518
|
+
variantOf?: WeaponId;
|
|
519
|
+
sources?: readonly DataSource[];
|
|
130
520
|
}
|
|
131
521
|
interface TriggerResult {
|
|
132
522
|
/** Shots fired this call (firearms). */
|
|
@@ -134,11 +524,24 @@ interface TriggerResult {
|
|
|
134
524
|
/** Uses this call (everything else). */
|
|
135
525
|
uses: Use[];
|
|
136
526
|
/** `ok`, or why nothing happened. */
|
|
137
|
-
status: 'ok' | 'empty' | 'reloading' | 'cooldown' | 'no_fuel' | 'safe';
|
|
527
|
+
status: 'ok' | 'empty' | 'reloading' | 'cooldown' | 'no_fuel' | 'safe' | 'drawing' | 'fault' | 'misfire' | 'clearing';
|
|
138
528
|
/** Camera kick to apply, degrees [pitch, yaw]. */
|
|
139
529
|
recoil: [number, number];
|
|
140
530
|
/** Audible radius of what happened, metres (0 when nothing). */
|
|
141
531
|
noise: number;
|
|
532
|
+
/** Cartridges spent by this call: a shotgun shell is one, a burst is several. */
|
|
533
|
+
rounds: number;
|
|
534
|
+
/** Seconds after the start of the call at which each round left the barrel. */
|
|
535
|
+
roundTimes: number[];
|
|
536
|
+
/** The fault that stopped the weapon during this call, if any. */
|
|
537
|
+
fault?: FaultId;
|
|
538
|
+
}
|
|
539
|
+
type ReloadRequest = 'auto' | 'full' | 'one_by_one';
|
|
540
|
+
/** What the weapon is busy with right now, and between which seconds of its own clock. */
|
|
541
|
+
interface WeaponPhase {
|
|
542
|
+
readonly id: 'draw' | 'cycle' | 'reload' | 'clear' | 'mode';
|
|
543
|
+
readonly start: number;
|
|
544
|
+
readonly end: number;
|
|
142
545
|
}
|
|
143
546
|
interface WeaponState {
|
|
144
547
|
readonly def: WeaponDef;
|
|
@@ -150,65 +553,185 @@ interface WeaponState {
|
|
|
150
553
|
reserve: number;
|
|
151
554
|
mode: FireMode;
|
|
152
555
|
readonly reloading: boolean;
|
|
556
|
+
/** True after a pistol fires its last round: the slide stays back until the magazine is changed. */
|
|
557
|
+
readonly locked: boolean;
|
|
558
|
+
readonly phase: WeaponPhase | null;
|
|
559
|
+
/** The fault the weapon is stuck with until it is cleared. */
|
|
560
|
+
readonly fault: FaultId | null;
|
|
561
|
+
readonly clearing: boolean;
|
|
562
|
+
/** With the safety on the trigger does nothing. */
|
|
563
|
+
readonly safety: boolean;
|
|
564
|
+
/** Heat of the barrel, 0 to `rules.heat.cap`. */
|
|
565
|
+
readonly heat: number;
|
|
566
|
+
/** 0 to 1: the heat against what the display shows as full. */
|
|
567
|
+
readonly heatLevel: number;
|
|
568
|
+
readonly condition: string;
|
|
569
|
+
readonly ammoQuality: string;
|
|
153
570
|
/** Current spread in degrees (base + bloom). */
|
|
154
571
|
readonly spread: number;
|
|
155
572
|
/**
|
|
156
573
|
* Pull or hold the trigger for `dt` seconds from `origin` towards `direction`. `held` = the trigger stays down (auto fire, continuous
|
|
157
|
-
* flame); a new pull with `held: false` fires semi/single once.
|
|
574
|
+
* flame); a new pull with `held: false` fires semi/single once. A throwable with a timer fuse is cooked: the pull takes the pin out and the
|
|
575
|
+
* fuse starts to count, `release()` throws it with the fuse that is left, and holding past the fuse sets it off in the hand (a `throw` use with
|
|
576
|
+
* `inHand`). Impact and remote ones, and the ones set down, act on the pull.
|
|
158
577
|
*/
|
|
159
578
|
trigger(origin: Vec3, direction: Vec3, dt: number, held?: boolean, source?: string): TriggerResult;
|
|
160
|
-
|
|
161
|
-
|
|
579
|
+
/**
|
|
580
|
+
* Lets go of the trigger. A throwable being cooked (see `trigger`) is thrown with what is left of its fuse, so this returns the result of that throw
|
|
581
|
+
* (`origin` and `direction` default to the aim of the last `trigger` call); anything else returns null.
|
|
582
|
+
*/
|
|
583
|
+
release(origin?: Vec3, direction?: Vec3): TriggerResult | null;
|
|
584
|
+
/** True while a throwable's pin is pulled and the trigger is held. */
|
|
585
|
+
readonly cooking: boolean;
|
|
586
|
+
/** Turns the safety on or off; returns the state it is in now. */
|
|
587
|
+
setSafety(on: boolean): boolean;
|
|
588
|
+
/** Starts clearing the fault (it takes `timings.clear` seconds); false when there is nothing to clear. */
|
|
589
|
+
clearFault(): boolean;
|
|
590
|
+
/** Wear of the weapon, by `rules.conditions` id; it sets how likely a round jams. */
|
|
591
|
+
setCondition(id: string): void;
|
|
592
|
+
/** Quality of the rounds, by `rules.ammoQualities` id. */
|
|
593
|
+
setAmmoQuality(id: string): void;
|
|
594
|
+
/** Metres of safety fuse for explosives that burn one (dynamite): replaces the explosive's `fuseLength`; `undefined` goes back to it. */
|
|
595
|
+
setFuseLength(metres: number | undefined): void;
|
|
596
|
+
/** Start putting the weapon in hand; the trigger answers `drawing` until it is ready. */
|
|
597
|
+
draw(): void;
|
|
598
|
+
/**
|
|
599
|
+
* Start a reload; false when there is nothing to do. `auto` picks by the weapon (one by one when it loads that way, a magazine swap
|
|
600
|
+
* otherwise); `full` loads a revolver all at once (speed loader); `one_by_one` forces round by round.
|
|
601
|
+
*/
|
|
602
|
+
reload(kind?: ReloadRequest): boolean;
|
|
162
603
|
cycleMode(): FireMode;
|
|
163
604
|
/** Advance reload, cooldown and spread recovery. */
|
|
164
605
|
update(dt: number): void;
|
|
165
606
|
/** Fill the magazine and reserve (test rooms). */
|
|
166
607
|
refill(): void;
|
|
608
|
+
/** What happened since the last call (for animation and sound), in order of time; empties the list. */
|
|
609
|
+
drain(): WeaponEvent[];
|
|
167
610
|
}
|
|
611
|
+
/** Recursively optional; arrays and functions are replaced as a whole, objects are merged. */
|
|
612
|
+
type DeepPartial<TValue> = TValue extends (...args: never[]) => unknown ? TValue : TValue extends readonly unknown[] ? TValue : TValue extends object ? {
|
|
613
|
+
[TKey in keyof TValue]?: DeepPartial<TValue[TKey]>;
|
|
614
|
+
} : TValue;
|
|
615
|
+
/** Changes to a weapon def: `action`, `timings` and `dimensions` merge field by field, anything else replaces. */
|
|
616
|
+
type WeaponPatch = DeepPartial<Omit<WeaponDef, 'id'>>;
|
|
168
617
|
interface ArsenalOptions {
|
|
169
|
-
/** Extra or overriding calibres and
|
|
618
|
+
/** Extra or overriding calibres, weapons and explosives (merged by id over the ones the kit ships). */
|
|
170
619
|
calibers?: CaliberDef[];
|
|
171
620
|
weapons?: WeaponDef[];
|
|
621
|
+
explosives?: ExplosiveDef[];
|
|
622
|
+
/** Changes to shipped or added entries, by id, applied after the lists above are merged. */
|
|
623
|
+
patch?: {
|
|
624
|
+
weapons?: Record<WeaponId, WeaponPatch>;
|
|
625
|
+
calibers?: Record<CaliberId, Partial<CaliberDef>>;
|
|
626
|
+
explosives?: Record<ExplosiveId, Partial<ExplosiveDef>>;
|
|
627
|
+
};
|
|
628
|
+
/** Entries to leave out, by id. */
|
|
629
|
+
remove?: {
|
|
630
|
+
weapons?: WeaponId[];
|
|
631
|
+
calibers?: CaliberId[];
|
|
632
|
+
explosives?: ExplosiveId[];
|
|
633
|
+
};
|
|
634
|
+
/** Keeps a weapon only when this returns true (applied after `remove`). */
|
|
635
|
+
include?: (def: WeaponDef) => boolean;
|
|
636
|
+
/** Numbers that rule faults, heat, noise bursts and handling times. */
|
|
637
|
+
rules?: DeepPartial<WeaponRules>;
|
|
638
|
+
/** Replaces display names (merged over the locale). */
|
|
639
|
+
strings?: DeepPartial<WeaponsStrings>;
|
|
172
640
|
seed?: number;
|
|
173
641
|
locale?: string;
|
|
174
642
|
}
|
|
175
643
|
interface Arsenal {
|
|
176
644
|
readonly calibers: ReadonlyMap<CaliberId, CaliberDef>;
|
|
177
645
|
readonly weapons: ReadonlyMap<WeaponId, WeaponDef>;
|
|
646
|
+
readonly explosives: ReadonlyMap<ExplosiveId, ExplosiveDef>;
|
|
647
|
+
readonly rules: WeaponRules;
|
|
178
648
|
/** Make a runtime state for a weapon (each holder gets its own). Unknown id throws. */
|
|
179
649
|
create(id: WeaponId, options?: {
|
|
180
650
|
seed?: number;
|
|
181
651
|
reserve?: number;
|
|
652
|
+
condition?: string;
|
|
653
|
+
ammoQuality?: string;
|
|
182
654
|
}): WeaponState;
|
|
183
655
|
/** Muzzle energy of a calibre (optionally with a barrel factor). */
|
|
184
656
|
muzzleEnergy(caliber: CaliberId, barrel?: number): number;
|
|
185
|
-
/**
|
|
186
|
-
|
|
657
|
+
/** The explosive a `throw` or `place` use carries, ready to fly (`step`) or wait for its trigger; undefined when the use carries none. */
|
|
658
|
+
explosiveBody(use: Use): ExplosiveBody | undefined;
|
|
659
|
+
/** Joules of what one use of a weapon delivers: one projectile (or one pellet), a blast, or a melee blow. */
|
|
660
|
+
energy(id: WeaponId): number;
|
|
661
|
+
/** Translated name of a weapon, explosive, fire mode, category, fault, condition or calibre. */
|
|
662
|
+
name(id: string): string;
|
|
187
663
|
list(category?: WeaponCategory): WeaponDef[];
|
|
188
664
|
}
|
|
189
665
|
|
|
666
|
+
/** Deterministic mulberry32 generator; returns floats in [0, 1). */
|
|
667
|
+
declare const createRng: (seed: number) => (() => number);
|
|
668
|
+
|
|
669
|
+
interface ArsenalParts {
|
|
670
|
+
readonly weapons: ReadonlyMap<WeaponId, WeaponDef>;
|
|
671
|
+
readonly calibers: ReadonlyMap<CaliberId, CaliberDef>;
|
|
672
|
+
readonly explosives: ReadonlyMap<ExplosiveId, ExplosiveDef>;
|
|
673
|
+
/** When given, the default condition and ammunition quality must be ones the rules define. */
|
|
674
|
+
readonly rules?: Pick<WeaponRules, 'conditions' | 'defaultCondition' | 'ammoQualities' | 'defaultAmmoQuality'>;
|
|
675
|
+
}
|
|
676
|
+
/** Every problem found in an arsenal, so a game sees them all at once instead of one per run. Empty when it is consistent. */
|
|
677
|
+
declare const checkArsenal: ({ weapons, calibers, explosives, rules }: ArsenalParts) => string[];
|
|
678
|
+
|
|
190
679
|
/** Muzzle energy in joules of ONE projectile (a bullet, or one pellet): 0.5 × mass × speed², speed scaled by the barrel factor. */
|
|
191
680
|
declare const muzzleEnergy: (caliber: CaliberDef, barrel?: number) => number;
|
|
192
681
|
|
|
193
682
|
declare const CALIBERS: CaliberDef[];
|
|
683
|
+
declare const EXPLOSIVES: ExplosiveDef[];
|
|
684
|
+
declare const ARCHETYPE_IDS: readonly WeaponId[];
|
|
194
685
|
declare const WEAPONS: WeaponDef[];
|
|
195
686
|
/** A reasonable starting kit for a test room or a sandbox. */
|
|
196
687
|
declare const DEFAULT_LOADOUT: WeaponId[];
|
|
197
688
|
|
|
198
|
-
/**
|
|
689
|
+
/**
|
|
690
|
+
* Create an arsenal. Order: the shipped entries, then `calibers`/`weapons`/`explosives` (added or replaced by id), then `patch`, then `remove`, then `include`;
|
|
691
|
+
* a throwable that names an explosive follows that explosive. Every inconsistency found is reported in one error.
|
|
692
|
+
*/
|
|
199
693
|
declare const createArsenal: (options?: ArsenalOptions) => Arsenal;
|
|
200
694
|
|
|
201
|
-
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
|
|
695
|
+
/** The rules the kit ships with; a game overrides any of them through `ArsenalOptions.rules`. */
|
|
696
|
+
declare const DEFAULT_RULES: WeaponRules;
|
|
697
|
+
|
|
698
|
+
interface BlastEffect {
|
|
699
|
+
/** `lethal` kills and dismembers, `injury` wounds, `none` is out of reach (or behind a directional charge). */
|
|
700
|
+
readonly zone: 'lethal' | 'injury' | 'none';
|
|
701
|
+
readonly distance: number;
|
|
702
|
+
/** 1 in the lethal zone, falling linearly to 0 at the edge of the injury zone. */
|
|
703
|
+
readonly falloff: number;
|
|
704
|
+
/** Seconds of stun for whoever is in reach (flashbang). */
|
|
705
|
+
readonly stunSeconds: number;
|
|
210
706
|
}
|
|
211
|
-
|
|
212
|
-
declare const
|
|
707
|
+
/** What a detonation does to something at `target`: the zone, how hard, and the stun. A directional charge only reaches inside its cone. */
|
|
708
|
+
declare const blastEffect: (detonation: Detonation, target: Vec3) => BlastEffect;
|
|
709
|
+
/** How much of the blast behind a launcher reaches `target`: 0 outside the cone or the radius, falling linearly from 1 at the tube. */
|
|
710
|
+
declare const backblastEffect: (use: Extract<Use, {
|
|
711
|
+
kind: "backblast";
|
|
712
|
+
}>, target: Vec3) => number;
|
|
713
|
+
interface TripwireSegment {
|
|
714
|
+
readonly from: Vec3;
|
|
715
|
+
readonly to: Vec3;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Where the wire of a charge set down with `use` runs: from the charge, `length` metres along the horizontal facing turned by `angleDeg`
|
|
719
|
+
* (counter-clockwise seen from above), `height` metres above it. Null for a charge with no wire.
|
|
720
|
+
*/
|
|
721
|
+
declare const tripwireSegment: (use: Extract<Use, {
|
|
722
|
+
kind: "place";
|
|
723
|
+
}>) => TripwireSegment | null;
|
|
724
|
+
|
|
725
|
+
/** The fuse of an explosive with no randomness: a fixed `fuse`, the burn of a safety fuse (length times rate), or the middle of `fuseRange`. */
|
|
726
|
+
declare const nominalFuse: (explosive: ExplosiveDef, fuseLength?: number) => number | undefined;
|
|
727
|
+
/**
|
|
728
|
+
* The fuse of one throw. A safety fuse burns `fuseLength × burnRate` seconds, scattered by `burnTolerance` (a fraction, ±); `fuseRange` picks a time
|
|
729
|
+
* between its two ends; a fixed `fuse` is returned as is. Draws from `random` only when the explosive is not fixed, so fixed ones leave the stream alone.
|
|
730
|
+
*/
|
|
731
|
+
declare const sampleFuse: (explosive: ExplosiveDef, random: () => number, fuseLength?: number) => number | undefined;
|
|
732
|
+
|
|
733
|
+
type StageTable = Readonly<Record<ReloadKind, readonly ReloadStage[]>>;
|
|
734
|
+
/** Where each step of a reload falls, as a fraction of its duration, from the key frames of the gallery animations. The runtime scales them to the duration of the weapon. */
|
|
735
|
+
declare const RELOAD_STAGES: Readonly<Record<ReloadFamily, StageTable>>;
|
|
213
736
|
|
|
214
|
-
export { type Arsenal, type ArsenalOptions, CALIBERS, type CaliberDef, type CaliberId, DEFAULT_LOADOUT, type FireMode, type TriggerResult, WEAPONS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponId, type WeaponState, type WeaponsLocale, type WeaponsStrings, createArsenal, locales, muzzleEnergy, resolveStrings };
|
|
737
|
+
export { ARCHETYPE_IDS, type AmmoQualityDef, type Arsenal, type ArsenalOptions, type BlastEffect, CALIBERS, type CaliberDef, type CaliberId, type CartridgeDims, type CaseType, type ConditionDef, DEFAULT_LOADOUT, DEFAULT_RULES, type DataSource, type DeepPartial, type Detonation, EXPLOSIVES, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type SurfaceProbe, type TriggerResult, type TripwireSegment, WEAPONS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponDimensions, type WeaponEvent, type WeaponId, type WeaponPatch, type WeaponPhase, type WeaponRules, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, backblastEffect, blastEffect, checkArsenal, createArsenal, createExplosiveBody, createRng, locales, muzzleEnergy, nominalFuse, resolveStrings, sampleFuse, tripwireSegment };
|