wren/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 51e1b3de2c93c9d19656cbce7937019e452ac771
| 1 | import { expect, test } from "bun:test"; |
| 2 | import { AGENTS, agentById, buyableSlots, cast, castable, flashDuration, sightBlocked, SLOTS } from "./abilities.ts"; |
| 3 | import { newMatch, startRound, tick } from "./match.ts"; |
| 4 | import type { MatchState, Player, Zone } from "./state.ts"; |
| 5 | |
| 6 | const live = (): MatchState => { |
| 7 | const state = newMatch(11); |
| 8 | state.phase = "live"; |
| 9 | state.clock = 100; |
| 10 | return state; |
| 11 | }; |
| 12 | const attacker = (state: MatchState): Player => state.players.find((p) => p.side === "atk")!; |
| 13 | |
| 14 | test("every agent has two bought basics, a free signature and an ultimate", () => { |
| 15 | expect(AGENTS.length).toBe(5); |
| 16 | for (const agent of AGENTS) { |
| 17 | for (const slot of SLOTS) expect(agent.abilities[slot].name.length).toBeGreaterThan(0); |
| 18 | for (const slot of buyableSlots) expect(agent.abilities[slot].cost).toBeGreaterThan(0); |
| 19 | expect(agent.abilities.e.cost).toBe(0); |
| 20 | expect(agent.abilities.e.cooldown).toBeGreaterThan(0); |
| 21 | expect(agent.abilities.x.points).toBeGreaterThanOrEqual(6); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | test("a flash blinds by the angle you were facing", () => { |
| 26 | const at = { x: 1000, y: 1000 }; |
| 27 | const staring = { x: 1200, y: 1000 }; |
| 28 | const facingIt = Math.PI; // looking back down the line at the flash |
| 29 | const facingAway = 0; |
| 30 | expect(flashDuration(1.7, staring, at, facingIt, false)).toBeGreaterThan(1.6); |
| 31 | expect(flashDuration(1.7, staring, at, facingAway, false)).toBe(0); |
| 32 | // Half turned away is a shorter blind than staring straight at it. |
| 33 | const glance = flashDuration(1.7, staring, at, facingIt - 1.2, false); |
| 34 | expect(glance).toBeGreaterThan(0); |
| 35 | expect(glance).toBeLessThan(1.7); |
| 36 | }); |
| 37 | |
| 38 | test("a wall between you and the flash means no blind at all", () => { |
| 39 | const blind = flashDuration(1.7, { x: 1200, y: 1000 }, { x: 1000, y: 1000 }, Math.PI, true); |
| 40 | expect(blind).toBe(0); |
| 41 | }); |
| 42 | |
| 43 | test("a smoke blocks the sight line for as long as it lives", () => { |
| 44 | const smoke: Zone = { |
| 45 | id: 1, kind: "smoke", owner: "x", side: "atk", x: 1200, y: 1000, r: 140, |
| 46 | life: 8, fuse: 0, beat: 0, pulses: 0, damage: 0, blocks: true, solid: false, |
| 47 | }; |
| 48 | // Straight down the mid corridor, which is open floor end to end. |
| 49 | const from = { x: 1100, y: 1000 }; |
| 50 | const to = { x: 1300, y: 1000 }; |
| 51 | expect(sightBlocked(from, to, [])).toBe(false); |
| 52 | expect(sightBlocked(from, to, [smoke])).toBe(true); |
| 53 | // Standing off the line, the smoke is not in the way. |
| 54 | expect(sightBlocked({ x: 1100, y: 700 }, { x: 1300, y: 700 }, [smoke])).toBe(false); |
| 55 | }); |
| 56 | |
| 57 | test("a charge is spent on a cast and refused when there is none", () => { |
| 58 | const state = live(); |
| 59 | const player = attacker(state); |
| 60 | player.agent = "veil"; |
| 61 | player.charges.c = 1; |
| 62 | expect(cast(state, player, "c")).toBe(true); |
| 63 | expect(player.charges.c).toBe(0); |
| 64 | expect(state.zones.some((z) => z.kind === "smoke")).toBe(true); |
| 65 | expect(cast(state, player, "c")).toBe(false); |
| 66 | expect(castable(player, "c")).toBe(false); |
| 67 | }); |
| 68 | |
| 69 | test("the signature goes on cooldown and comes back on its own", () => { |
| 70 | const state = live(); |
| 71 | const player = attacker(state); |
| 72 | player.agent = "veil"; |
| 73 | const cooldown = agentById("veil").abilities.e.cooldown; |
| 74 | expect(cast(state, player, "e")).toBe(true); |
| 75 | expect(player.charges.e).toBe(0); |
| 76 | expect(player.cooldown.e).toBe(cooldown); |
| 77 | for (let i = 0; i < Math.ceil(cooldown * 10) + 4; i++) tick(state, 0.1); |
| 78 | expect(player.cooldown.e).toBe(0); |
| 79 | expect(castable(player, "e")).toBe(true); |
| 80 | }); |
| 81 | |
| 82 | test("an ultimate costs its points and empties the meter", () => { |
| 83 | const state = live(); |
| 84 | const player = attacker(state); |
| 85 | player.agent = "sable"; |
| 86 | player.ult = 3; |
| 87 | expect(cast(state, player, "x")).toBe(false); |
| 88 | player.ult = 7; |
| 89 | expect(cast(state, player, "x")).toBe(true); |
| 90 | expect(player.ult).toBe(0); |
| 91 | // Hunt reveals every enemy and leaves the caster's own side alone. |
| 92 | for (const other of state.players) expect(other.revealed > 0).toBe(other.side !== player.side); |
| 93 | }); |
| 94 | |
| 95 | test("a molly burns whoever stands in it and leaves the thrower's team alone", () => { |
| 96 | const state = live(); |
| 97 | const player = attacker(state); |
| 98 | player.agent = "ember"; |
| 99 | player.charges.q = 1; |
| 100 | const victim = state.players.find((p) => p.side === "def")!; |
| 101 | const mate = state.players.find((p) => p.side === "atk" && p.id !== player.id)!; |
| 102 | victim.x = player.x + 120; |
| 103 | victim.y = player.y; |
| 104 | mate.x = player.x + 120; |
| 105 | mate.y = player.y; |
| 106 | player.angle = 0; |
| 107 | player.x = victim.x - 120; |
| 108 | cast(state, player, "q"); |
| 109 | for (const zone of state.zones) { |
| 110 | zone.x = victim.x; |
| 111 | zone.y = victim.y; |
| 112 | } |
| 113 | for (let i = 0; i < 20; i++) tick(state, 0.1); |
| 114 | expect(victim.hp).toBeLessThan(100); |
| 115 | expect(mate.hp).toBe(100); |
| 116 | }); |
| 117 | |
| 118 | test("a wall is solid: it blocks the sight line that was open", () => { |
| 119 | const state = live(); |
| 120 | const player = attacker(state); |
| 121 | player.agent = "rook"; |
| 122 | // Along the back corridor, which is open from one side of the map to the other. |
| 123 | player.x = 400; |
| 124 | player.y = 1400; |
| 125 | player.angle = 0; |
| 126 | const behind = { x: 1000, y: 1400 }; |
| 127 | const openBefore = !sightBlocked(player, behind, state.zones); |
| 128 | expect(cast(state, player, "e")).toBe(true); |
| 129 | expect(openBefore).toBe(true); |
| 130 | expect(sightBlocked(player, behind, state.zones)).toBe(true); |
| 131 | expect(state.zones.every((z) => z.solid)).toBe(true); |
| 132 | }); |
| 133 | |
| 134 | test("a round starts with the signature ready and no bought charges", () => { |
| 135 | const state = newMatch(3); |
| 136 | startRound(state, true); |
| 137 | for (const player of state.players) { |
| 138 | expect(player.charges.c).toBe(0); |
| 139 | expect(player.charges.q).toBe(0); |
| 140 | expect(player.charges.e).toBe(1); |
| 141 | } |
| 142 | }); |