import { expect, test } from "bun:test"; import { AGENTS, agentById, buyableSlots, cast, castable, flashDuration, sightBlocked, SLOTS } from "./abilities.ts"; import { newMatch, startRound, tick } from "./match.ts"; import type { MatchState, Player, Zone } from "./state.ts"; const live = (): MatchState => { const state = newMatch(11); state.phase = "live"; state.clock = 100; return state; }; const attacker = (state: MatchState): Player => state.players.find((p) => p.side === "atk")!; test("every agent has two bought basics, a free signature and an ultimate", () => { expect(AGENTS.length).toBe(5); for (const agent of AGENTS) { for (const slot of SLOTS) expect(agent.abilities[slot].name.length).toBeGreaterThan(0); for (const slot of buyableSlots) expect(agent.abilities[slot].cost).toBeGreaterThan(0); expect(agent.abilities.e.cost).toBe(0); expect(agent.abilities.e.cooldown).toBeGreaterThan(0); expect(agent.abilities.x.points).toBeGreaterThanOrEqual(6); } }); test("a flash blinds by the angle you were facing", () => { const at = { x: 1000, y: 1000 }; const staring = { x: 1200, y: 1000 }; const facingIt = Math.PI; // looking back down the line at the flash const facingAway = 0; expect(flashDuration(1.7, staring, at, facingIt, false)).toBeGreaterThan(1.6); expect(flashDuration(1.7, staring, at, facingAway, false)).toBe(0); // Half turned away is a shorter blind than staring straight at it. const glance = flashDuration(1.7, staring, at, facingIt - 1.2, false); expect(glance).toBeGreaterThan(0); expect(glance).toBeLessThan(1.7); }); test("a wall between you and the flash means no blind at all", () => { const blind = flashDuration(1.7, { x: 1200, y: 1000 }, { x: 1000, y: 1000 }, Math.PI, true); expect(blind).toBe(0); }); test("a smoke blocks the sight line for as long as it lives", () => { const smoke: Zone = { id: 1, kind: "smoke", owner: "x", side: "atk", x: 1200, y: 1000, r: 140, life: 8, fuse: 0, beat: 0, pulses: 0, damage: 0, blocks: true, solid: false, }; // Straight down the mid corridor, which is open floor end to end. const from = { x: 1100, y: 1000 }; const to = { x: 1300, y: 1000 }; expect(sightBlocked(from, to, [])).toBe(false); expect(sightBlocked(from, to, [smoke])).toBe(true); // Standing off the line, the smoke is not in the way. expect(sightBlocked({ x: 1100, y: 700 }, { x: 1300, y: 700 }, [smoke])).toBe(false); }); test("a charge is spent on a cast and refused when there is none", () => { const state = live(); const player = attacker(state); player.agent = "veil"; player.charges.c = 1; expect(cast(state, player, "c")).toBe(true); expect(player.charges.c).toBe(0); expect(state.zones.some((z) => z.kind === "smoke")).toBe(true); expect(cast(state, player, "c")).toBe(false); expect(castable(player, "c")).toBe(false); }); test("the signature goes on cooldown and comes back on its own", () => { const state = live(); const player = attacker(state); player.agent = "veil"; const cooldown = agentById("veil").abilities.e.cooldown; expect(cast(state, player, "e")).toBe(true); expect(player.charges.e).toBe(0); expect(player.cooldown.e).toBe(cooldown); for (let i = 0; i < Math.ceil(cooldown * 10) + 4; i++) tick(state, 0.1); expect(player.cooldown.e).toBe(0); expect(castable(player, "e")).toBe(true); }); test("an ultimate costs its points and empties the meter", () => { const state = live(); const player = attacker(state); player.agent = "sable"; player.ult = 3; expect(cast(state, player, "x")).toBe(false); player.ult = 7; expect(cast(state, player, "x")).toBe(true); expect(player.ult).toBe(0); // Hunt reveals every enemy and leaves the caster's own side alone. for (const other of state.players) expect(other.revealed > 0).toBe(other.side !== player.side); }); test("a molly burns whoever stands in it and leaves the thrower's team alone", () => { const state = live(); const player = attacker(state); player.agent = "ember"; player.charges.q = 1; const victim = state.players.find((p) => p.side === "def")!; const mate = state.players.find((p) => p.side === "atk" && p.id !== player.id)!; victim.x = player.x + 120; victim.y = player.y; mate.x = player.x + 120; mate.y = player.y; player.angle = 0; player.x = victim.x - 120; cast(state, player, "q"); for (const zone of state.zones) { zone.x = victim.x; zone.y = victim.y; } for (let i = 0; i < 20; i++) tick(state, 0.1); expect(victim.hp).toBeLessThan(100); expect(mate.hp).toBe(100); }); test("a wall is solid: it blocks the sight line that was open", () => { const state = live(); const player = attacker(state); player.agent = "rook"; player.x = 1200; player.y = 1320; player.angle = -Math.PI / 2; const behind = { x: 1200, y: 1320 - 600 }; const openBefore = !sightBlocked(player, behind, state.zones); expect(cast(state, player, "e")).toBe(true); expect(openBefore).toBe(true); expect(sightBlocked(player, behind, state.zones)).toBe(true); expect(state.zones.every((z) => z.solid)).toBe(true); }); test("a round starts with the signature ready and no bought charges", () => { const state = newMatch(3); startRound(state, true); for (const player of state.players) { expect(player.charges.c).toBe(0); expect(player.charges.q).toBe(0); expect(player.charges.e).toBe(1); } });