@adatechnology/game-weapons 0.2.0 → 0.3.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 +48 -3
- package/dist/index.d.ts +314 -6
- package/dist/index.global.js +9526 -3535
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +9526 -3535
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -126,16 +126,61 @@ instead of thrown, which builds a delayed trap. `nominalFuse(explosive)` and `sa
|
|
|
126
126
|
An explosive with the `wire` trigger (the Claymore) carries `tripwire: { length, angleDeg?, height? }` (default `rules.explosives.tripwire`: 10 m ahead, 0.15 m above the charge, derived: no source
|
|
127
127
|
gives the length of the M18A1 kit). The `place` use has it, and `tripwireSegment(use)` gives the segment `{ from, to }` the host stretches and tests bodies against; when a body crosses it the host calls `body.trigger('wire')`.
|
|
128
128
|
|
|
129
|
+
## Accessories, stocks and aiming
|
|
130
|
+
|
|
131
|
+
`arsenal.attachments` is the catalogue of accessories (`data/attachments.json`, generated from the Arsenal §11 lines and `decisions.json`: suppressors, brakes, optics, grips, bipod, light, laser,
|
|
132
|
+
magazines, barrels, sling, ammunition backpack, tripod, grenade launchers). A weapon lists its places (`mounts`: muzzle, rails, underbarrel, magazine, barrel, sling, feed, each with the
|
|
133
|
+
interfaces it takes: `picatinny`, `ak_side`, `thread_14x1lh`...), what it ships with (`fitted`, already in the numbers of `action`; `integral: true` cannot come off) and its stock (`stock`:
|
|
134
|
+
`fixed`, `fold`, `retract`, `fold_retract`, `none`, and the `foldAxis`).
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
weapon.canFit('suppressor') // { ok: true, mount: 'muzzle' } | { ok: false, reason: 'no_mount' | 'interface' | 'caliber' | 'category' | 'occupied' | 'blocked' | 'rejected' }
|
|
138
|
+
weapon.fit('suppressor', { install: 'tool' }) // phase `fit` (rules.attachments.fitSeconds: field 2 s, tool 15 s, bench 30 s); counts when the phase ends; `trigger` answers `busy` meanwhile
|
|
139
|
+
weapon.remove('vertical_grip') // a factory part that is `integral` stays; what no longer fits in a smaller magazine goes back to the reserve
|
|
140
|
+
weapon.toggle('weapon_light') // lights and lasers count only while on (event `toggle`)
|
|
141
|
+
weapon.setStock('collapsed') // phase `stock` (rules.stock.seconds); then rules.stock.collapsed applies (draw ×0.8, aim ×0.85, vertical recoil ×1.3, spread ×1.15)
|
|
142
|
+
weapon.setStance({ aiming: true, supported: false })
|
|
143
|
+
weapon.aimSeconds // rules.aim.base + rules.aim.perKg × mass, with the effects (red dot ×0.8...)
|
|
144
|
+
const snapshot = weapon.snapshot(); arsenal.restore(snapshot, { seed })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Effects are `StatModifier`s (`stat`, then `set`, `add`, `mul`, with a condition: `always`, `aiming`, `hip`, `supported`, `subsonic`, `collapsed`): every `set` first, then the sum of the `add`s,
|
|
148
|
+
then the product of the `mul`s. A factory part is already in the numbers, so taking it off applies its inverse and putting it back returns the numbers of the def exactly. A bullet slower than
|
|
149
|
+
`rules.attachments.speedOfSound` (343 m/s) is subsonic, which a suppressor mutes more (×0.25 in all). A suppressed pull sets `TriggerResult.suppressed` (and on the `shot` event): pass it to the shot sound.
|
|
150
|
+
A home-made suppressor breaks at a shot drawn in `durability.shots` from a stream of its own (`seed ^ 0x3c6ef372`), so spreads and faults do not move (event `attachment`, `action: 'break'`).
|
|
151
|
+
`ArsenalOptions` gains `attachments`, `patch.attachments`, `remove.attachments` and `isCompatible(def, attachment, fitted)` (a game vetoes an accessory); `canFit(def, attachment, fitted, context, mount?)` is exported.
|
|
152
|
+
|
|
153
|
+
**A launcher under the barrel.** `m203` (M16, M4), `gp_25` (AK-47, AKM, AK-74 and AK-12 only: the SKS has a bayonet lug but not the GP-25 mount) and `ag36` (HK416) are accessories whose `launcher` names a weapon of the
|
|
154
|
+
catalogue (`category: 'launcher'`, `tags: ['underbarrel']`, family `underbarrel`: breech open, grenade in, breech close). Fitting one gives the weapon a second state, `weapon.underbarrel`, with its own
|
|
155
|
+
ammunition (the M79 launcher rule: one grenade, `launcherUses`, explosive `m79_40mm`, or `vog_25` for the GP-25, which has the same radii). `useUnderbarrel(true)` takes `rules.attachments.switchSeconds` (0.8 s,
|
|
156
|
+
phase `switch`, event `underbarrel`); while it is on, `trigger` and `reload` go to the launcher and `drain()` carries its events too. The launcher covers the lower rail (`blocks: ['rail_bottom']`).
|
|
157
|
+
`snapshot()` carries the launcher's snapshot. A shipped launcher accessory leaves the arsenal when its launcher weapon is removed or filtered out.
|
|
158
|
+
|
|
159
|
+
**Weapons beyond the team pages.** 21 more firearms come from `decisions.creations` of the catalogue tool, each number with its `source` and `reason` (a reference always with a URL): `hk_mp5sd3`, `fn_parafal`,
|
|
160
|
+
`taurus_t4_civil`, `taurus_th380`, `mossberg_500_cruiser`, `hk_mp5k`, `hk_ump9`, `mini_uzi`, `hk_mp7a1`, `hk_g36` (`k`, `c`), `fn_m249`, `fn_minimi_para`, `fn_mag`, `rpk`, `sig_mpx`, `mg3`, `pp19_bizon`, `vz61`
|
|
161
|
+
and `m134`, and the calibres `4_6x30` and `32acp`. The MP5SD3 ships with an integral suppressor (its noise and speed are the suppressed ones; the subsonic factor is already in its base numbers) and the G36 and
|
|
162
|
+
G36K with an integral 3x optic; neither comes off. The M134 is a rotary gun with three modes: hand-held with a 200 round belt box, with the ammunition backpack (500, see above) or on the `tripod` mount
|
|
163
|
+
(supported). `action.rpmRange` (`[2000, 6000]`) bounds the rate a game may set with `patch.weapons.m134.action.rpm` (3000 by default) and `action.spin` (`{ upSeconds: 0.5, holdSeconds: 1 }`, derived) delays the
|
|
164
|
+
first round of a pull until the barrels are at speed and keeps them spinning for a second after the last round (hold the trigger with `held`).
|
|
165
|
+
|
|
166
|
+
The hip: `rules.aim.hipSpread` times the spread when not aiming. The SDK default is **1** (neutral); the Arsenal says ×6 (§08) and ZombiAdA turns it on with `rules: { aim: { hipSpread: 6 } }`. A laser takes
|
|
167
|
+
half of the excess (`hipSpreadExcess` ×0.5). The ammunition backpack (`feed` mount, `belt`) sets the capacity to 500 rounds by default (`patch.attachments.ammo_backpack`); a tripod counts as support.
|
|
168
|
+
|
|
169
|
+
**In the weapons test area** (`@adatechnology/game-weapons-three`): L, K, V and U work the light, the laser, the stock and the launcher; the **right mouse button aims** with a firearm in hand (the camera zooms by the
|
|
170
|
+
optic that is fitted over `aimSeconds`), and only when the click lands on the room's canvas or the pointer is locked: a click on a panel, an input or an overlay is never taken, and a tool that does not fire (the hand,
|
|
171
|
+
a throwable) leaves the button to the room, which grabs with it. The bench's **Supported** switch (`supported_stance`) puts the weapon in the supported stance (deployed or prone), so the bipod effect can be exercised;
|
|
172
|
+
it goes back off when another tool is taken. The laser measures its distance at most 30 times a second and ignores hidden nodes (a hidden ancestor counts) and the weapon in the hands.
|
|
173
|
+
|
|
129
174
|
## API
|
|
130
175
|
|
|
131
|
-
- `createArsenal(options?)` returns an `Arsenal`: `calibers`, `weapons`, `explosives` (maps), `rules`, `create(id, { seed?, reserve?, condition?, ammoQuality? })` (unknown id throws),
|
|
176
|
+
- `createArsenal(options?)` returns an `Arsenal`: `calibers`, `weapons`, `explosives` (maps), `rules`, `create(id, { seed?, reserve?, condition?, ammoQuality? })` (unknown id throws), `attachments`, `canFit(weapon, attachment, options?)`, `restore(snapshot, options?)`,
|
|
132
177
|
`muzzleEnergy(caliberId, barrel?)`, `energy(weaponId)`, `name(id)` (weapon, explosive, fire mode, category, fault, condition or calibre, translated), `list(category?)`.
|
|
133
178
|
Options: `calibers`, `weapons`, `explosives`, `patch`, `remove`, `include`, `rules`, `strings`, `seed`, `locale`.
|
|
134
179
|
- `WeaponState`: `def`, `caliber`, `ammo`, `capacity`, `reserve`, `mode`, `reloading`, `locked`, `phase`, `fault`, `clearing`, `safety`, `heat`, `heatLevel`, `condition`,
|
|
135
180
|
`ammoQuality`, `spread`, `trigger(origin, direction, dt, held?, source?)`, `release(origin?, direction?)`, `draw()`, `reload(kind?)`, `cycleMode()`, `setSafety(on)`, `clearFault()`,
|
|
136
|
-
`setCondition(id)`, `setAmmoQuality(id)`, `setFuseLength(metres)`, `cooking`, `update(dt)`, `refill()`, `drain()`. `release(origin?, direction?)` returns the throw of a cooked grenade (null for anything else).
|
|
181
|
+
`setCondition(id)`, `setAmmoQuality(id)`, `setFuseLength(metres)`, `cooking`, `attachments`, `mass`, `aimSeconds`, `suppressed`, `stock`, `canFit`, `fit`, `remove`, `toggle`, `setStock`, `setStance`, `snapshot`, `update(dt)`, `refill()`, `drain()`. `release(origin?, direction?)` returns the throw of a cooked grenade (null for anything else).
|
|
137
182
|
- `Shot`: `origin`, `direction`, `energy` (J), `caliber` (mm), `caliberId`, `speed`, `energyAt(distance)` (energy × speed factor², drag per 100 m), `pellet`, `weapon`, `source`.
|
|
138
|
-
- `Use`: `melee`, `flame`, `heat`, `throw`, `tool`, `extinguish`, `hand`. `TriggerResult`: `shots`, `uses`, `status` (`ok`, `empty`, `reloading`, `cooldown`, `no_fuel`, `safe`, `drawing`, `fault`, `misfire`, `clearing`), `recoil`, `noise`, `rounds`, `roundTimes`, `fault?`.
|
|
183
|
+
- `Use`: `melee`, `flame`, `heat`, `throw`, `tool`, `extinguish`, `hand`. `TriggerResult`: `shots`, `uses`, `status` (`ok`, `empty`, `reloading`, `cooldown`, `no_fuel`, `safe`, `drawing`, `fault`, `misfire`, `clearing`, `busy`), `recoil`, `noise`, `rounds`, `roundTimes`, `fault?`, `suppressed?`.
|
|
139
184
|
- `muzzleEnergy(caliber, barrel?)`, `CALIBERS`, `WEAPONS`, `EXPLOSIVES`, `ARCHETYPE_IDS`, `DEFAULT_LOADOUT`, `DEFAULT_RULES`, `RELOAD_STAGES`, `checkArsenal`, `locales`, `resolveStrings`.
|
|
140
185
|
|
|
141
186
|
Locales: `en` and `pt-BR` (`locale` option; unknown falls back to `en`). Calibre labels are technical names and are not translated.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,150 @@
|
|
|
1
1
|
import { Vec3, Use, ExplosionChain, Shot } from '@adatechnology/game-contracts';
|
|
2
2
|
export { Shot, Use, Vec3 } from '@adatechnology/game-contracts';
|
|
3
3
|
|
|
4
|
+
type AttachmentId = string;
|
|
5
|
+
/** Where on a weapon something goes. */
|
|
6
|
+
type MountKind = 'muzzle' | 'rail_top' | 'rail_bottom' | 'rail_left' | 'rail_right' | 'underbarrel' | 'magazine' | 'stock' | 'barrel' | 'sling' | 'feed';
|
|
7
|
+
/**
|
|
8
|
+
* A place on a weapon an accessory can take. `interfaces` is what the place accepts: `picatinny`, `mlok`, `ak_side`, `dovetail`, `thread_1/2x28`, `thread_5/8x24`,
|
|
9
|
+
* `thread_14x1lh`, `thread_24x1.5`, `hk_3lug`, `m203`, `gp25`, `ag36`, `mag_<family>`, `buffer_tube`, `swivel`, `belt`, `tripod`.
|
|
10
|
+
*/
|
|
11
|
+
interface MountDef {
|
|
12
|
+
readonly kind: MountKind;
|
|
13
|
+
readonly interfaces: readonly string[];
|
|
14
|
+
/** Metres of rail or free length at the place. */
|
|
15
|
+
readonly length?: number;
|
|
16
|
+
readonly sources: readonly DataSource[];
|
|
17
|
+
}
|
|
18
|
+
/** What an accessory changes on the weapon it is on. */
|
|
19
|
+
type WeaponStat = 'noise' | 'spread' | 'hipSpreadExcess' | 'recoilVertical' | 'recoilHorizontal' | 'range' | 'muzzleSpeed' | 'mass' | 'capacity' | 'reload' | 'reloadEmpty' | 'draw' | 'aim' | 'faultChance' | 'heatPerShot';
|
|
20
|
+
/** When an effect counts: `supported` is lying down or on a bipod or tripod, `subsonic` the bullet is slower than sound, `collapsed` the stock is folded. */
|
|
21
|
+
type EffectCondition = 'always' | 'aiming' | 'hip' | 'supported' | 'subsonic' | 'collapsed';
|
|
22
|
+
/** One change of one number: every `set` first, then the sum of the `add`s, then the product of the `mul`s. */
|
|
23
|
+
interface StatModifier {
|
|
24
|
+
readonly stat: WeaponStat;
|
|
25
|
+
readonly mul?: number;
|
|
26
|
+
readonly add?: number;
|
|
27
|
+
readonly set?: number;
|
|
28
|
+
readonly when?: EffectCondition;
|
|
29
|
+
}
|
|
30
|
+
type AttachmentKind = 'suppressor' | 'muzzle_device' | 'optic' | 'light' | 'laser' | 'grip' | 'bipod' | 'underbarrel' | 'magazine' | 'stock' | 'barrel' | 'sling' | 'feed' | 'mount';
|
|
31
|
+
type AttachmentInstall = 'field' | 'tool' | 'bench';
|
|
32
|
+
interface AttachmentDef {
|
|
33
|
+
readonly id: AttachmentId;
|
|
34
|
+
/** Generic real-world description used as the default name. */
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
readonly kind: AttachmentKind;
|
|
37
|
+
/** The places it can take. */
|
|
38
|
+
readonly mounts: readonly MountKind[];
|
|
39
|
+
/** The interfaces it fits (one of them must be on the mount). */
|
|
40
|
+
readonly interfaces: readonly string[];
|
|
41
|
+
/** Places that stop being usable while it is on (a grenade launcher takes the lower rail). */
|
|
42
|
+
readonly blocks?: readonly MountKind[];
|
|
43
|
+
/** A suppressor takes calibres up to a diameter and an energy; `ids` limits it to named calibres. */
|
|
44
|
+
readonly calibers?: {
|
|
45
|
+
readonly maxDiameter?: number;
|
|
46
|
+
readonly maxEnergy?: number;
|
|
47
|
+
readonly ids?: readonly CaliberId[];
|
|
48
|
+
};
|
|
49
|
+
readonly categories?: readonly WeaponCategory[];
|
|
50
|
+
/** Kg. */
|
|
51
|
+
readonly mass: number;
|
|
52
|
+
/** Metres. */
|
|
53
|
+
readonly dims?: {
|
|
54
|
+
readonly length: number;
|
|
55
|
+
readonly diameter?: number;
|
|
56
|
+
readonly width?: number;
|
|
57
|
+
readonly height?: number;
|
|
58
|
+
};
|
|
59
|
+
/** Where it can be put on: in the field with the hands, with a tool, or only at a bench. */
|
|
60
|
+
readonly install: AttachmentInstall;
|
|
61
|
+
readonly removable?: boolean;
|
|
62
|
+
readonly effects: readonly StatModifier[];
|
|
63
|
+
readonly optic?: {
|
|
64
|
+
readonly zoom: readonly [number, number];
|
|
65
|
+
readonly reticle: 'dot' | 'holo' | 'chevron' | 'duplex' | 'mildot';
|
|
66
|
+
readonly vision?: 'day' | 'night' | 'thermal';
|
|
67
|
+
readonly batteryHours?: number;
|
|
68
|
+
};
|
|
69
|
+
readonly light?: {
|
|
70
|
+
readonly coneDeg: number;
|
|
71
|
+
readonly range: number;
|
|
72
|
+
readonly visibleFrom: number;
|
|
73
|
+
readonly batteryHours?: number;
|
|
74
|
+
};
|
|
75
|
+
readonly laser?: {
|
|
76
|
+
readonly color: number;
|
|
77
|
+
readonly range: number;
|
|
78
|
+
readonly visibleFrom: number;
|
|
79
|
+
};
|
|
80
|
+
/** The weapon a grenade launcher accessory is. */
|
|
81
|
+
readonly launcher?: WeaponId;
|
|
82
|
+
/** Shots until it breaks, between the two numbers (a home-made suppressor). */
|
|
83
|
+
readonly durability?: {
|
|
84
|
+
readonly shots: readonly [number, number];
|
|
85
|
+
};
|
|
86
|
+
/** Carried on the back (an ammunition backpack). */
|
|
87
|
+
readonly carry?: 'back';
|
|
88
|
+
/** Can be slung, which lets the weapon be stowed on the body (a sling). */
|
|
89
|
+
readonly stowable?: boolean;
|
|
90
|
+
/** The effects count on every second reload only: the spare magazine is already coupled (a dual coupler). */
|
|
91
|
+
readonly secondReload?: boolean;
|
|
92
|
+
/** Name of the model the renderer draws it with. */
|
|
93
|
+
readonly model: string;
|
|
94
|
+
readonly sources: readonly DataSource[];
|
|
95
|
+
}
|
|
96
|
+
/** An accessory on a weapon: the place it is in, whether it came with the weapon (`integral`) and, for a light or a laser, whether it is on. */
|
|
97
|
+
interface FittedAttachment {
|
|
98
|
+
readonly id: AttachmentId;
|
|
99
|
+
readonly mount: MountKind;
|
|
100
|
+
readonly integral?: boolean;
|
|
101
|
+
readonly on?: boolean;
|
|
102
|
+
/** Shots until a home-made accessory breaks (drawn when it goes on). */
|
|
103
|
+
readonly shotsLeft?: number;
|
|
104
|
+
}
|
|
105
|
+
type StockState = 'collapsed' | 'extended';
|
|
106
|
+
/** What the stock of a weapon does: `fold` swings to a side, `retract` slides in, `none` has no shoulder piece. */
|
|
107
|
+
interface StockDef {
|
|
108
|
+
readonly kind: 'fixed' | 'fold' | 'retract' | 'fold_retract' | 'none';
|
|
109
|
+
readonly foldAxis?: 'right' | 'left' | 'under' | 'over';
|
|
110
|
+
}
|
|
111
|
+
/** What `snapshot()` gives and `arsenal.restore()` takes: enough to rebuild a weapon exactly as it was (the random streams restart from the seed given). */
|
|
112
|
+
interface WeaponSnapshot {
|
|
113
|
+
readonly id: WeaponId;
|
|
114
|
+
readonly attachments: readonly FittedAttachment[];
|
|
115
|
+
readonly stock: StockState;
|
|
116
|
+
readonly ammo: number;
|
|
117
|
+
readonly reserve: number;
|
|
118
|
+
readonly mode: FireMode;
|
|
119
|
+
readonly condition: string;
|
|
120
|
+
readonly ammoQuality: string;
|
|
121
|
+
readonly underbarrel?: WeaponSnapshot;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type FitRefusal = 'no_mount' | 'interface' | 'caliber' | 'category' | 'occupied' | 'blocked' | 'rejected';
|
|
125
|
+
type CanFit = {
|
|
126
|
+
readonly ok: true;
|
|
127
|
+
readonly mount: MountKind;
|
|
128
|
+
} | {
|
|
129
|
+
readonly ok: false;
|
|
130
|
+
readonly reason: FitRefusal;
|
|
131
|
+
};
|
|
132
|
+
/** What a game adds to the rule: false keeps the accessory off the weapon whatever the mounts say. */
|
|
133
|
+
type IsCompatible = (def: WeaponDef, attachment: AttachmentDef, fitted: readonly FittedAttachment[]) => boolean;
|
|
134
|
+
interface CanFitContext {
|
|
135
|
+
readonly caliber: CaliberDef | null;
|
|
136
|
+
readonly catalogue: ReadonlyMap<string, AttachmentDef>;
|
|
137
|
+
readonly isCompatible?: IsCompatible;
|
|
138
|
+
}
|
|
139
|
+
/** Whether what is at hand (`field`: the hands, `tool`: a tool, `bench`: a bench) is enough to put the accessory on or take it off. */
|
|
140
|
+
declare const canInstallWith: (available: AttachmentInstall, needed: AttachmentInstall) => boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the accessory goes on the weapon, and where. Order of the checks: a place of its kind (`no_mount`), an interface the place takes
|
|
143
|
+
* (`interface`), the calibre limits of a suppressor (`caliber`), the weapon categories (`category`), the place being free (`occupied`),
|
|
144
|
+
* something else covering it (`blocked`), then the game's own `isCompatible` (`rejected`).
|
|
145
|
+
*/
|
|
146
|
+
declare const canFit: (def: WeaponDef, attachment: AttachmentDef, fitted: readonly FittedAttachment[], context: CanFitContext, mount?: MountKind) => CanFit;
|
|
147
|
+
|
|
4
148
|
/** Everything a host needs to apply a blast: where, how big, in which direction, and what else it does. */
|
|
5
149
|
interface Detonation {
|
|
6
150
|
readonly explosive: ExplosiveId;
|
|
@@ -232,6 +376,26 @@ interface WeaponRules {
|
|
|
232
376
|
/** The wire of a charge set down with the `wire` trigger that does not name one. */
|
|
233
377
|
readonly tripwire: Required<ExplosiveTripwire>;
|
|
234
378
|
};
|
|
379
|
+
/** Putting accessories on and taking them off. */
|
|
380
|
+
readonly attachments: {
|
|
381
|
+
/** Seconds the work takes, by where it can be done: with the hands, with a tool, at a bench. */
|
|
382
|
+
readonly fitSeconds: Readonly<Record<AttachmentInstall, number>>;
|
|
383
|
+
/** Seconds to change between the weapon and the launcher under its barrel. */
|
|
384
|
+
readonly switchSeconds: number;
|
|
385
|
+
/** m/s: a bullet slower than this is subsonic (a suppressor mutes it more). */
|
|
386
|
+
readonly speedOfSound: number;
|
|
387
|
+
};
|
|
388
|
+
/** Time to raise the weapon to the sights (`base` + `perKg` × mass) and how much worse the hip is: `hipSpread` times the spread when not aiming (1: no difference). */
|
|
389
|
+
readonly aim: {
|
|
390
|
+
readonly base: number;
|
|
391
|
+
readonly perKg: number;
|
|
392
|
+
readonly hipSpread: number;
|
|
393
|
+
};
|
|
394
|
+
/** Folding or sliding in the stock: the seconds it takes and what it does to the weapon while it is in. */
|
|
395
|
+
readonly stock: {
|
|
396
|
+
readonly seconds: number;
|
|
397
|
+
readonly collapsed: readonly StatModifier[];
|
|
398
|
+
};
|
|
235
399
|
readonly draw: number;
|
|
236
400
|
readonly clear: number;
|
|
237
401
|
readonly startSafe: boolean;
|
|
@@ -254,6 +418,7 @@ type WeaponEvent = {
|
|
|
254
418
|
rounds: number;
|
|
255
419
|
mode: FireMode;
|
|
256
420
|
at: number;
|
|
421
|
+
suppressed?: boolean;
|
|
257
422
|
} | {
|
|
258
423
|
type: 'misfire';
|
|
259
424
|
at: number;
|
|
@@ -300,6 +465,34 @@ type WeaponEvent = {
|
|
|
300
465
|
phase: 'start' | 'throw' | 'burst';
|
|
301
466
|
fuse: number;
|
|
302
467
|
at: number;
|
|
468
|
+
}
|
|
469
|
+
/** An accessory goes on (`fit`), comes off (`remove`) or breaks (`break`, a home-made suppressor). `mount` is where it was. */
|
|
470
|
+
| {
|
|
471
|
+
type: 'attachment';
|
|
472
|
+
action: 'fit' | 'remove' | 'break';
|
|
473
|
+
id: AttachmentId;
|
|
474
|
+
mount: MountKind;
|
|
475
|
+
at: number;
|
|
476
|
+
}
|
|
477
|
+
/** A light or a laser is turned on or off. */
|
|
478
|
+
| {
|
|
479
|
+
type: 'toggle';
|
|
480
|
+
id: AttachmentId;
|
|
481
|
+
on: boolean;
|
|
482
|
+
at: number;
|
|
483
|
+
}
|
|
484
|
+
/** The stock is folded or slid in (`collapsed`) or opened (`extended`). */
|
|
485
|
+
| {
|
|
486
|
+
type: 'stock';
|
|
487
|
+
state: StockState;
|
|
488
|
+
kind: StockDef['kind'];
|
|
489
|
+
at: number;
|
|
490
|
+
}
|
|
491
|
+
/** The weapon in the hand changes between the rifle and the launcher under its barrel. */
|
|
492
|
+
| {
|
|
493
|
+
type: 'underbarrel';
|
|
494
|
+
on: boolean;
|
|
495
|
+
at: number;
|
|
303
496
|
};
|
|
304
497
|
|
|
305
498
|
/**
|
|
@@ -360,7 +553,7 @@ type FirearmAction = Extract<WeaponAction, {
|
|
|
360
553
|
type FireMode = 'single' | 'semi' | 'burst' | 'auto' | 'pump' | 'bolt' | 'lever' | 'break' | 'volley';
|
|
361
554
|
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
555
|
/** 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';
|
|
556
|
+
type ReloadFamily = 'pistol' | 'magazine' | 'top_magazine' | 'top_load_semi' | 'tube_semi' | 'pump' | 'lever' | 'bolt' | 'bolt_magazine' | 'belt' | 'revolver' | 'break' | 'rocket' | 'underbarrel' | 'flame';
|
|
364
557
|
/** Seconds of each phase of handling a weapon. */
|
|
365
558
|
interface WeaponTimings {
|
|
366
559
|
readonly draw: number;
|
|
@@ -420,6 +613,13 @@ type WeaponAction = {
|
|
|
420
613
|
tubes?: number;
|
|
421
614
|
/** Multiplies the fault chance (1 = average, below 1 more reliable). */
|
|
422
615
|
faultFactor?: number;
|
|
616
|
+
/** A rotary gun: seconds the barrels need to reach speed before the first round of a pull, and how long they keep spinning after the last one. */
|
|
617
|
+
spin?: {
|
|
618
|
+
readonly upSeconds: number;
|
|
619
|
+
readonly holdSeconds: number;
|
|
620
|
+
};
|
|
621
|
+
/** The cyclic rates a rotary gun can be set to; `rpm` is the default and a `patch` may change it inside this range. */
|
|
622
|
+
rpmRange?: readonly [number, number];
|
|
423
623
|
/** Real accuracy in minutes of angle (data only). */
|
|
424
624
|
moa?: number;
|
|
425
625
|
/** Shotgun pattern width at 25 m in centimetres (data only). */
|
|
@@ -432,7 +632,7 @@ type WeaponAction = {
|
|
|
432
632
|
magazine: number;
|
|
433
633
|
reload: number;
|
|
434
634
|
timings?: WeaponTimings;
|
|
435
|
-
family: 'rocket' | 'break';
|
|
635
|
+
family: 'rocket' | 'break' | 'underbarrel';
|
|
436
636
|
disposable?: boolean;
|
|
437
637
|
speed: number;
|
|
438
638
|
/** Distance in metres below which the projectile hits without exploding. */
|
|
@@ -516,6 +716,12 @@ interface WeaponDef {
|
|
|
516
716
|
archetype?: WeaponId;
|
|
517
717
|
/** The weapon this one is a variant of. */
|
|
518
718
|
variantOf?: WeaponId;
|
|
719
|
+
/** The places an accessory can go on this weapon. */
|
|
720
|
+
mounts?: readonly MountDef[];
|
|
721
|
+
/** The accessories the weapon comes with; their effects are already in the numbers of `action`. */
|
|
722
|
+
fitted?: readonly FittedAttachment[];
|
|
723
|
+
/** What the stock does (fold, retract); absent: a fixed stock or none. */
|
|
724
|
+
stock?: StockDef;
|
|
519
725
|
sources?: readonly DataSource[];
|
|
520
726
|
}
|
|
521
727
|
interface TriggerResult {
|
|
@@ -524,11 +730,13 @@ interface TriggerResult {
|
|
|
524
730
|
/** Uses this call (everything else). */
|
|
525
731
|
uses: Use[];
|
|
526
732
|
/** `ok`, or why nothing happened. */
|
|
527
|
-
status: 'ok' | 'empty' | 'reloading' | 'cooldown' | 'no_fuel' | 'safe' | 'drawing' | 'fault' | 'misfire' | 'clearing';
|
|
733
|
+
status: 'ok' | 'empty' | 'reloading' | 'cooldown' | 'no_fuel' | 'safe' | 'drawing' | 'fault' | 'misfire' | 'clearing' | 'busy';
|
|
528
734
|
/** Camera kick to apply, degrees [pitch, yaw]. */
|
|
529
735
|
recoil: [number, number];
|
|
530
736
|
/** Audible radius of what happened, metres (0 when nothing). */
|
|
531
737
|
noise: number;
|
|
738
|
+
/** True when a suppressor was on for the shots of this call (the host passes it to the shot sound). */
|
|
739
|
+
suppressed?: boolean;
|
|
532
740
|
/** Cartridges spent by this call: a shotgun shell is one, a burst is several. */
|
|
533
741
|
rounds: number;
|
|
534
742
|
/** Seconds after the start of the call at which each round left the barrel. */
|
|
@@ -539,10 +747,29 @@ interface TriggerResult {
|
|
|
539
747
|
type ReloadRequest = 'auto' | 'full' | 'one_by_one';
|
|
540
748
|
/** What the weapon is busy with right now, and between which seconds of its own clock. */
|
|
541
749
|
interface WeaponPhase {
|
|
542
|
-
readonly id: 'draw' | 'cycle' | 'reload' | 'clear' | 'mode';
|
|
750
|
+
readonly id: 'draw' | 'cycle' | 'reload' | 'clear' | 'mode' | 'fit' | 'stock' | 'switch';
|
|
543
751
|
readonly start: number;
|
|
544
752
|
readonly end: number;
|
|
545
753
|
}
|
|
754
|
+
/** What the hands have to put an accessory on (`install`) and where, when it fits on more than one place (`mount`). */
|
|
755
|
+
interface FitOptions {
|
|
756
|
+
readonly install?: AttachmentInstall;
|
|
757
|
+
readonly mount?: MountKind;
|
|
758
|
+
}
|
|
759
|
+
/** Whether the work started, with the seconds it takes (the phase `fit`), or why not. */
|
|
760
|
+
type FitResult = {
|
|
761
|
+
readonly ok: true;
|
|
762
|
+
readonly seconds: number;
|
|
763
|
+
} | {
|
|
764
|
+
readonly ok: false;
|
|
765
|
+
readonly reason: FitRefusal | 'busy' | 'unknown' | 'install' | 'fixed' | 'not_fitted';
|
|
766
|
+
};
|
|
767
|
+
/** How the weapon is held: it decides which conditional effects count. */
|
|
768
|
+
interface WeaponStance {
|
|
769
|
+
readonly aiming?: boolean;
|
|
770
|
+
/** Lying down, or on a bipod or tripod. */
|
|
771
|
+
readonly supported?: boolean;
|
|
772
|
+
}
|
|
546
773
|
interface WeaponState {
|
|
547
774
|
readonly def: WeaponDef;
|
|
548
775
|
readonly caliber: CaliberDef | null;
|
|
@@ -605,6 +832,34 @@ interface WeaponState {
|
|
|
605
832
|
update(dt: number): void;
|
|
606
833
|
/** Fill the magazine and reserve (test rooms). */
|
|
607
834
|
refill(): void;
|
|
835
|
+
/** What is on the weapon, factory parts included. */
|
|
836
|
+
readonly attachments: readonly FittedAttachment[];
|
|
837
|
+
/** Kg: the weapon with what is on it. */
|
|
838
|
+
readonly mass: number;
|
|
839
|
+
/** Seconds to raise the weapon to the sights: `rules.aim.base` + `perKg` × mass, with the effects of the accessories. */
|
|
840
|
+
readonly aimSeconds: number;
|
|
841
|
+
/** True while a suppressor is on: shots carry `suppressed` and the noise already counts it. */
|
|
842
|
+
readonly suppressed: boolean;
|
|
843
|
+
readonly stock: StockState;
|
|
844
|
+
/** Whether the accessory goes on, and where, with what is on the weapon now. */
|
|
845
|
+
canFit(id: AttachmentId, mount?: MountKind): CanFit;
|
|
846
|
+
/** Starts putting an accessory on (phase `fit`, `rules.attachments.fitSeconds` by where it installs); it counts when the phase ends. */
|
|
847
|
+
fit(id: AttachmentId, options?: FitOptions): FitResult;
|
|
848
|
+
/** Starts taking an accessory off; a factory part that is `integral` stays. Sobra de cartuchos de um carregador maior volta à reserva. */
|
|
849
|
+
remove(id: AttachmentId, options?: FitOptions): FitResult;
|
|
850
|
+
/** Turns a light or a laser on or off; returns the state it is in now, or null when the accessory is not a light or a laser on the weapon. */
|
|
851
|
+
toggle(id: AttachmentId): boolean | null;
|
|
852
|
+
/** Folds or slides the stock in or opens it (phase `stock`); false when the weapon has no such stock or it is already there. */
|
|
853
|
+
setStock(state: StockState): boolean;
|
|
854
|
+
setStance(stance: WeaponStance): void;
|
|
855
|
+
/** The launcher under the barrel (a second state with its own ammunition), or null when no launcher is fitted. */
|
|
856
|
+
readonly underbarrel: WeaponState | null;
|
|
857
|
+
/** True while the trigger and the reload go to the launcher. */
|
|
858
|
+
readonly underbarrelActive: boolean;
|
|
859
|
+
/** Changes between the weapon and the launcher under its barrel (phase `switch`, `rules.attachments.switchSeconds`); false when there is none, it is already so, or the weapon is busy. */
|
|
860
|
+
useUnderbarrel(on: boolean): boolean;
|
|
861
|
+
/** Enough to rebuild the weapon as it is (`arsenal.restore`). */
|
|
862
|
+
snapshot(): WeaponSnapshot;
|
|
608
863
|
/** What happened since the last call (for animation and sound), in order of time; empties the list. */
|
|
609
864
|
drain(): WeaponEvent[];
|
|
610
865
|
}
|
|
@@ -624,15 +879,21 @@ interface ArsenalOptions {
|
|
|
624
879
|
weapons?: Record<WeaponId, WeaponPatch>;
|
|
625
880
|
calibers?: Record<CaliberId, Partial<CaliberDef>>;
|
|
626
881
|
explosives?: Record<ExplosiveId, Partial<ExplosiveDef>>;
|
|
882
|
+
attachments?: Record<AttachmentId, DeepPartial<AttachmentDef>>;
|
|
627
883
|
};
|
|
628
884
|
/** Entries to leave out, by id. */
|
|
629
885
|
remove?: {
|
|
630
886
|
weapons?: WeaponId[];
|
|
631
887
|
calibers?: CaliberId[];
|
|
632
888
|
explosives?: ExplosiveId[];
|
|
889
|
+
attachments?: AttachmentId[];
|
|
633
890
|
};
|
|
634
891
|
/** Keeps a weapon only when this returns true (applied after `remove`). */
|
|
635
892
|
include?: (def: WeaponDef) => boolean;
|
|
893
|
+
/** Added or replaced accessories (merged by id over the ones the kit ships). */
|
|
894
|
+
attachments?: AttachmentDef[];
|
|
895
|
+
/** Keeps an accessory off a weapon whatever its mounts say (applied after the mounts and calibre checks). */
|
|
896
|
+
isCompatible?: IsCompatible;
|
|
636
897
|
/** Numbers that rule faults, heat, noise bursts and handling times. */
|
|
637
898
|
rules?: DeepPartial<WeaponRules>;
|
|
638
899
|
/** Replaces display names (merged over the locale). */
|
|
@@ -644,7 +905,17 @@ interface Arsenal {
|
|
|
644
905
|
readonly calibers: ReadonlyMap<CaliberId, CaliberDef>;
|
|
645
906
|
readonly weapons: ReadonlyMap<WeaponId, WeaponDef>;
|
|
646
907
|
readonly explosives: ReadonlyMap<ExplosiveId, ExplosiveDef>;
|
|
908
|
+
readonly attachments: ReadonlyMap<AttachmentId, AttachmentDef>;
|
|
647
909
|
readonly rules: WeaponRules;
|
|
910
|
+
/** Whether an accessory goes on a weapon with the given parts on it (a weapon as it ships when `fitted` is left out), and where. */
|
|
911
|
+
canFit(weapon: WeaponId, attachment: AttachmentId, options?: {
|
|
912
|
+
fitted?: readonly FittedAttachment[];
|
|
913
|
+
mount?: MountKind;
|
|
914
|
+
}): CanFit;
|
|
915
|
+
/** Rebuilds a weapon from `WeaponState.snapshot()`; the random streams start again from `seed`. */
|
|
916
|
+
restore(snapshot: WeaponSnapshot, options?: {
|
|
917
|
+
seed?: number;
|
|
918
|
+
}): WeaponState;
|
|
648
919
|
/** Make a runtime state for a weapon (each holder gets its own). Unknown id throws. */
|
|
649
920
|
create(id: WeaponId, options?: {
|
|
650
921
|
seed?: number;
|
|
@@ -670,16 +941,53 @@ interface ArsenalParts {
|
|
|
670
941
|
readonly weapons: ReadonlyMap<WeaponId, WeaponDef>;
|
|
671
942
|
readonly calibers: ReadonlyMap<CaliberId, CaliberDef>;
|
|
672
943
|
readonly explosives: ReadonlyMap<ExplosiveId, ExplosiveDef>;
|
|
944
|
+
readonly attachments?: ReadonlyMap<AttachmentId, AttachmentDef>;
|
|
673
945
|
/** When given, the default condition and ammunition quality must be ones the rules define. */
|
|
674
946
|
readonly rules?: Pick<WeaponRules, 'conditions' | 'defaultCondition' | 'ammoQualities' | 'defaultAmmoQuality'>;
|
|
675
947
|
}
|
|
676
948
|
/** 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[];
|
|
949
|
+
declare const checkArsenal: ({ weapons, calibers, explosives, attachments, rules }: ArsenalParts) => string[];
|
|
950
|
+
|
|
951
|
+
/** How the weapon is held and what it is in: what the conditional effects (`aiming`, `hip`, `supported`, `subsonic`, `collapsed`) ask. */
|
|
952
|
+
interface LoadoutContext {
|
|
953
|
+
readonly aiming: boolean;
|
|
954
|
+
readonly supported: boolean;
|
|
955
|
+
readonly stock: 'collapsed' | 'extended';
|
|
956
|
+
readonly caliber: CaliberDef | null;
|
|
957
|
+
readonly rules: Pick<WeaponRules, 'attachments' | 'aim' | 'stock'>;
|
|
958
|
+
}
|
|
959
|
+
interface Loadout {
|
|
960
|
+
/** The action with every effect applied; the very object of the def when nothing differs from the weapon as it ships. */
|
|
961
|
+
readonly action: WeaponAction;
|
|
962
|
+
/** Kg: the weapon with what is on it. */
|
|
963
|
+
readonly mass: number;
|
|
964
|
+
/** Seconds to raise the weapon to the sights. */
|
|
965
|
+
readonly aimSeconds: number;
|
|
966
|
+
/** Times the spread when not aiming. */
|
|
967
|
+
readonly hipFactor: number;
|
|
968
|
+
readonly suppressed: boolean;
|
|
969
|
+
readonly drawFactor: number;
|
|
970
|
+
readonly heatFactor: number;
|
|
971
|
+
readonly faultFactor: number;
|
|
972
|
+
/** What a dual coupler does to the reload of every second magazine change (1: nothing). */
|
|
973
|
+
readonly secondReloadFactor: number;
|
|
974
|
+
readonly optic: AttachmentDef['optic'] | undefined;
|
|
975
|
+
readonly light: (NonNullable<AttachmentDef['light']> & {
|
|
976
|
+
readonly id: AttachmentId;
|
|
977
|
+
}) | undefined;
|
|
978
|
+
readonly laser: (NonNullable<AttachmentDef['laser']> & {
|
|
979
|
+
readonly id: AttachmentId;
|
|
980
|
+
}) | undefined;
|
|
981
|
+
}
|
|
982
|
+
type Catalogue = ReadonlyMap<AttachmentId, AttachmentDef>;
|
|
983
|
+
/** The weapon with what is on it: the numbers of the action, the mass, the time to aim, and the lights, laser and optic that are on. */
|
|
984
|
+
declare const resolveLoadout: (def: WeaponDef, fitted: readonly FittedAttachment[], catalogue: Catalogue, context: LoadoutContext) => Loadout;
|
|
678
985
|
|
|
679
986
|
/** Muzzle energy in joules of ONE projectile (a bullet, or one pellet): 0.5 × mass × speed², speed scaled by the barrel factor. */
|
|
680
987
|
declare const muzzleEnergy: (caliber: CaliberDef, barrel?: number) => number;
|
|
681
988
|
|
|
682
989
|
declare const CALIBERS: CaliberDef[];
|
|
990
|
+
declare const ATTACHMENTS: AttachmentDef[];
|
|
683
991
|
declare const EXPLOSIVES: ExplosiveDef[];
|
|
684
992
|
declare const ARCHETYPE_IDS: readonly WeaponId[];
|
|
685
993
|
declare const WEAPONS: WeaponDef[];
|
|
@@ -734,4 +1042,4 @@ type StageTable = Readonly<Record<ReloadKind, readonly ReloadStage[]>>;
|
|
|
734
1042
|
/** 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
1043
|
declare const RELOAD_STAGES: Readonly<Record<ReloadFamily, StageTable>>;
|
|
736
1044
|
|
|
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 };
|
|
1045
|
+
export { ARCHETYPE_IDS, ATTACHMENTS, type AmmoQualityDef, type Arsenal, type ArsenalOptions, type AttachmentDef, type AttachmentId, type AttachmentInstall, type AttachmentKind, type BlastEffect, CALIBERS, type CaliberDef, type CaliberId, type CanFit, type CanFitContext, type CartridgeDims, type CaseType, type ConditionDef, DEFAULT_LOADOUT, DEFAULT_RULES, type DataSource, type DeepPartial, type Detonation, EXPLOSIVES, type EffectCondition, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, type IsCompatible, type Loadout, type LoadoutContext, type MountDef, type MountKind, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type StatModifier, type StockDef, type StockState, 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 WeaponSnapshot, type WeaponStance, type WeaponStat, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, backblastEffect, blastEffect, canFit, canInstallWith, checkArsenal, createArsenal, createExplosiveBody, createRng, locales, muzzleEnergy, nominalFuse, resolveLoadout, resolveStrings, sampleFuse, tripwireSegment };
|