@adatechnology/game-weapons 0.1.3 → 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 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,53 @@ 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')`.
71
128
 
72
129
  ## API
73
130
 
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()`.
131
+ - `createArsenal(options?)` returns an `Arsenal`: `calibers`, `weapons`, `explosives` (maps), `rules`, `create(id, { seed?, reserve?, condition?, ammoQuality? })` (unknown id throws),
132
+ `muzzleEnergy(caliberId, barrel?)`, `energy(weaponId)`, `name(id)` (weapon, explosive, fire mode, category, fault, condition or calibre, translated), `list(category?)`.
133
+ Options: `calibers`, `weapons`, `explosives`, `patch`, `remove`, `include`, `rules`, `strings`, `seed`, `locale`.
134
+ - `WeaponState`: `def`, `caliber`, `ammo`, `capacity`, `reserve`, `mode`, `reloading`, `locked`, `phase`, `fault`, `clearing`, `safety`, `heat`, `heatLevel`, `condition`,
135
+ `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).
78
137
  - `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`.
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?`.
139
+ - `muzzleEnergy(caliber, barrel?)`, `CALIBERS`, `WEAPONS`, `EXPLOSIVES`, `ARCHETYPE_IDS`, `DEFAULT_LOADOUT`, `DEFAULT_RULES`, `RELOAD_STAGES`, `checkArsenal`, `locales`, `resolveStrings`.
81
140
 
82
141
  Locales: `en` and `pt-BR` (`locale` option; unknown falls back to `en`). Calibre labels are technical names and are not translated.
83
142
 
84
143
  ## Português
85
144
 
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
145
+ 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,
146
+ 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,
147
+ 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.
148
+ `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
149
  `world.shoot(origem, direção, shot.energy, shot.caliber)` do `@adatechnology/game-destruction`. Use `createArsenal({ locale: 'pt-BR' })` para os nomes
90
150
  em português (`arsenal.name('rifle_5_56')` devolve "fuzil 5,56"). A recarga nunca é automática; o jogo chama `reload()`.