quake2ts 0.0.505 → 0.0.506

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.
@@ -8937,12 +8937,12 @@ function registerTriggerSpawns(registry) {
8937
8937
  }
8938
8938
 
8939
8939
  // src/combat/weapons/state.ts
8940
- var WeaponStateEnum = /* @__PURE__ */ ((WeaponStateEnum2) => {
8941
- WeaponStateEnum2[WeaponStateEnum2["WEAPON_READY"] = 0] = "WEAPON_READY";
8942
- WeaponStateEnum2[WeaponStateEnum2["WEAPON_ACTIVATING"] = 1] = "WEAPON_ACTIVATING";
8943
- WeaponStateEnum2[WeaponStateEnum2["WEAPON_DROPPING"] = 2] = "WEAPON_DROPPING";
8944
- WeaponStateEnum2[WeaponStateEnum2["WEAPON_FIRING"] = 3] = "WEAPON_FIRING";
8945
- return WeaponStateEnum2;
8940
+ var WeaponStateEnum = /* @__PURE__ */ ((WeaponStateEnum3) => {
8941
+ WeaponStateEnum3[WeaponStateEnum3["WEAPON_READY"] = 0] = "WEAPON_READY";
8942
+ WeaponStateEnum3[WeaponStateEnum3["WEAPON_ACTIVATING"] = 1] = "WEAPON_ACTIVATING";
8943
+ WeaponStateEnum3[WeaponStateEnum3["WEAPON_DROPPING"] = 2] = "WEAPON_DROPPING";
8944
+ WeaponStateEnum3[WeaponStateEnum3["WEAPON_FIRING"] = 3] = "WEAPON_FIRING";
8945
+ return WeaponStateEnum3;
8946
8946
  })(WeaponStateEnum || {});
8947
8947
  function createPlayerWeaponStates() {
8948
8948
  return {
@@ -9047,6 +9047,106 @@ var ANIM_ATTACK = 1;
9047
9047
  var ANIM_PAIN = 2;
9048
9048
  var ANIM_DEATH = 3;
9049
9049
 
9050
+ // src/combat/weapons/switching.ts
9051
+ var instantSwitch = false;
9052
+ function getWeaponIdleLastFrame(weaponId) {
9053
+ switch (weaponId) {
9054
+ case WeaponId.HandGrenade:
9055
+ return FRAME_GRENADE_IDLE_LAST;
9056
+ case WeaponId.Shotgun:
9057
+ return FRAME_SHOTGUN_IDLE_LAST;
9058
+ case WeaponId.SuperShotgun:
9059
+ return FRAME_SSHOTGUN_IDLE_LAST;
9060
+ case WeaponId.Machinegun:
9061
+ return FRAME_MACHINEGUN_IDLE_LAST;
9062
+ case WeaponId.Chaingun:
9063
+ return FRAME_CHAINGUN_IDLE_LAST;
9064
+ case WeaponId.Railgun:
9065
+ return FRAME_RAILGUN_IDLE_LAST;
9066
+ case WeaponId.RocketLauncher:
9067
+ return FRAME_ROCKET_IDLE_LAST;
9068
+ case WeaponId.HyperBlaster:
9069
+ return FRAME_HYPERBLASTER_IDLE_LAST;
9070
+ case WeaponId.BFG10K:
9071
+ return FRAME_BFG_IDLE_LAST;
9072
+ case WeaponId.GrenadeLauncher:
9073
+ return FRAME_GRENADELAUNCHER_IDLE_LAST;
9074
+ case WeaponId.Blaster:
9075
+ return FRAME_BLASTER_IDLE_LAST;
9076
+ default:
9077
+ return 0;
9078
+ }
9079
+ }
9080
+ function ChangeWeapon(ent, weaponId) {
9081
+ if (!ent.client) return;
9082
+ const client = ent.client;
9083
+ if (weaponId) {
9084
+ if (client.weaponstate === 2 /* WEAPON_DROPPING */) {
9085
+ client.newWeapon = weaponId;
9086
+ return;
9087
+ }
9088
+ if (client.weaponstate === 0 /* WEAPON_READY */ || client.weaponstate === 3 /* WEAPON_FIRING */) {
9089
+ client.newWeapon = weaponId;
9090
+ client.weaponstate = 2 /* WEAPON_DROPPING */;
9091
+ if (client.inventory.currentWeapon) {
9092
+ client.gun_frame = getWeaponIdleLastFrame(client.inventory.currentWeapon) + 1;
9093
+ } else {
9094
+ client.gun_frame = 0;
9095
+ }
9096
+ if (instantSwitch) {
9097
+ selectWeapon(client.inventory, weaponId);
9098
+ client.weaponstate = 0 /* WEAPON_READY */;
9099
+ client.weapon_think_time = 0;
9100
+ client.newWeapon = void 0;
9101
+ }
9102
+ return;
9103
+ }
9104
+ client.newWeapon = weaponId;
9105
+ return;
9106
+ }
9107
+ if (client.newWeapon) {
9108
+ selectWeapon(client.inventory, client.newWeapon);
9109
+ client.weaponstate = 1 /* WEAPON_ACTIVATING */;
9110
+ client.gun_frame = 0;
9111
+ client.weapon_think_time = 0;
9112
+ client.newWeapon = void 0;
9113
+ }
9114
+ }
9115
+ function NoAmmoWeaponChange(ent) {
9116
+ if (!ent.client) return;
9117
+ const bestWeapon = getBestWeapon(ent);
9118
+ if (bestWeapon && bestWeapon !== ent.client.inventory.currentWeapon) {
9119
+ ChangeWeapon(ent, bestWeapon);
9120
+ }
9121
+ }
9122
+ function getBestWeapon(player) {
9123
+ if (!player.client) {
9124
+ return null;
9125
+ }
9126
+ const inventory = player.client.inventory;
9127
+ if (inventory.ownedWeapons.has(WeaponId.BFG10K) && inventory.ammo.counts[AmmoType.Cells] >= 50) {
9128
+ return WeaponId.BFG10K;
9129
+ } else if (inventory.ownedWeapons.has(WeaponId.RocketLauncher) && inventory.ammo.counts[AmmoType.Rockets] >= 1) {
9130
+ return WeaponId.RocketLauncher;
9131
+ } else if (inventory.ownedWeapons.has(WeaponId.HyperBlaster) && inventory.ammo.counts[AmmoType.Cells] >= 1) {
9132
+ return WeaponId.HyperBlaster;
9133
+ } else if (inventory.ownedWeapons.has(WeaponId.Railgun) && inventory.ammo.counts[AmmoType.Slugs] >= 1) {
9134
+ return WeaponId.Railgun;
9135
+ } else if (inventory.ownedWeapons.has(WeaponId.Chaingun) && inventory.ammo.counts[AmmoType.Bullets] >= 1) {
9136
+ return WeaponId.Chaingun;
9137
+ } else if (inventory.ownedWeapons.has(WeaponId.GrenadeLauncher) && inventory.ammo.counts[AmmoType.Grenades] >= 1) {
9138
+ return WeaponId.GrenadeLauncher;
9139
+ } else if (inventory.ownedWeapons.has(WeaponId.SuperShotgun) && inventory.ammo.counts[AmmoType.Shells] >= 2) {
9140
+ return WeaponId.SuperShotgun;
9141
+ } else if (inventory.ownedWeapons.has(WeaponId.Machinegun) && inventory.ammo.counts[AmmoType.Bullets] >= 1) {
9142
+ return WeaponId.Machinegun;
9143
+ } else if (inventory.ownedWeapons.has(WeaponId.Shotgun) && inventory.ammo.counts[AmmoType.Shells] >= 1) {
9144
+ return WeaponId.Shotgun;
9145
+ } else {
9146
+ return WeaponId.Blaster;
9147
+ }
9148
+ }
9149
+
9050
9150
  // src/combat/weapons/firing.ts
9051
9151
  var random3 = createRandomGenerator();
9052
9152
  var DEFAULT_SHOTGUN_HSPREAD = 500;
@@ -9075,6 +9175,15 @@ function setPlayerAttackAnim(player) {
9075
9175
  player.client.anim_end = FRAME_attack8;
9076
9176
  }
9077
9177
  }
9178
+ function checkAmmo(game, player, ammoType, count) {
9179
+ if (!player.client) return false;
9180
+ if (player.client.inventory.ammo.counts[ammoType] < count) {
9181
+ game.sound(player, 0, "weapons/noammo.wav", 1, ATTN_NORM, 0);
9182
+ NoAmmoWeaponChange(player);
9183
+ return false;
9184
+ }
9185
+ return true;
9186
+ }
9078
9187
  function fireHitscan(game, player, start, forward, damage, knockback, mod) {
9079
9188
  const end = { x: start.x + forward.x * 8192, y: start.y + forward.y * 8192, z: start.z + forward.z * 8192 };
9080
9189
  if (game.setLagCompensation && player.client) {
@@ -9209,9 +9318,7 @@ function fireRailgun(game, player, start, forward, damage, knockback) {
9209
9318
  function fireShotgun(game, player) {
9210
9319
  if (!player.client) return;
9211
9320
  const inventory = player.client.inventory;
9212
- if (inventory.ammo.counts[AmmoType.Shells] < 1) {
9213
- return;
9214
- }
9321
+ if (!checkAmmo(game, player, AmmoType.Shells, 1)) return;
9215
9322
  inventory.ammo.counts[AmmoType.Shells]--;
9216
9323
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_SHOTGUN);
9217
9324
  applyKick(player, -2, 0, -2);
@@ -9224,9 +9331,7 @@ function fireShotgun(game, player) {
9224
9331
  function fireSuperShotgun(game, player) {
9225
9332
  if (!player.client) return;
9226
9333
  const inventory = player.client.inventory;
9227
- if (inventory.ammo.counts[AmmoType.Shells] < 2) {
9228
- return;
9229
- }
9334
+ if (!checkAmmo(game, player, AmmoType.Shells, 2)) return;
9230
9335
  const isPrecision = (player.client.buttons & BUTTON_ATTACK2) !== 0;
9231
9336
  inventory.ammo.counts[AmmoType.Shells] -= 2;
9232
9337
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_SSHOTGUN);
@@ -9251,9 +9356,7 @@ function fireSuperShotgun(game, player) {
9251
9356
  function fireMachinegun(game, player) {
9252
9357
  if (!player.client) return;
9253
9358
  const inventory = player.client.inventory;
9254
- if (inventory.ammo.counts[AmmoType.Bullets] < 1) {
9255
- return;
9256
- }
9359
+ if (!checkAmmo(game, player, AmmoType.Bullets, 1)) return;
9257
9360
  inventory.ammo.counts[AmmoType.Bullets]--;
9258
9361
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_MACHINEGUN);
9259
9362
  applyKick(player, -1, random3.crandom() * 0.5, 0);
@@ -9289,6 +9392,7 @@ function fireChaingun(game, player) {
9289
9392
  shots = inventory.ammo.counts[AmmoType.Bullets];
9290
9393
  }
9291
9394
  if (shots === 0) {
9395
+ if (!checkAmmo(game, player, AmmoType.Bullets, 1)) return;
9292
9396
  return;
9293
9397
  }
9294
9398
  inventory.ammo.counts[AmmoType.Bullets] -= shots;
@@ -9313,9 +9417,7 @@ function fireChaingun(game, player) {
9313
9417
  function fireRailgunShot(game, player) {
9314
9418
  if (!player.client) return;
9315
9419
  const inventory = player.client.inventory;
9316
- if (inventory.ammo.counts[AmmoType.Slugs] < 1) {
9317
- return;
9318
- }
9420
+ if (!checkAmmo(game, player, AmmoType.Slugs, 1)) return;
9319
9421
  inventory.ammo.counts[AmmoType.Slugs]--;
9320
9422
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_RAILGUN);
9321
9423
  applyKick(player, -3, 0, -3);
@@ -9329,9 +9431,7 @@ function fireRailgunShot(game, player) {
9329
9431
  function fireHyperBlaster(game, player) {
9330
9432
  if (!player.client) return;
9331
9433
  const inventory = player.client.inventory;
9332
- if (inventory.ammo.counts[AmmoType.Cells] < 1) {
9333
- return;
9334
- }
9434
+ if (!checkAmmo(game, player, AmmoType.Cells, 1)) return;
9335
9435
  inventory.ammo.counts[AmmoType.Cells]--;
9336
9436
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_HYPERBLASTER);
9337
9437
  applyKick(player, -0.5, 0, 0);
@@ -9390,9 +9490,7 @@ function fireBlaster(game, player) {
9390
9490
  function fireRocket(game, player) {
9391
9491
  if (!player.client) return;
9392
9492
  const inventory = player.client.inventory;
9393
- if (inventory.ammo.counts[AmmoType.Rockets] < 1) {
9394
- return;
9395
- }
9493
+ if (!checkAmmo(game, player, AmmoType.Rockets, 1)) return;
9396
9494
  inventory.ammo.counts[AmmoType.Rockets]--;
9397
9495
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_ROCKET);
9398
9496
  applyKick(player, -2, 0, -2);
@@ -9410,9 +9508,7 @@ function fireRocket(game, player) {
9410
9508
  function fireGrenadeLauncher(game, player, timer) {
9411
9509
  if (!player.client) return;
9412
9510
  const inventory = player.client.inventory;
9413
- if (inventory.ammo.counts[AmmoType.Grenades] < 1) {
9414
- return;
9415
- }
9511
+ if (!checkAmmo(game, player, AmmoType.Grenades, 1)) return;
9416
9512
  inventory.ammo.counts[AmmoType.Grenades]--;
9417
9513
  game.multicast(player.origin, 1 /* Pvs */, ServerCommand.muzzleflash, player.index, MZ_GRENADE);
9418
9514
  applyKick(player, -2, 0, -2);
@@ -9424,9 +9520,7 @@ function fireGrenadeLauncher(game, player, timer) {
9424
9520
  function fireHyperBlasterBeam(game, player, weaponState) {
9425
9521
  if (!player.client) return;
9426
9522
  const inventory = player.client.inventory;
9427
- if (inventory.ammo.counts[AmmoType.Cells] < 2) {
9428
- return;
9429
- }
9523
+ if (!checkAmmo(game, player, AmmoType.Cells, 2)) return;
9430
9524
  if ((weaponState.heat || 0) > 20) {
9431
9525
  game.sound(player, 0, "weapons/lashit.wav", 1, 1, 0);
9432
9526
  return;
@@ -9474,9 +9568,7 @@ function fireBFG(game, player) {
9474
9568
  const isPrimeFrame = gun_frame === 9 || gun_frame === 0 || gun_frame === void 0;
9475
9569
  const isFireFrame = gun_frame === 22 || gun_frame === 0 || gun_frame === void 0;
9476
9570
  if (isPrimeFrame) {
9477
- if (inventory.ammo.counts[AmmoType.Cells] < 50) {
9478
- return;
9479
- }
9571
+ if (!checkAmmo(game, player, AmmoType.Cells, 50)) return;
9480
9572
  inventory.ammo.counts[AmmoType.Cells] -= 50;
9481
9573
  game.sound(player, 0, "weapons/bfg__f1y.wav", 1, 0, 0);
9482
9574
  }
@@ -9492,72 +9584,6 @@ function fireBFG(game, player) {
9492
9584
  }
9493
9585
  }
9494
9586
 
9495
- // src/combat/weapons/switching.ts
9496
- var instantSwitch = false;
9497
- function getWeaponIdleLastFrame(weaponId) {
9498
- switch (weaponId) {
9499
- case WeaponId.HandGrenade:
9500
- return FRAME_GRENADE_IDLE_LAST;
9501
- case WeaponId.Shotgun:
9502
- return FRAME_SHOTGUN_IDLE_LAST;
9503
- case WeaponId.SuperShotgun:
9504
- return FRAME_SSHOTGUN_IDLE_LAST;
9505
- case WeaponId.Machinegun:
9506
- return FRAME_MACHINEGUN_IDLE_LAST;
9507
- case WeaponId.Chaingun:
9508
- return FRAME_CHAINGUN_IDLE_LAST;
9509
- case WeaponId.Railgun:
9510
- return FRAME_RAILGUN_IDLE_LAST;
9511
- case WeaponId.RocketLauncher:
9512
- return FRAME_ROCKET_IDLE_LAST;
9513
- case WeaponId.HyperBlaster:
9514
- return FRAME_HYPERBLASTER_IDLE_LAST;
9515
- case WeaponId.BFG10K:
9516
- return FRAME_BFG_IDLE_LAST;
9517
- case WeaponId.GrenadeLauncher:
9518
- return FRAME_GRENADELAUNCHER_IDLE_LAST;
9519
- case WeaponId.Blaster:
9520
- return FRAME_BLASTER_IDLE_LAST;
9521
- default:
9522
- return 0;
9523
- }
9524
- }
9525
- function ChangeWeapon(ent, weaponId) {
9526
- if (!ent.client) return;
9527
- const client = ent.client;
9528
- if (weaponId) {
9529
- if (client.weaponstate === 2 /* WEAPON_DROPPING */) {
9530
- client.newWeapon = weaponId;
9531
- return;
9532
- }
9533
- if (client.weaponstate === 0 /* WEAPON_READY */ || client.weaponstate === 3 /* WEAPON_FIRING */) {
9534
- client.newWeapon = weaponId;
9535
- client.weaponstate = 2 /* WEAPON_DROPPING */;
9536
- if (client.inventory.currentWeapon) {
9537
- client.gun_frame = getWeaponIdleLastFrame(client.inventory.currentWeapon) + 1;
9538
- } else {
9539
- client.gun_frame = 0;
9540
- }
9541
- if (instantSwitch) {
9542
- selectWeapon(client.inventory, weaponId);
9543
- client.weaponstate = 0 /* WEAPON_READY */;
9544
- client.weapon_think_time = 0;
9545
- client.newWeapon = void 0;
9546
- }
9547
- return;
9548
- }
9549
- client.newWeapon = weaponId;
9550
- return;
9551
- }
9552
- if (client.newWeapon) {
9553
- selectWeapon(client.inventory, client.newWeapon);
9554
- client.weaponstate = 1 /* WEAPON_ACTIVATING */;
9555
- client.gun_frame = 0;
9556
- client.weapon_think_time = 0;
9557
- client.newWeapon = void 0;
9558
- }
9559
- }
9560
-
9561
9587
  // src/combat/weapons/common.ts
9562
9588
  function applyKick2(player, pitch, yaw = 0, kickOrigin = 0) {
9563
9589
  if (player.client) {
@@ -10789,6 +10815,7 @@ function createItemRespawnFunction(game, originalModel) {
10789
10815
  self.modelindex = cachedIndex;
10790
10816
  self.svflags &= ~1 /* NoClient */;
10791
10817
  game.multicast(self.origin, 1 /* Pvs */, ServerCommand.sound, 0, "items/respawn.wav", 1, 0, 0);
10818
+ game.multicast(self.origin, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.TELEPORT_EFFECT, self.origin);
10792
10819
  };
10793
10820
  }
10794
10821