@adatechnology/game-weapons 0.1.4 → 0.3.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 CHANGED
@@ -1,8 +1,9 @@
1
1
  # @adatechnology/game-weapons
2
2
 
3
- Engine-agnostic weapons and ammunition. Real calibres as data (muzzle energy from `0.5 × m × v²`), generic real-world weapon archetypes (no brands),
4
- and a tiny deterministic runtime: magazines, fire modes, reload, spread and bloom, shotgun pellets, recoil, noise, plus melee, flame, heat, throwables,
5
- tools and a fire extinguisher. A trigger pull returns plain-data `Shot`s and `Use`s, so any damage model can consume them. It knows nothing about any game.
3
+ Engine-agnostic weapons and ammunition. 28 real calibres as data (muzzle energy from `0.5 × m × v²`), 79 real models with their brands and measures
4
+ (Glock 17, AK-47, Remington 870, Browning M2...), 17 explosives, 42 generic archetypes, and a deterministic runtime: magazines, fire modes, reload by kind
5
+ with its steps, draw, manual cycle, jams and clearing, safety, barrel heat, spread and bloom, shotgun pellets, recoil, noise, plus melee, flame, heat,
6
+ throwables, launchers, tools and a fire extinguisher. A trigger pull returns plain-data `Shot`s and `Use`s, so any damage model can consume them. It knows nothing about any game.
6
7
 
7
8
  Units: metres, seconds, joules, mm (calibre diameter), grams (bullet mass), m/s, degrees, °C. Every random choice comes from a seeded generator, so the
8
9
  same seed gives the same shots on every machine.
@@ -48,16 +49,46 @@ loads one round per `reload` seconds and the trigger interrupts it. `trigger(dt)
48
49
  counting `dt` twice.
49
50
 
50
51
  Non-firearms: `flame`/`heat` drain `fuelPerSecond × dt` of fuel (`no_fuel` when dry), `tool` ticks with `duration: dt`, `extinguisher` spends its
51
- charge in seconds, `throwable` throws once per pull (`velocity = direction × throwSpeed` plus a small upward arc, three by default), `melee` swings at
52
+ charge in seconds, `throwable` throws (`velocity = direction × throwSpeed` plus a small upward arc, three by default; a timer one is cooked, see below), `melee` swings at
52
53
  its rpm, `hand` produces one `hand` use per pull.
53
54
 
55
+ ### Handling: events, faults and heat
56
+
57
+ ```ts
58
+ const rifle = arsenal.create('ak_47', { condition: 'used', ammoQuality: 'reloaded' })
59
+ rifle.draw() // 0.35 s: the trigger answers `drawing`
60
+ rifle.reload('auto') // 'full' loads a revolver all at once, 'one_by_one' forces round by round
61
+ const result = rifle.trigger(origin, direction, dt, held)
62
+ result.rounds // cartridges spent: a shell is one, a burst is several
63
+ result.roundTimes // seconds after the start of the call at which each round left the barrel
64
+ if (result.fault) rifle.clearFault() // 1.2 s; `rifle.fault` stays set until it ends
65
+ rifle.setSafety(true) // the trigger answers `safe`
66
+ rifle.heatLevel // 0..1, from the barrel heat (`rifle.heat`, up to 140)
67
+ for (const event of rifle.drain()) animate(event) // draw, shot, misfire, cycle, reload (+ stages, feed), empty, mode, fault, clear, safety
68
+ ```
69
+
70
+ Each cartridge rolls its own fault from a second generator (`seed ^ 0x6a09e667`), so the spread of a seed does not change when faults are on. The chance is
71
+ `condition × faultFactor × (1 + max(0, heat − 60) / 40)` (new 0.3%, used 1.5%, worn 5%, rusty 12%), and reloaded ammunition adds a misfire chance of 8%.
72
+ A revolver or break-action only misfires (the round is spent, no jam); a pump, bolt or lever fails to extract; the rest stovepipe or double feed.
73
+ A bow or crossbow has no cartridge: it adds no heat and never jams. Everything is a number you can change with `rules` (`faults: false` turns jams off,
74
+ `faultChance` takes a function), and the order of the reload steps is in `RELOAD_STAGES`.
75
+
76
+ Real models point to a generic `archetype` for the handling numbers (spread, bloom, range, recoil); `patch`, `remove` and `include` change the shipped
77
+ entries by id, and `checkArsenal` reports every inconsistency at once.
78
+
54
79
  ## Data
55
80
 
56
- `CALIBERS` (`src/data/calibers.json`): `22lr`, `9x19`, `38spl`, `357mag`, `40sw`, `45acp`, `380acp`, `5_56x45`, `7_62x39`, `7_62x51`, `338lapua`, `50bmg`,
57
- `12ga_00buck` (9 pellets), `12ga_slug`, `12ga_birdshot` (90 pellets), `20ga_buck`, `arrow`, `crossbow_bolt`. Muzzle energy is per projectile (per pellet
58
- for shotguns), e.g. 9×19 ~500 J, 5.56 ~1750 J, .308 ~3500 J, .50 BMG ~18 kJ, 00 buck ~300 J per pellet.
81
+ `CALIBERS` (28, generated by `tools/weapons-catalog`): from `22lr` and `9x19` to `50bmg`, with the new `9x18`, `5_7x28`, `44mag`, `50ae`, `5_45x39`, `30_30`,
82
+ `7_62x54r`, `30_06`, `300wm` and `408cheytac`. Muzzle energy is per projectile (per pellet for shotguns), e.g. 9×19 ~500 J, 5.56 ~1750 J, .308 ~3500 J,
83
+ .50 BMG ~18 kJ, 00 buck ~300 J per pellet. Each calibre also carries the audible distance of its shot (`noise`: 150 / 300 / 420 / 600 m), the case type
84
+ that sets the heat per round, and the cartridge measures.
85
+
86
+ `WEAPONS` is the union of four files: `firearms.json` (73 real models, from the Galeria and the Arsenal), `launchers.json` (4 rocket launchers and 2
87
+ flamethrowers), `explosive-weapons.json` (flashbang, dynamite, C4 and the Claymore, kept by hand: they point to `frag_grenade` for the throw) and `archetypes.json` (the 42 generic weapons below). Every real model has its `maker`, `dimensions` (length, barrel, empty mass), `family`
88
+ (how it reloads), `timings` (draw, reload, empty reload, per round, cycle, clear), `muzzleSpeed`, `faultFactor` and an `archetype`. `EXPLOSIVES` has 17
89
+ entries with lethal and injury radius, energy, noise and fuse.
59
90
 
60
- `WEAPONS` (`src/data/weapons.json`):
91
+ The generic archetypes:
61
92
 
62
93
  | Category | Ids |
63
94
  |---|---|
@@ -67,24 +98,98 @@ for shotguns), e.g. 9×19 ~500 J, 5.56 ~1750 J, .308 ~3500 J, .50 BMG ~18 kJ, 00
67
98
  | Explosives | `frag_grenade`, `pipe_bomb` |
68
99
  | Tools | `screwdriver`, `wrench`, `pry_bar`, `hacksaw`, `utility_knife`, `claw_hammer`, `extinguisher`, `hand` |
69
100
 
70
- `DEFAULT_LOADOUT` lists a starter kit of 19 ids. Pass `calibers` / `weapons` to `createArsenal` to add or override entries by id.
101
+ `DEFAULT_LOADOUT` lists a starter kit of 19 ids. Pass `calibers` / `weapons` / `explosives` to `createArsenal` to add or override entries by id.
102
+
103
+ ## Explosives, launchers and flamethrowers
104
+
105
+ A trigger pull on a launcher returns a `throw` use (the rocket: `explosive`, `trigger: 'impact'`, `armDistance`, speed in `velocity`) and, when the launcher has one, a
106
+ `backblast` use (5 m, cone of 19°, pointing away from the target). A throwable returns a `throw` use (fuse from the explosive: M67 4 s, pipe bomb 3 s; fuse 0 means it
107
+ goes off on the first hit, like the molotov, which leaves fire of 4 m for 9 s) or, for the Claymore and C4, a `place` use that waits for `wire` or `remote`.
108
+ `arsenal.explosiveBody(use)` makes the flying (or waiting) body: `step(dt, probe)` applies gravity and bounces (`rules.explosives`), counts the fuse, arms by distance and
109
+ returns `armed`, `impact`, `dud` and `detonate` events; `trigger('wire' | 'remote' | ...)` sets off what waits. `blastEffect(detonation, point)` says if a point is in
110
+ the lethal or the injury zone (with the cone of a directional charge and the stun of a flashbang) and `backblastEffect(use, point)` the danger behind a tube.
111
+ The world explosives (`propane_p13`, `fuel_barrel`, `car_fuel_tank`, `fuel_pump`, `fuel_station_tank`) carry `chain`, the delays of the chain reaction `game-destruction` uses.
112
+
113
+ ### Cooking a grenade, safety fuses, the flashbang and trip wires
114
+
115
+ A throwable with a timer fuse is **cooked** (owner decision, 2026-10-24): the pull takes the pin out and the fuse starts to count (`cook` event, `start`); keep calling
116
+ `trigger(..., held)` each frame and, on the frame the trigger goes up, call `release(origin, direction)`: it returns the throw with the fuse that is left
117
+ (`use.fuse`, and `use.cooked` for the seconds held; `cook` event `throw`). Holding past the fuse sets it off in the hand: the `trigger` (or the `release`) returns a `throw` use with
118
+ `inHand: true`, `fuse: 0` and no velocity (`cook` event `burst`). Impact throwables (molotov, launchers) and the ones set down (C4, Claymore, a long-fuse dynamite) act on the pull, as before.
119
+
120
+ `ExplosiveDef` has four ways to say how long the fuse is: `fuse` (fixed seconds), `fuseRange: [min, max]` (sampled per throw; the flashbang is the real M84 delay of 1.0 to 2.3 s from the lever),
121
+ and `fuseLength` (metres) with `burnRate` (s/m) and `burnTolerance` (a fraction): the dynamite is 0.03 m of safety fuse at 131 s/m ±10%, about 4 s. The sampling uses a stream of its own
122
+ (`seed ^ 0xbb67ae85`), so the spread of the shots does not move. `weapon.setFuseLength(metres)` (the test area's `fuse_length` control) or
123
+ `patch.explosives.dynamite.fuseLength` makes a longer fuse; when the fuse reaches `rules.explosives.placeFuseFrom` (10 s) the explosive is set down lit (`place` use with the `timer` trigger)
124
+ instead of thrown, which builds a delayed trap. `nominalFuse(explosive)` and `sampleFuse(explosive, random)` are exported.
125
+
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
+ 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
+
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.
71
173
 
72
174
  ## API
73
175
 
74
- - `createArsenal(options?)` returns an `Arsenal`: `calibers`, `weapons` (maps), `create(id, { seed?, reserve? })` (unknown id throws), `muzzleEnergy(caliberId, barrel?)`,
75
- `name(id)` (weapon, fire mode or category, translated), `list(category?)`.
76
- - `WeaponState`: `def`, `caliber`, `ammo`, `capacity`, `reserve`, `mode`, `reloading`, `spread`, `trigger(origin, direction, dt, held?, source?)`, `release()`,
77
- `reload()`, `cycleMode()`, `update(dt)`, `refill()`.
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?)`,
177
+ `muzzleEnergy(caliberId, barrel?)`, `energy(weaponId)`, `name(id)` (weapon, explosive, fire mode, category, fault, condition or calibre, translated), `list(category?)`.
178
+ Options: `calibers`, `weapons`, `explosives`, `patch`, `remove`, `include`, `rules`, `strings`, `seed`, `locale`.
179
+ - `WeaponState`: `def`, `caliber`, `ammo`, `capacity`, `reserve`, `mode`, `reloading`, `locked`, `phase`, `fault`, `clearing`, `safety`, `heat`, `heatLevel`, `condition`,
180
+ `ammoQuality`, `spread`, `trigger(origin, direction, dt, held?, source?)`, `release(origin?, direction?)`, `draw()`, `reload(kind?)`, `cycleMode()`, `setSafety(on)`, `clearFault()`,
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).
78
182
  - `Shot`: `origin`, `direction`, `energy` (J), `caliber` (mm), `caliberId`, `speed`, `energyAt(distance)` (energy × speed factor², drag per 100 m), `pellet`, `weapon`, `source`.
79
- - `Use`: `melee`, `flame`, `heat`, `throw`, `tool`, `extinguish`, `hand`. `TriggerResult`: `shots`, `uses`, `status` (`ok`, `empty`, `reloading`, `cooldown`, `no_fuel`, `safe`), `recoil`, `noise`.
80
- - `muzzleEnergy(caliber, barrel?)`, `CALIBERS`, `WEAPONS`, `DEFAULT_LOADOUT`, `locales`, `resolveStrings`.
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?`.
184
+ - `muzzleEnergy(caliber, barrel?)`, `CALIBERS`, `WEAPONS`, `EXPLOSIVES`, `ARCHETYPE_IDS`, `DEFAULT_LOADOUT`, `DEFAULT_RULES`, `RELOAD_STAGES`, `checkArsenal`, `locales`, `resolveStrings`.
81
185
 
82
186
  Locales: `en` and `pt-BR` (`locale` option; unknown falls back to `en`). Calibre labels are technical names and are not translated.
83
187
 
84
188
  ## Português
85
189
 
86
- Armas e munição independentes de engine: calibres reais como dados (energia de boca = `0,5 × m × v²`), arquétipos genéricos de armas (sem marcas) e um
87
- runtime determinístico (carregador, modos de tiro, recarga, dispersão, chumbos de espingarda, recuo, ruído), além de corpo a corpo, chama, calor,
88
- arremessáveis, ferramentas e extintor. Cada disparo vira um `Shot` (energia em joules, calibre em mm, direção) que se passa direto para
190
+ Armas e munição independentes de engine: 28 calibres reais como dados (energia de boca = `0,5 × m × v²`), 79 armas reais com marca e medidas, 17 explosivos,
191
+ 42 arquétipos genéricos e um runtime determinístico (carregador, modos de tiro, saque, ciclo manual, recarga por tipo com suas etapas, panes e desobstruir,
192
+ trava, calor do cano, dispersão, chumbos de espingarda, recuo, ruído), além de corpo a corpo, chama, calor, arremessáveis, lançadores, ferramentas e extintor.
193
+ `weapon.drain()` entrega os eventos (saque, tiro, pane, recarga...) para animação e som; `rules` muda qualquer número (`faults: false` desliga as panes). Cada disparo vira um `Shot` (energia em joules, calibre em mm, direção) que se passa direto para
89
194
  `world.shoot(origem, direção, shot.energy, shot.caliber)` do `@adatechnology/game-destruction`. Use `createArsenal({ locale: 'pt-BR' })` para os nomes
90
195
  em português (`arsenal.name('rifle_5_56')` devolve "fuzil 5,56"). A recarga nunca é automática; o jogo chama `reload()`.