|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import type { Game } from "../src/game"; |
| 3 | +declare global { |
| 4 | + interface Window { |
| 5 | + __game: Game; |
| 6 | + } |
| 7 | +} |
| 8 | +test("AK headshot damage on the native A-site ramp line", async ({ page }) => { |
| 9 | + test.setTimeout(180000); |
| 10 | + await page.goto("/"); |
| 11 | + await expect(page.locator("#play")).toBeEnabled({ timeout: 120000 }); |
| 12 | + await page.locator("#play").evaluate((button) => { |
| 13 | + button.onclick = () => window.__game.start("practice"); |
| 14 | + }); |
| 15 | + await page.locator("#home-play").click(); |
| 16 | + await page.locator("#play").click(); |
| 17 | + await page.waitForFunction(() => window.__game.locked); |
| 18 | + await page.waitForLoadState("networkidle"); |
| 19 | + const result = await page.evaluate(() => { |
| 20 | + const g = window.__game; |
| 21 | + g.freezeTime = 0; |
| 22 | + g.roundPause = 10000; |
| 23 | + g.health = 1e6; |
| 24 | + g.updateBots = () => {}; |
| 25 | + g.moveBots = () => {}; |
| 26 | + g.bots.forEach((bot) => { |
| 27 | + bot.group.position.x += 100; |
| 28 | + }); |
| 29 | + g.buy(0); |
| 30 | + g.reload = g.drawTime = g.cooldown = 0; |
| 31 | + const victim = g.bots.find((bot) => bot.team !== g.team)!; |
| 32 | + const victimIndex = g.bots.indexOf(victim); |
| 33 | + const hits: { damage: number; head: boolean | undefined }[] = []; |
| 34 | + const damage = g.damageActor.bind(g); |
| 35 | + g.damageActor = (actor, amount, data, ...rest) => { |
| 36 | + hits.push({ damage: amount, head: data.head }); |
| 37 | + damage(actor, amount, data, ...rest); |
| 38 | + }; |
| 39 | + const sounds: string[] = []; |
| 40 | + g.sound = (cue) => { |
| 41 | + sounds.push(cue); |
| 42 | + }; |
| 43 | + const nav = g.dust!.navigation; |
| 44 | + const rows = []; |
| 45 | + for (const source of [1902, 1930, 1952]) |
| 46 | + for (const target of [1896, 1905, 1938]) { |
| 47 | + const from = nav.areas.find((area) => area.id === source)!.center; |
| 48 | + const to = nav.areas.find((area) => area.id === target)!.center; |
| 49 | + g.position.fromArray(from); |
| 50 | + g.velocity.x = g.velocity.z = 0; |
| 51 | + g.vertical = 0; |
| 52 | + g.eye = 1.65; |
| 53 | + victim.health = 100; |
| 54 | + victim.armor = 100; |
| 55 | + victim.helmet = true; |
| 56 | + victim.group.position.fromArray(to); |
| 57 | + victim.group.updateMatrixWorld(true); |
| 58 | + const head = victim.rig.head.getWorldPosition(g.position.clone()); |
| 59 | + head.y += 0.04; |
| 60 | + const eye = g.position.clone(); |
| 61 | + eye.y += g.eye; |
| 62 | + const direction = head.clone().sub(eye).normalize(); |
| 63 | + g.yaw = Math.atan2(-direction.x, -direction.z); |
| 64 | + g.pitch = Math.asin(direction.y); |
| 65 | + g.aimPunch.pitch = g.aimPunch.yaw = 0; |
| 66 | + g.weaponRecoil[0].index = 0; |
| 67 | + g.ammo = 30; |
| 68 | + g.cooldown = g.drawTime = g.shotTime = 0; |
| 69 | + g.ray.set(eye, direction); |
| 70 | + g.ray.far = eye.distanceTo(head) + 0.5; |
| 71 | + const cover = g.dust!.collision.intersections(g.ray.ray, g.ray.far).map((impact) => ({ |
| 72 | + distance: impact.distance, |
| 73 | + material: impact.object.userData.bulletMaterial, |
| 74 | + name: impact.object.name, |
| 75 | + })); |
| 76 | + hits.length = sounds.length = 0; |
| 77 | + const random = Math.random; |
| 78 | + Math.random = () => 0; |
| 79 | + try { |
| 80 | + g.fire(); |
| 81 | + } finally { |
| 82 | + Math.random = random; |
| 83 | + } |
| 84 | + rows.push({ |
| 85 | + source, |
| 86 | + target, |
| 87 | + distance: eye.distanceTo(head), |
| 88 | + cover, |
| 89 | + hits: [...hits], |
| 90 | + sounds: [...sounds], |
| 91 | + health: victim.health, |
| 92 | + victimIndex, |
| 93 | + }); |
| 94 | + } |
| 95 | + return rows; |
| 96 | + }); |
| 97 | + console.log("A-SITE DAMAGE AUDIT", JSON.stringify(result)); |
| 98 | + const clear = result.filter((row) => row.cover.length === 0 && row.hits.some((hit) => hit.head)); |
| 99 | + expect(clear.length).toBeGreaterThan(0); |
| 100 | + for (const row of clear) expect(row.health, JSON.stringify(row)).toBe(0); |
| 101 | + const utility = await page.evaluate(() => { |
| 102 | + const g = window.__game, |
| 103 | + victim = g.bots.find((bot) => bot.team !== g.team)!; |
| 104 | + victim.group.position.copy(g.position).x += 2; |
| 105 | + g.visible = () => true; |
| 106 | + return ["he", "decoy", "molotov", "incendiary"].map((kind) => { |
| 107 | + victim.health = 100; |
| 108 | + victim.armor = kind === "he" || kind === "decoy" ? 0 : 100; |
| 109 | + const position = victim.group.position.clone(); |
| 110 | + position.y += 0.8; |
| 111 | + g.utility.areaDamage( |
| 112 | + { |
| 113 | + kind, |
| 114 | + owner: "player", |
| 115 | + team: g.team, |
| 116 | + position, |
| 117 | + cells: [victim.group.position.clone()], |
| 118 | + } as never, |
| 119 | + 2.9, |
| 120 | + 1.5, |
| 121 | + ); |
| 122 | + return { kind, health: victim.health, armor: victim.armor }; |
| 123 | + }); |
| 124 | + }); |
| 125 | + expect(utility).toEqual([ |
| 126 | + { kind: "he", health: 98, armor: 0 }, |
| 127 | + { kind: "decoy", health: 98, armor: 0 }, |
| 128 | + { kind: "molotov", health: 98, armor: 100 }, |
| 129 | + { kind: "incendiary", health: 98, armor: 100 }, |
| 130 | + ]); |
| 131 | +}); |
0 commit comments