@adatechnology/game-weapons 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11712,7 +11712,9 @@ var firearms_default = [
11712
11712
  dimensions: {
11713
11713
  length: 0.801,
11714
11714
  barrel: 0.559,
11715
- emptyMass: 39
11715
+ emptyMass: 39,
11716
+ barrels: 6,
11717
+ barrelMass: 2
11716
11718
  },
11717
11719
  archetype: "rifle_7_62x39",
11718
11720
  sources: [
@@ -12710,19 +12712,41 @@ var resolveThrowables = (weapons, explosives) => {
12710
12712
  // src/rules.ts
12711
12713
  import { DEFAULT_IGNITION_RULES } from "@adatechnology/game-contracts";
12712
12714
  var DEFAULT_HEAT = {
12713
- cap: 140,
12714
- displayMax: 120,
12715
- decayBase: 1.6,
12716
- decayPerPoint: 0.03,
12717
- faultFrom: 60,
12718
- faultSpan: 40,
12719
- perShot: { shell: 3, big: 6, tiny: 0.5, pistol: 1.2, rifle: 2 },
12715
+ cap: 900,
12716
+ displayMax: 750,
12717
+ faultFrom: 350,
12718
+ faultSpan: 200,
12719
+ specificHeat: 490,
12720
+ barrelShare: { shell: 0.48, big: 0.48, tiny: 0.3, pistol: 0.3, rifle: 0.48 },
12721
+ barrelKilogramsPerMetre: {
12722
+ pistol: 1,
12723
+ revolver: 1.4,
12724
+ smg: 1.2,
12725
+ carbine: 1.6,
12726
+ rifle: 1.6,
12727
+ dmr: 2.4,
12728
+ sniper: 2.4,
12729
+ hunting: 2.4,
12730
+ machine_gun: 3,
12731
+ shotgun: 1.1
12732
+ },
12733
+ barrelFallback: { metres: 0.4, kilogramsPerMetre: 1.6 },
12734
+ cooling: { baseSeconds: 30, secondsPerKilogram: 250 },
12720
12735
  perRocket: 35,
12721
- visual: { smokeFrom: 70, smokeSeconds: 2.5, glowFrom: 80, glowSpan: 40 }
12736
+ visual: { smokeFrom: 250, smokeSpan: 300, smokeSeconds: 2.5, glowFrom: 450, glowSpan: 300 }
12722
12737
  };
12723
12738
  var GALLERY_HEAT = {
12724
12739
  ...DEFAULT_HEAT,
12725
- perShot: { shell: 6, big: 9, tiny: 1.2, pistol: 3, rifle: 4.5 }
12740
+ cap: 140,
12741
+ displayMax: 120,
12742
+ faultFrom: 60,
12743
+ faultSpan: 40,
12744
+ visual: { smokeFrom: 70, smokeSpan: 100, smokeSeconds: 2.5, glowFrom: 80, glowSpan: 40 },
12745
+ gallery: {
12746
+ perShot: { shell: 6, big: 9, tiny: 1.2, pistol: 3, rifle: 4.5 },
12747
+ decayBase: 1.6,
12748
+ decayPerPoint: 0.03
12749
+ }
12726
12750
  };
12727
12751
  var defaultFaultChance = (context) => {
12728
12752
  const factor = context.def.action.kind === "firearm" ? context.def.action.faultFactor ?? 1 : 1;
@@ -13012,18 +13036,79 @@ var throwableUse = (params) => {
13012
13036
  };
13013
13037
  };
13014
13038
 
13039
+ // src/fire.ts
13040
+ var EPS2 = 1e-9;
13041
+ var MANUAL_MODES = /* @__PURE__ */ new Set(["pump", "bolt", "lever"]);
13042
+ var weaponSpeed = (action, caliber) => action.muzzleSpeed ?? caliber.muzzleSpeed * (action.barrel ?? 1);
13043
+ var weaponNoise = (action, caliber) => action.noise ?? caliber.noise ?? 0;
13044
+ var timingsOf = (action) => "timings" in action ? action.timings : void 0;
13045
+ var drawSeconds = (action, rules) => timingsOf(action)?.draw ?? rules.draw;
13046
+ var clearSeconds = (action, rules) => timingsOf(action)?.clear ?? rules.clear;
13047
+ var manualCycleSeconds = (action, mode) => MANUAL_MODES.has(mode) ? action.timings?.cycle ?? 0 : 0;
13048
+ var planRounds = (action, mode, ammo, firstAt, frameEnd) => {
13049
+ const interval = 60 / action.rpm;
13050
+ const times = [];
13051
+ if (mode === "auto") {
13052
+ for (let t = firstAt; times.length < ammo && (times.length === 0 ? t <= frameEnd + EPS2 : t < frameEnd - EPS2); t += interval) times.push(t);
13053
+ return times;
13054
+ }
13055
+ if (mode === "burst") {
13056
+ const count = Math.min(action.burst ?? 3, ammo);
13057
+ for (let k = 0; k < count; k++) times.push(firstAt + k * interval);
13058
+ return times;
13059
+ }
13060
+ if (mode === "volley") return Array.from({ length: Math.min(action.magazine, ammo) }, () => firstAt);
13061
+ return [firstAt];
13062
+ };
13063
+
13015
13064
  // src/heat.ts
13016
13065
  var SUBSTEP_SECONDS = 1 / 60;
13017
- var decayHeat = (heat, seconds, rules) => {
13066
+ var MAX_ROUNDS_SEARCHED = 1e5;
13067
+ var barrelMassOf = (def, rules) => {
13068
+ const dimensions = def.dimensions;
13069
+ const kilogramsPerMetre = rules.barrelKilogramsPerMetre[def.category] ?? rules.barrelFallback.kilogramsPerMetre;
13070
+ const single = dimensions?.barrelMass ?? (dimensions?.barrel ?? rules.barrelFallback.metres) * kilogramsPerMetre;
13071
+ return single * (dimensions?.barrels ?? 1);
13072
+ };
13073
+ var coolingTimeConstant = (barrelMass, rules) => rules.cooling.baseSeconds + rules.cooling.secondsPerKilogram * barrelMass;
13074
+ var decayHeat = (heat, seconds, barrelMass, rules) => {
13075
+ if (heat <= 0) return 0;
13076
+ if (rules.gallery) return decayGallery(heat, seconds, rules.gallery);
13077
+ return heat * Math.exp(-seconds / coolingTimeConstant(barrelMass, rules));
13078
+ };
13079
+ var decayGallery = (heat, seconds, gallery) => {
13018
13080
  const steps = Math.max(1, Math.ceil(seconds / SUBSTEP_SECONDS - 1e-9));
13019
13081
  const step = seconds / steps;
13020
13082
  let current = heat;
13021
- for (let i = 0; i < steps && current > 0; i++) current = Math.max(0, current - step * (rules.decayBase + current * rules.decayPerPoint));
13083
+ for (let i = 0; i < steps && current > 0; i++) current = Math.max(0, current - step * (gallery.decayBase + current * gallery.decayPerPoint));
13022
13084
  return current;
13023
13085
  };
13024
- var heatPerRound = (action, caliber, rules) => {
13086
+ var heatPerRound = ({ action, caliber, energy, barrelMass, rules }) => {
13025
13087
  if (action.kind === "launcher") return rules.perRocket;
13026
- return caliber?.caseType ? rules.perShot[caliber.caseType] : 0;
13088
+ const caseType = caliber?.caseType;
13089
+ if (!caseType) return 0;
13090
+ if (rules.gallery) return rules.gallery.perShot[caseType];
13091
+ return rules.barrelShare[caseType] * energy / (barrelMass * rules.specificHeat);
13092
+ };
13093
+ var roundsToWarning = ({ def, caliber, energy, rpm, rules }) => {
13094
+ if (def.action.kind !== "firearm" || rpm <= 0) return Infinity;
13095
+ const barrelMass = barrelMassOf(def, rules);
13096
+ const perRound = heatPerRound({ action: def.action, caliber, energy: energy * (caliber.pellets ?? 1), barrelMass, rules });
13097
+ const interval = 60 / rpm;
13098
+ let heat = 0;
13099
+ for (let round = 1; round <= MAX_ROUNDS_SEARCHED; round++) {
13100
+ heat = decayHeat(heat, round === 1 ? 0 : interval, barrelMass, rules) + perRound;
13101
+ if (heat >= rules.faultFrom) return round;
13102
+ }
13103
+ return Infinity;
13104
+ };
13105
+ var roundsToWarningOf = (arsenal, weaponId) => {
13106
+ const def = arsenal.weapons.get(weaponId);
13107
+ if (!def || def.action.kind !== "firearm") return Infinity;
13108
+ const caliber = arsenal.calibers.get(def.action.caliber);
13109
+ if (!caliber) return Infinity;
13110
+ const energy = 0.5 * (caliber.bulletGrams / 1e3) * weaponSpeed(def.action, caliber) ** 2;
13111
+ return roundsToWarning({ def, caliber, energy, rpm: def.action.rpm, rules: arsenal.rules.heat });
13027
13112
  };
13028
13113
  var burstNoise = (base, recentShots, rules) => base * (1 + Math.min(rules.cap, rules.step * recentShots));
13029
13114
 
@@ -13157,31 +13242,6 @@ var rollFault = (roll) => {
13157
13242
  };
13158
13243
  var isDudWithoutJam = (action, fault) => fault === "misfire" && action.kind === "firearm" && MISFIRE_ONLY.has(action.family);
13159
13244
 
13160
- // src/fire.ts
13161
- var EPS2 = 1e-9;
13162
- var MANUAL_MODES = /* @__PURE__ */ new Set(["pump", "bolt", "lever"]);
13163
- var weaponSpeed = (action, caliber) => action.muzzleSpeed ?? caliber.muzzleSpeed * (action.barrel ?? 1);
13164
- var weaponNoise = (action, caliber) => action.noise ?? caliber.noise ?? 0;
13165
- var timingsOf = (action) => "timings" in action ? action.timings : void 0;
13166
- var drawSeconds = (action, rules) => timingsOf(action)?.draw ?? rules.draw;
13167
- var clearSeconds = (action, rules) => timingsOf(action)?.clear ?? rules.clear;
13168
- var manualCycleSeconds = (action, mode) => MANUAL_MODES.has(mode) ? action.timings?.cycle ?? 0 : 0;
13169
- var planRounds = (action, mode, ammo, firstAt, frameEnd) => {
13170
- const interval = 60 / action.rpm;
13171
- const times = [];
13172
- if (mode === "auto") {
13173
- for (let t = firstAt; times.length < ammo && (times.length === 0 ? t <= frameEnd + EPS2 : t < frameEnd - EPS2); t += interval) times.push(t);
13174
- return times;
13175
- }
13176
- if (mode === "burst") {
13177
- const count = Math.min(action.burst ?? 3, ammo);
13178
- for (let k = 0; k < count; k++) times.push(firstAt + k * interval);
13179
- return times;
13180
- }
13181
- if (mode === "volley") return Array.from({ length: Math.min(action.magazine, ammo) }, () => firstAt);
13182
- return [firstAt];
13183
- };
13184
-
13185
13245
  // src/attachment-effects.ts
13186
13246
  var activeParts = (fitted, catalogue) => fitted.flatMap((part) => {
13187
13247
  const def = catalogue.get(part.id);
@@ -13428,6 +13488,10 @@ var WeaponCore = class {
13428
13488
  get safety() {
13429
13489
  return this._safety;
13430
13490
  }
13491
+ /** Kg of steel that heat up with the shots. */
13492
+ get barrelMass() {
13493
+ return barrelMassOf(this.def, this.rules.heat);
13494
+ }
13431
13495
  get heat() {
13432
13496
  return this._heat;
13433
13497
  }
@@ -13480,7 +13544,7 @@ var WeaponCore = class {
13480
13544
  }
13481
13545
  advance(seconds) {
13482
13546
  if (seconds <= 0) return;
13483
- this._heat = decayHeat(this._heat, seconds, this.rules.heat);
13547
+ this._heat = decayHeat(this._heat, seconds, this.barrelMass, this.rules.heat);
13484
13548
  this.clock += seconds;
13485
13549
  }
13486
13550
  /** Complete what falls at or before `t`: scheduled events and the reload steps. */
@@ -14043,7 +14107,7 @@ var WeaponFirearm = class extends WeaponAttachments {
14043
14107
  res.shots.push(shot);
14044
14108
  }
14045
14109
  this._ammo -= 1;
14046
- this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound(a, cal, this.rules.heat) * this.load.heatFactor);
14110
+ this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound({ action: a, caliber: cal, energy: energy * pellets, barrelMass: this.barrelMass, rules: this.rules.heat }) * this.load.heatFactor);
14047
14111
  this.readyAt = t + 60 / a.rpm;
14048
14112
  this.extra = Math.min(bloomNow + (a.bloomDeg ?? 0), a.spreadDeg * (BLOOM_CAP - 1));
14049
14113
  this.extraClock = t;
@@ -14134,7 +14198,7 @@ var WeaponRuntime = class extends WeaponFirearm {
14134
14198
  }
14135
14199
  const t = Math.max(start, this.readyAt);
14136
14200
  this._ammo -= 1;
14137
- this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound(a, null, this.rules.heat));
14201
+ this._heat = Math.min(this.rules.heat.cap, this._heat + heatPerRound({ action: a, caliber: null, energy: 0, barrelMass: this.barrelMass, rules: this.rules.heat }));
14138
14202
  this.emit({ type: "shot", shots: 0, rounds: 1, mode: this.mode, at: t });
14139
14203
  return result("ok", { uses: launcherUses(a, this.explosive, origin, dir), recoil: [a.recoil[0], a.recoil[1]], noise: a.noise ?? 0, rounds: 1, roundTimes: [t - start] });
14140
14204
  }
@@ -14558,13 +14622,16 @@ export {
14558
14622
  ammoId,
14559
14623
  ammoIgnition,
14560
14624
  backblastEffect,
14625
+ barrelMassOf,
14561
14626
  blastEffect,
14562
14627
  canFit,
14563
14628
  canInstallWith,
14564
14629
  checkArsenal,
14630
+ coolingTimeConstant,
14565
14631
  createArsenal,
14566
14632
  createExplosiveBody,
14567
14633
  createRng,
14634
+ decayHeat,
14568
14635
  genericWeapons,
14569
14636
  locales,
14570
14637
  muzzleEnergy,
@@ -14574,6 +14641,8 @@ export {
14574
14641
  resolveLoad,
14575
14642
  resolveLoadout,
14576
14643
  resolveStrings,
14644
+ roundsToWarning,
14645
+ roundsToWarningOf,
14577
14646
  sampleFuse,
14578
14647
  tripwireSegment,
14579
14648
  weaponMenu