@adatechnology/game-weapons 0.10.1 → 0.11.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.d.ts +36 -2
- package/dist/index.global.js +60 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +60 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -177,7 +177,7 @@ type ExplosiveEvent = {
|
|
|
177
177
|
point: Vec3;
|
|
178
178
|
armed: boolean;
|
|
179
179
|
}
|
|
180
|
-
/** Hit something before it was armed
|
|
180
|
+
/** Hit something before it was armed and `rules.explosives.unarmedImpact` is `dud`: it does not explode. */
|
|
181
181
|
| {
|
|
182
182
|
type: 'dud';
|
|
183
183
|
at: number;
|
|
@@ -225,6 +225,9 @@ declare class ExplosiveBody {
|
|
|
225
225
|
private isArmed;
|
|
226
226
|
private isDone;
|
|
227
227
|
private isDud;
|
|
228
|
+
/** Fired with a speed and an impact fuze (a rocket, a 40 mm grenade): it must end in a blast, never lie live on what it hit. */
|
|
229
|
+
private readonly isLaunched;
|
|
230
|
+
private stillSteps;
|
|
228
231
|
constructor(init: ExplosiveBodyInit);
|
|
229
232
|
get age(): number;
|
|
230
233
|
/** Metres flown so far. */
|
|
@@ -239,6 +242,8 @@ declare class ExplosiveBody {
|
|
|
239
242
|
/** Sets it off from outside; undefined when this explosive does not answer to `cause` or is already done. */
|
|
240
243
|
trigger(cause: ExplosiveTrigger): ExplosiveEvent | undefined;
|
|
241
244
|
private moves;
|
|
245
|
+
/** A launched round that came to rest (stopped, or still for `STILL_STEPS` steps) or flew past its self-destruct time. */
|
|
246
|
+
private isSpent;
|
|
242
247
|
private fly;
|
|
243
248
|
private checkArmed;
|
|
244
249
|
private onImpact;
|
|
@@ -456,6 +461,15 @@ interface WeaponRules {
|
|
|
456
461
|
readonly placeFuseFrom: number;
|
|
457
462
|
/** The wire of a charge set down with the `wire` trigger that does not name one. */
|
|
458
463
|
readonly tripwire: Required<ExplosiveTripwire>;
|
|
464
|
+
/**
|
|
465
|
+
* What an impact fuze does when the round hits before it flew its arming distance: `detonate` (default: a launched round always goes off where
|
|
466
|
+
* it lands, however close) or `dud` (the real safety of the fuze: it does not go off and the host decides what the inert round does).
|
|
467
|
+
*/
|
|
468
|
+
readonly unarmedImpact: 'detonate' | 'dud';
|
|
469
|
+
/** m/s: a launched impact-fuzed round blocked or stopped below this speed has come to rest on something and goes off; it never lies there live. */
|
|
470
|
+
readonly restSpeed: number;
|
|
471
|
+
/** Seconds of flight after which a launched impact-fuzed round that hit nothing goes off by itself (the fuze's self-destruct). */
|
|
472
|
+
readonly selfDestructSeconds: number;
|
|
459
473
|
};
|
|
460
474
|
/** Putting accessories on and taking them off. */
|
|
461
475
|
readonly attachments: {
|
|
@@ -1238,6 +1252,26 @@ declare const roundsToWarning: ({ def, caliber, energy, rpm, rules }: RoundsToWa
|
|
|
1238
1252
|
/** `roundsToWarning` for a weapon of the arsenal, from the muzzle energy of its own calibre and barrel at its listed rate of fire; Infinity for what has no cartridge or never heats up that far. */
|
|
1239
1253
|
declare const roundsToWarningOf: (arsenal: Pick<Arsenal, "weapons" | "calibers" | "rules">, weaponId: string) => number;
|
|
1240
1254
|
|
|
1255
|
+
/** The height of the ground under a point of the plane (a terrain, a floor, a heap): the surface an explosive in flight must not pass through. */
|
|
1256
|
+
type GroundHeight = (x: number, z: number) => number;
|
|
1257
|
+
type GroundSweepOptions = {
|
|
1258
|
+
/** Metres above the ground the body counts as touching it (its radius). Default 0. */
|
|
1259
|
+
readonly clearance?: number;
|
|
1260
|
+
/** Most metres between two heights read along the way. Default 0.1 (a cell of the terrain): a bump or the rim of a crater shorter than a fast round's step is still met. */
|
|
1261
|
+
readonly spacing?: number;
|
|
1262
|
+
};
|
|
1263
|
+
type GroundSweepHit = {
|
|
1264
|
+
readonly point: Vec3;
|
|
1265
|
+
readonly normal: Vec3;
|
|
1266
|
+
readonly ground: true;
|
|
1267
|
+
readonly distance: number;
|
|
1268
|
+
};
|
|
1269
|
+
/**
|
|
1270
|
+
* Where the segment `from` to `to` first goes under the ground, read every `spacing` metres along it and narrowed by halving, or null when it stays
|
|
1271
|
+
* above. Only the end of a step is not enough: a round that crosses a heap, a kerb or a crater rim within one frame would go through it.
|
|
1272
|
+
*/
|
|
1273
|
+
declare function sweepGround(from: Vec3, to: Vec3, groundAt: GroundHeight, options?: GroundSweepOptions): GroundSweepHit | null;
|
|
1274
|
+
|
|
1241
1275
|
interface BlastEffect {
|
|
1242
1276
|
/** `lethal` kills and dismembers, `injury` wounds, `none` is out of reach (or behind a directional charge). */
|
|
1243
1277
|
readonly zone: 'lethal' | 'injury' | 'none';
|
|
@@ -1401,4 +1435,4 @@ declare function genericWeapons(arsenal: Arsenal): ReadonlyMap<WeaponId, WeaponI
|
|
|
1401
1435
|
/** A loadout with each generic gun swapped for the real weapon that stands for it (dropped when none does), and no id twice. */
|
|
1402
1436
|
declare function realLoadout(arsenal: Arsenal, loadout: readonly WeaponId[]): WeaponId[];
|
|
1403
1437
|
|
|
1404
|
-
export { AMMO, ARCHETYPE_IDS, ATTACHMENTS, type AmmoCore, type AmmoDef, type AmmoJacket, type AmmoKind, type AmmoLoad, type AmmoPenetration, 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 Detonation, EXPLOSIVES, type EffectCondition, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveLeak, type ExplosiveShell, type ExplosiveSmoke, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, type IsCompatible, type Loadout, type LoadoutContext, MUZZLE_SMOKE, type MountDef, type MountKind, type MuzzleSmokeParams, type MuzzleSmokeProfile, type MuzzleSmokeProfileId, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type RoundsToWarningParams, type StatModifier, type StockDef, type StockState, type SurfaceProbe, type TriggerResult, type TripwireSegment, WEAPONS, WEAPON_MENU_GROUPS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponDimensions, type WeaponEvent, type WeaponId, type WeaponMenuEntry, type WeaponMenuGroup, type WeaponMenuGroupDef, type WeaponMenuOptions, type WeaponMenuSection, type WeaponPatch, type WeaponPhase, type WeaponRules, type WeaponSnapshot, type WeaponStance, type WeaponStat, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, aimZoomOf, ammoId, ammoIgnition, backblastEffect, barrelMassOf, blastEffect, canDualWield, canFit, canInstallWith, checkArsenal, coolingTimeConstant, createArsenal, createExplosiveBody, createRng, decayHeat, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, roundsToWarning, roundsToWarningOf, sampleFuse, tripwireSegment, weaponMenu };
|
|
1438
|
+
export { AMMO, ARCHETYPE_IDS, ATTACHMENTS, type AmmoCore, type AmmoDef, type AmmoJacket, type AmmoKind, type AmmoLoad, type AmmoPenetration, 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 Detonation, EXPLOSIVES, type EffectCondition, ExplosiveBody, type ExplosiveBodyInit, type ExplosiveChain, type ExplosiveDef, type ExplosiveEvent, type ExplosiveId, type ExplosiveLeak, type ExplosiveShell, type ExplosiveSmoke, type ExplosiveTrigger, type ExplosiveTripwire, type FaultContext, type FaultId, type FireMode, type FirearmAction, type FitOptions, type FitRefusal, type FitResult, type FittedAttachment, GALLERY_HEAT, type GroundHeight, type GroundSweepHit, type GroundSweepOptions, type IsCompatible, type Loadout, type LoadoutContext, MUZZLE_SMOKE, type MountDef, type MountKind, type MuzzleSmokeParams, type MuzzleSmokeProfile, type MuzzleSmokeProfileId, RELOAD_STAGES, type ReloadFamily, type ReloadKind, type ReloadRequest, type ReloadStage, type ReloadStageId, type RimType, type RoundsToWarningParams, type StatModifier, type StockDef, type StockState, type SurfaceProbe, type TriggerResult, type TripwireSegment, WEAPONS, WEAPON_MENU_GROUPS, type WeaponAction, type WeaponCategory, type WeaponDef, type WeaponDimensions, type WeaponEvent, type WeaponId, type WeaponMenuEntry, type WeaponMenuGroup, type WeaponMenuGroupDef, type WeaponMenuOptions, type WeaponMenuSection, type WeaponPatch, type WeaponPhase, type WeaponRules, type WeaponSnapshot, type WeaponStance, type WeaponStat, type WeaponState, type WeaponTimings, type WeaponsLocale, type WeaponsStrings, aimZoomOf, ammoId, ammoIgnition, backblastEffect, barrelMassOf, blastEffect, canDualWield, canFit, canInstallWith, checkArsenal, coolingTimeConstant, createArsenal, createExplosiveBody, createRng, decayHeat, genericWeapons, locales, muzzleEnergy, muzzleSmokeOf, nominalFuse, realLoadout, resolveLoad, resolveLoadout, resolveStrings, roundsToWarning, roundsToWarningOf, sampleFuse, sweepGround, tripwireSegment, weaponMenu };
|
package/dist/index.global.js
CHANGED
|
@@ -63,6 +63,7 @@ var GameWeapons = (() => {
|
|
|
63
63
|
roundsToWarning: () => roundsToWarning,
|
|
64
64
|
roundsToWarningOf: () => roundsToWarningOf,
|
|
65
65
|
sampleFuse: () => sampleFuse,
|
|
66
|
+
sweepGround: () => sweepGround,
|
|
66
67
|
tripwireSegment: () => tripwireSegment,
|
|
67
68
|
weaponMenu: () => weaponMenu
|
|
68
69
|
});
|
|
@@ -14768,7 +14769,7 @@ var GameWeapons = (() => {
|
|
|
14768
14769
|
heat: DEFAULT_HEAT,
|
|
14769
14770
|
noiseBurst: { step: 0.05, window: 3, cap: 0.5 },
|
|
14770
14771
|
// jogo.js (Jogo) explosionsUpdate 68300-68312: vy -= 9,8·dt; chão vy·-0,35 e vx,vz·0,6; parede v·-0,4
|
|
14771
|
-
explosives: { gravity: 9.8, groundRestitution: 0.35, groundFriction: 0.6, wallRestitution: 0.4, placeFuseFrom: 10, tripwire: { length: 10, angleDeg: 0, height: 0.15 } },
|
|
14772
|
+
explosives: { gravity: 9.8, groundRestitution: 0.35, groundFriction: 0.6, wallRestitution: 0.4, placeFuseFrom: 10, tripwire: { length: 10, angleDeg: 0, height: 0.15 }, unarmedImpact: "detonate", restSpeed: 0.5, selfDestructSeconds: 20 },
|
|
14772
14773
|
// Arsenal §11: montar e desmontar exige chave de fenda ou bancada; 2/15/30 s e a troca do lança-granadas (0,8 s) são padrões aprovados pelo dono (2026-10-24)
|
|
14773
14774
|
attachments: { fitSeconds: { field: 2, tool: 15, bench: 30 }, switchSeconds: 0.8, speedOfSound: 343 },
|
|
14774
14775
|
// Arsenal §08: tempo de mira = 0,15 s + 0,05 s por kg. O quadril do Arsenal é ×6 (o ZombiAdA liga isso por configuração); o SDK é neutro (1)
|
|
@@ -14821,6 +14822,8 @@ var GameWeapons = (() => {
|
|
|
14821
14822
|
|
|
14822
14823
|
// src/explosive-body.ts
|
|
14823
14824
|
var EPS = 1e-9;
|
|
14825
|
+
var STILL_STEPS = 2;
|
|
14826
|
+
var STILL_SHARE = 0.05;
|
|
14824
14827
|
var bounce = (velocity, normal, ground, rules) => {
|
|
14825
14828
|
const along = dot(velocity, normal);
|
|
14826
14829
|
if (along >= 0) return velocity;
|
|
@@ -14848,6 +14851,9 @@ var GameWeapons = (() => {
|
|
|
14848
14851
|
__publicField(this, "isArmed");
|
|
14849
14852
|
__publicField(this, "isDone", false);
|
|
14850
14853
|
__publicField(this, "isDud", false);
|
|
14854
|
+
/** Fired with a speed and an impact fuze (a rocket, a 40 mm grenade): it must end in a blast, never lie live on what it hit. */
|
|
14855
|
+
__publicField(this, "isLaunched");
|
|
14856
|
+
__publicField(this, "stillSteps", 0);
|
|
14851
14857
|
this.explosive = init.explosive;
|
|
14852
14858
|
this.position = [init.origin[0], init.origin[1], init.origin[2]];
|
|
14853
14859
|
this.velocity = init.velocity ? [init.velocity[0], init.velocity[1], init.velocity[2]] : [0, 0, 0];
|
|
@@ -14857,6 +14863,7 @@ var GameWeapons = (() => {
|
|
|
14857
14863
|
this.isArmed = this.armDistance <= 0;
|
|
14858
14864
|
this.fuseLeft = this.triggers.has("timer") ? init.fuse : void 0;
|
|
14859
14865
|
this.rules = init.rules;
|
|
14866
|
+
this.isLaunched = this.triggers.has("impact") && this.moves();
|
|
14860
14867
|
}
|
|
14861
14868
|
get age() {
|
|
14862
14869
|
return this.clock;
|
|
@@ -14886,6 +14893,10 @@ var GameWeapons = (() => {
|
|
|
14886
14893
|
const slice = this.fuseLeft === void 0 ? seconds : Math.min(seconds, this.fuseLeft);
|
|
14887
14894
|
this.fly(slice, probe, events);
|
|
14888
14895
|
if (this.isDone) return events;
|
|
14896
|
+
if (this.isLaunched && this.isSpent()) {
|
|
14897
|
+
events.push(this.detonate(this.clock >= this.rules.selfDestructSeconds ? "timer" : "impact"));
|
|
14898
|
+
return events;
|
|
14899
|
+
}
|
|
14889
14900
|
if (this.fuseLeft !== void 0) {
|
|
14890
14901
|
this.fuseLeft -= slice;
|
|
14891
14902
|
if (this.fuseLeft <= EPS) events.push(this.detonate("timer"));
|
|
@@ -14901,11 +14912,17 @@ var GameWeapons = (() => {
|
|
|
14901
14912
|
moves() {
|
|
14902
14913
|
return length(this.velocity) > EPS;
|
|
14903
14914
|
}
|
|
14915
|
+
/** A launched round that came to rest (stopped, or still for `STILL_STEPS` steps) or flew past its self-destruct time. */
|
|
14916
|
+
isSpent() {
|
|
14917
|
+
if (this.clock >= this.rules.selfDestructSeconds) return true;
|
|
14918
|
+
return !this.moves() || this.stillSteps >= STILL_STEPS;
|
|
14919
|
+
}
|
|
14904
14920
|
fly(seconds, probe, events) {
|
|
14905
14921
|
if (seconds <= 0 || !this.moves()) {
|
|
14906
14922
|
this.clock += Math.max(0, seconds);
|
|
14907
14923
|
return;
|
|
14908
14924
|
}
|
|
14925
|
+
const start = this.position;
|
|
14909
14926
|
this.velocity = [this.velocity[0], this.velocity[1] - this.rules.gravity * seconds, this.velocity[2]];
|
|
14910
14927
|
const next = [this.position[0] + this.velocity[0] * seconds, this.position[1] + this.velocity[1] * seconds, this.position[2] + this.velocity[2] * seconds];
|
|
14911
14928
|
const hit = probe?.(this.position, next) ?? null;
|
|
@@ -14914,11 +14931,12 @@ var GameWeapons = (() => {
|
|
|
14914
14931
|
const planned = distance(this.position, next);
|
|
14915
14932
|
this.flown += moved;
|
|
14916
14933
|
this.position = [target[0], target[1], target[2]];
|
|
14917
|
-
const
|
|
14934
|
+
const hitAt2 = this.clock + (hit && planned > EPS ? seconds * Math.min(1, moved / planned) : seconds);
|
|
14918
14935
|
this.clock += seconds;
|
|
14919
14936
|
if (length(this.velocity) > EPS) this.facing = normalize(this.velocity);
|
|
14937
|
+
this.stillSteps = distance(start, this.position) < this.rules.restSpeed * STILL_SHARE * seconds ? this.stillSteps + 1 : 0;
|
|
14920
14938
|
this.checkArmed(events);
|
|
14921
|
-
if (hit) this.onImpact(hit,
|
|
14939
|
+
if (hit) this.onImpact(hit, hitAt2, events);
|
|
14922
14940
|
}
|
|
14923
14941
|
checkArmed(events) {
|
|
14924
14942
|
if (this.isArmed || this.flown < this.armDistance) return;
|
|
@@ -14928,7 +14946,7 @@ var GameWeapons = (() => {
|
|
|
14928
14946
|
onImpact(hit, at, events) {
|
|
14929
14947
|
events.push({ type: "impact", at, point: hit.point, armed: this.isArmed });
|
|
14930
14948
|
if (this.triggers.has("impact")) {
|
|
14931
|
-
if (this.isArmed) events.push(this.detonate("impact", at));
|
|
14949
|
+
if (this.isArmed || this.rules.unarmedImpact !== "dud") events.push(this.detonate("impact", at));
|
|
14932
14950
|
else {
|
|
14933
14951
|
this.isDone = true;
|
|
14934
14952
|
this.isDud = true;
|
|
@@ -16448,6 +16466,44 @@ ${problems.map((problem) => ` - ${problem}`).join("\n")}`);
|
|
|
16448
16466
|
};
|
|
16449
16467
|
};
|
|
16450
16468
|
|
|
16469
|
+
// src/ground-sweep.ts
|
|
16470
|
+
var BISECTIONS = 10;
|
|
16471
|
+
var SLOPE_STEP = 0.1;
|
|
16472
|
+
var lerp = (from, to, k) => [from[0] + (to[0] - from[0]) * k, from[1] + (to[1] - from[1]) * k, from[2] + (to[2] - from[2]) * k];
|
|
16473
|
+
var groundNormal = (groundAt, x, z) => {
|
|
16474
|
+
const slopeX = (groundAt(x + SLOPE_STEP, z) - groundAt(x - SLOPE_STEP, z)) / (2 * SLOPE_STEP);
|
|
16475
|
+
const slopeZ = (groundAt(x, z + SLOPE_STEP) - groundAt(x, z - SLOPE_STEP)) / (2 * SLOPE_STEP);
|
|
16476
|
+
const size = Math.hypot(slopeX, 1, slopeZ);
|
|
16477
|
+
return [-slopeX / size, 1 / size, -slopeZ / size];
|
|
16478
|
+
};
|
|
16479
|
+
function sweepGround(from, to, groundAt, options = {}) {
|
|
16480
|
+
const clearance = options.clearance ?? 0;
|
|
16481
|
+
const below = (point) => point[1] < groundAt(point[0], point[2]) + clearance;
|
|
16482
|
+
const length2 = Math.hypot(to[0] - from[0], to[1] - from[1], to[2] - from[2]);
|
|
16483
|
+
const samples = Math.max(1, Math.ceil(length2 / (options.spacing ?? 0.1)));
|
|
16484
|
+
let above = 0;
|
|
16485
|
+
if (below(from)) return hitAt(from, from, groundAt, clearance);
|
|
16486
|
+
for (let index = 1; index <= samples; index++) {
|
|
16487
|
+
const k = index / samples;
|
|
16488
|
+
if (!below(lerp(from, to, k))) {
|
|
16489
|
+
above = k;
|
|
16490
|
+
continue;
|
|
16491
|
+
}
|
|
16492
|
+
let high = k;
|
|
16493
|
+
for (let step = 0; step < BISECTIONS; step++) {
|
|
16494
|
+
const middle = (above + high) / 2;
|
|
16495
|
+
if (below(lerp(from, to, middle))) high = middle;
|
|
16496
|
+
else above = middle;
|
|
16497
|
+
}
|
|
16498
|
+
return hitAt(from, lerp(from, to, high), groundAt, clearance);
|
|
16499
|
+
}
|
|
16500
|
+
return null;
|
|
16501
|
+
}
|
|
16502
|
+
var hitAt = (from, at, groundAt, clearance) => {
|
|
16503
|
+
const point = [at[0], groundAt(at[0], at[2]) + clearance, at[2]];
|
|
16504
|
+
return { point, normal: groundNormal(groundAt, at[0], at[2]), ground: true, distance: Math.hypot(point[0] - from[0], point[1] - from[1], point[2] - from[2]) };
|
|
16505
|
+
};
|
|
16506
|
+
|
|
16451
16507
|
// src/explosive-effect.ts
|
|
16452
16508
|
var OUT_OF_REACH = { zone: "none", distance: Infinity, falloff: 0, stunSeconds: 0 };
|
|
16453
16509
|
var insideCone = (offset, facing, halfAngleDeg) => {
|