/** * One line of advice, in the player's own words. * * A pure function of the snapshot the server sent plus two things the client * works out from the map it was given: whether you are standing on a site, * and whether you are within reach of the spike. Never more than one prompt — * the most urgent thing wins, because two instructions at once is none. */ /** Within this many units the server lets you pick up, plant or defuse. */ export const REACH = 46; const secs = (n) => Math.max(0, Math.ceil(n)); export function choosePrompt(snap, world = {}) { if (!snap) return ""; const me = snap.me; const spike = snap.spike; const onSite = world.onSite === true; const nearSpike = world.nearSpike === true; if (snap.phase === "over") return snap.result ? `Match over — ${snap.result}` : "Match over"; if (me.blind > 0.05) return "You are blind — back off until it clears"; if (!me.alive) return snap.phase === "buy" ? "Buy phase — you are back next round" : "Waiting for the next round — you're in it"; if (snap.phase === "end") return snap.result ? `${snap.result} — next round in ${secs(snap.clock)}s` : "Round over"; if (snap.phase === "buy") return `Buy phase — ${secs(snap.clock)}s left. Click a gun you can afford.`; if (me.planting > 0) return `Planting — hold F for ${secs(4 - me.planting)}s more`; if (spike.planted) { if (me.side === "def") { if (spike.defuse > 0) return `Defusing — keep holding F, ${secs(7 - spike.defuse)}s`; return nearSpike ? `Spike down, ${secs(spike.fuse)}s — hold F to defuse` : `Spike down, ${secs(spike.fuse)}s — get to it and hold F`; } return `Spike down, ${secs(spike.fuse)}s — keep them off it`; } if (me.side === "atk") { if (me.spike) return onSite ? "Hold F to plant" : "You have the spike — get to site A or B"; if (spike.carried) return "Your team has the spike — go with them and take a site"; if (nearSpike) return "Walk onto the spike to pick it up"; return "Somebody has to carry the spike — it is on the ground"; } return `Defending — hold A and B, ${secs(snap.clock)}s`; }