| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
export const REACH = 46; |
| 12 |
|
| 13 |
const secs = (n) => Math.max(0, Math.ceil(n)); |
| 14 |
|
| 15 |
|
| 16 |
export const lower = (text) => String(text).charAt(0).toLowerCase() + String(text).slice(1); |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
export function roundOutcome(snap) { |
| 24 |
const last = snap && snap.last; |
| 25 |
if (!last) return null; |
| 26 |
const team = snap.me && snap.me.team; |
| 27 |
const title = team ? (last.winner === team ? "Round won" : "Round lost") : `${last.winner} take the round`; |
| 28 |
return { title, why: lower(last.why), winner: last.winner }; |
| 29 |
} |
| 30 |
|
| 31 |
export function choosePrompt(snap, world = {}) { |
| 32 |
if (!snap) return ""; |
| 33 |
const me = snap.me; |
| 34 |
const spike = snap.spike; |
| 35 |
const onSite = world.onSite === true; |
| 36 |
const nearSpike = world.nearSpike === true; |
| 37 |
|
| 38 |
|
| 39 |
const buyWith = world.input === "keys" ? "Press b and buy a gun you can afford." : "Click a gun you can afford."; |
| 40 |
|
| 41 |
if (snap.phase === "over") |
| 42 |
return `Match over — ${snap.result ?? "done"} · a new match starts in ${secs(snap.clock)}s`; |
| 43 |
if (me.blind > 0.05) return "You are blind — back off until it clears"; |
| 44 |
if (snap.phase === "end") { |
| 45 |
const outcome = roundOutcome(snap); |
| 46 |
const next = `next round in ${secs(snap.clock)}s`; |
| 47 |
return outcome ? `${outcome.title} — ${outcome.why} · ${next}` : `Round over · ${next}`; |
| 48 |
} |
| 49 |
if (!me.alive) |
| 50 |
return snap.phase === "buy" |
| 51 |
? "Buy phase — you are back next round" |
| 52 |
: "Waiting for the next round — you're in it"; |
| 53 |
if (snap.phase === "buy") { |
| 54 |
const side = me.side === "atk" ? "You attack: plant the spike on A or B." : "You defend: hold A and B."; |
| 55 |
return `Buy phase — ${secs(snap.clock)}s left. ${side} ${buyWith}`; |
| 56 |
} |
| 57 |
|
| 58 |
if (me.planting > 0) return `Planting — hold F for ${secs(4 - me.planting)}s more`; |
| 59 |
if (spike.planted) { |
| 60 |
if (me.side === "def") { |
| 61 |
if (spike.defuse > 0) return `Defusing — keep holding F, ${secs(7 - spike.defuse)}s`; |
| 62 |
return nearSpike |
| 63 |
? `Spike down, ${secs(spike.fuse)}s — hold F to defuse` |
| 64 |
: `Spike down, ${secs(spike.fuse)}s — get to it and hold F`; |
| 65 |
} |
| 66 |
return `Spike down, ${secs(spike.fuse)}s — keep them off it`; |
| 67 |
} |
| 68 |
|
| 69 |
if (me.side === "atk") { |
| 70 |
if (me.spike) return onSite ? "Hold F to plant" : "You have the spike — get to site A or B"; |
| 71 |
if (spike.carried) return "Your team has the spike — go with them and take a site"; |
| 72 |
if (nearSpike) return "Walk onto the spike to pick it up"; |
| 73 |
return "Somebody has to carry the spike — it is on the ground"; |
| 74 |
} |
| 75 |
return `Defending — hold A and B, ${secs(snap.clock)}s`; |
| 76 |
} |