fable/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine
Files 52f9b27d06119c6bfd785e71a5f60ac5478147af
1
/**
2
 * One line of advice, in the player's own words.
3
 *
4
 * A pure function of the snapshot the server sent plus two things the client
5
 * works out from the map it was given: whether you are standing on a site,
6
 * and whether you are within reach of the spike. Never more than one prompt —
7
 * the most urgent thing wins, because two instructions at once is none.
8
 */
9
10
/** Within this many units the server lets you pick up, plant or defuse. */
11
export const REACH = 46;
12
13
const secs = (n) => Math.max(0, Math.ceil(n));
14
15
export function choosePrompt(snap, world = {}) {
16
  if (!snap) return "";
17
  const me = snap.me;
18
  const spike = snap.spike;
19
  const onSite = world.onSite === true;
20
  const nearSpike = world.nearSpike === true;
21
22
  if (snap.phase === "over") return snap.result ? `Match over — ${snap.result}` : "Match over";
23
  if (me.blind > 0.05) return "You are blind — back off until it clears";
24
  if (!me.alive)
25
    return snap.phase === "buy"
26
      ? "Buy phase — you are back next round"
27
      : "Waiting for the next round — you're in it";
28
  if (snap.phase === "end") return snap.result ? `${snap.result} — next round in ${secs(snap.clock)}s` : "Round over";
29
  if (snap.phase === "buy")
30
    return `Buy phase — ${secs(snap.clock)}s left. Click a gun you can afford.`;
31
32
  if (me.planting > 0) return `Planting — hold F for ${secs(4 - me.planting)}s more`;
33
  if (spike.planted) {
34
    if (me.side === "def") {
35
      if (spike.defuse > 0) return `Defusing — keep holding F, ${secs(7 - spike.defuse)}s`;
36
      return nearSpike
37
        ? `Spike down, ${secs(spike.fuse)}s — hold F to defuse`
38
        : `Spike down, ${secs(spike.fuse)}s — get to it and hold F`;
39
    }
40
    return `Spike down, ${secs(spike.fuse)}s — keep them off it`;
41
  }
42
43
  if (me.side === "atk") {
44
    if (me.spike) return onSite ? "Hold F to plant" : "You have the spike — get to site A or B";
45
    if (spike.carried) return "Your team has the spike — go with them and take a site";
46
    if (nearSpike) return "Walk onto the spike to pick it up";
47
    return "Somebody has to carry the spike — it is on the ground";
48
  }
49
  return `Defending — hold A and B, ${secs(snap.clock)}s`;
50
}
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts