wren/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 1156c415fe9c604592b0340399fb65d1c0748194
| 1 | /** |
| 2 | * The shape of a match. Types only, so the ability module and the match loop |
| 3 | * can both speak about a player without importing each other. |
| 4 | */ |
| 5 | |
| 6 | import type { Track } from "./aim.ts"; |
| 7 | import type { Point, Site } from "./map.ts"; |
| 8 | import type { WeaponId } from "./weapons.ts"; |
| 9 | |
| 10 | export type Side = "atk" | "def"; |
| 11 | export type Slot = "c" | "q" | "e" | "x"; |
| 12 | export type Team = "red" | "blue"; |
| 13 | |
| 14 | export type Phase = "buy" | "live" | "end" | "over"; |
| 15 | |
| 16 | export type ZoneKind = "smoke" | "molly" | "wall" | "trip" | "dart" | "flash" | "heal"; |
| 17 | |
| 18 | /** Anything an ability leaves on the map, with a clock on it. */ |
| 19 | export type Zone = { |
| 20 | id: number; |
| 21 | kind: ZoneKind; |
| 22 | owner: string; |
| 23 | side: Side; |
| 24 | x: number; |
| 25 | y: number; |
| 26 | r: number; |
| 27 | /** Seconds of life left. */ |
| 28 | life: number; |
| 29 | /** Seconds before it goes off (a flash in the air, a trip arming). */ |
| 30 | fuse: number; |
| 31 | /** Seconds to the next damage tick or recon pulse. */ |
| 32 | beat: number; |
| 33 | pulses: number; |
| 34 | damage: number; |
| 35 | /** Blocks line of sight (smoke, wall). */ |
| 36 | blocks: boolean; |
| 37 | /** Blocks movement (wall). */ |
| 38 | solid: boolean; |
| 39 | }; |
| 40 | |
| 41 | export type Input = { |
| 42 | mx: number; |
| 43 | my: number; |
| 44 | angle: number; |
| 45 | fire: boolean; |
| 46 | /** Plant, defuse, pick the spike up: one key for all of it. */ |
| 47 | use: boolean; |
| 48 | reload: boolean; |
| 49 | cast: Slot | null; |
| 50 | }; |
| 51 | |
| 52 | export const emptyInput = (): Input => ({ |
| 53 | mx: 0, |
| 54 | my: 0, |
| 55 | angle: 0, |
| 56 | fire: false, |
| 57 | use: false, |
| 58 | reload: false, |
| 59 | cast: null, |
| 60 | }); |
| 61 | |
| 62 | export type Player = { |
| 63 | id: string; |
| 64 | name: string; |
| 65 | bot: boolean; |
| 66 | agent: string; |
| 67 | team: Team; |
| 68 | side: Side; |
| 69 | x: number; |
| 70 | y: number; |
| 71 | angle: number; |
| 72 | hp: number; |
| 73 | armour: number; |
| 74 | alive: boolean; |
| 75 | credits: number; |
| 76 | weapon: WeaponId; |
| 77 | /** Kept through a round they survived, reset to the Classic when they die. */ |
| 78 | ammo: number; |
| 79 | reloadIn: number; |
| 80 | fireIn: number; |
| 81 | /** Basic charges bought this round, and signature/ult readiness. */ |
| 82 | charges: Record<Slot, number>; |
| 83 | cooldown: Record<Slot, number>; |
| 84 | ult: number; |
| 85 | blind: number; |
| 86 | slow: number; |
| 87 | haste: number; |
| 88 | /** Seconds this player stays visible to the other team however dark it is. */ |
| 89 | revealed: number; |
| 90 | spike: boolean; |
| 91 | planting: number; |
| 92 | defusing: number; |
| 93 | kills: number; |
| 94 | deaths: number; |
| 95 | assists: number; |
| 96 | damageDone: number; |
| 97 | input: Input; |
| 98 | /** Bot scratch space: where it is walking and when it last thought. */ |
| 99 | goal: Point | null; |
| 100 | think: number; |
| 101 | /** Bot scratch space: the target it is holding, and how badly. */ |
| 102 | aim: Track; |
| 103 | spray: number; |
| 104 | joinedAt: number; |
| 105 | }; |
| 106 | |
| 107 | export type MatchState = { |
| 108 | id: string; |
| 109 | phase: Phase; |
| 110 | /** Seconds left in the phase. */ |
| 111 | clock: number; |
| 112 | round: number; |
| 113 | score: Record<Team, number>; |
| 114 | /** Which team attacks this round. */ |
| 115 | attackers: Team; |
| 116 | lossStreak: Record<Team, number>; |
| 117 | players: Player[]; |
| 118 | zones: Zone[]; |
| 119 | nextZone: number; |
| 120 | spike: { carried: string | null; x: number; y: number; planted: boolean; fuse: number; site: Site | null; defuse: number; checkpoint: number }; |
| 121 | orbs: { x: number; y: number; taken: boolean }[]; |
| 122 | shots: { x1: number; y1: number; x2: number; y2: number; hit: boolean; age: number }[]; |
| 123 | events: { text: string; age: number }[]; |
| 124 | result: string | null; |
| 125 | seed: number; |
| 126 | now: number; |
| 127 | }; |