quake2ts 0.0.489 → 0.0.491

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.
@@ -10370,6 +10370,49 @@ function setFlagState(flag, newState, context) {
10370
10370
  flag.flagState = newState;
10371
10371
  }
10372
10372
 
10373
+ // src/modes/ctf/capture.ts
10374
+ function checkCapture(flag, player, game, context) {
10375
+ if (!player.client) return false;
10376
+ const playerTeam = player.client.team || "red";
10377
+ if (flag.flagTeam !== playerTeam) {
10378
+ return false;
10379
+ }
10380
+ if (flag.flagState !== 0 /* AT_BASE */) {
10381
+ return false;
10382
+ }
10383
+ const enemyFlagKey = playerTeam === "red" ? "key_blue_flag" /* BlueFlag */ : "key_red_flag" /* RedFlag */;
10384
+ if (hasKey(player.client.inventory, enemyFlagKey)) {
10385
+ return captureFlag(flag, player, game, context);
10386
+ }
10387
+ return false;
10388
+ }
10389
+ function captureFlag(ownFlag, player, game, context) {
10390
+ if (!player.client) return false;
10391
+ const playerTeam = player.client.team || "red";
10392
+ const enemyTeam = playerTeam === "red" ? "blue" : "red";
10393
+ if (player.client.score !== void 0) {
10394
+ player.client.score += 5;
10395
+ } else {
10396
+ player.client.score = 5;
10397
+ }
10398
+ game.sound?.(player, 0, "ctf/flagcap.wav", 1, 1, 0);
10399
+ game.centerprintf?.(player, "You captured the flag!");
10400
+ const enemyFlagKey = playerTeam === "red" ? "key_blue_flag" /* BlueFlag */ : "key_red_flag" /* RedFlag */;
10401
+ player.client.inventory.keys.delete(enemyFlagKey);
10402
+ context.forEachEntity((ent) => {
10403
+ const flag = ent;
10404
+ if ((flag.classname === "item_flag_team1" || flag.classname === "item_flag_team2") && flag.flagTeam === enemyTeam) {
10405
+ setFlagState(flag, 0 /* AT_BASE */, context);
10406
+ flag.origin = { ...flag.baseOrigin };
10407
+ flag.solid = 1 /* Trigger */;
10408
+ flag.owner = null;
10409
+ flag.model = flag.flagTeam === "red" ? "players/male/flag1.md2" : "players/male/flag2.md2";
10410
+ flag.svflags &= ~1;
10411
+ }
10412
+ });
10413
+ return true;
10414
+ }
10415
+
10373
10416
  // src/modes/ctf/flag.ts
10374
10417
  function createFlagPickupEntity(game, flagItem) {
10375
10418
  const isRed = flagItem.team === "red";
@@ -10404,6 +10447,9 @@ function createFlagPickupEntity(game, flagItem) {
10404
10447
  const sameTeam = self.flagTeam === playerTeam;
10405
10448
  if (sameTeam) {
10406
10449
  if (self.flagState === 0 /* AT_BASE */) {
10450
+ if (checkCapture(self, other, game, game.entities)) {
10451
+ return;
10452
+ }
10407
10453
  return;
10408
10454
  }
10409
10455
  if (self.flagState === 2 /* DROPPED */) {