aboutsummaryrefslogtreecommitdiff
path: root/webAO/packets/handlers/handlePV.ts
blob: 180fbeaf23664f6d3afcd908c9289cc91fe87dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { client } from "../../client";
import fileExists from "../../utils/fileExists";
import { updateActionCommands } from '../../dom/updateActionCommands'
import { pickEmotion } from '../../dom/pickEmotion'
import { AO_HOST } from "../../client/aoHost";

/**
 * Handles the server's assignment of a character for the player to use.
 * PV # playerID (unused) # CID # character ID
 * @param {Array} args packet arguments
 */
export const handlePV = async (args: string[]) => {
  client.charID = Number(args[3]);
  document.getElementById("client_waiting")!.style.display = "none";
  document.getElementById("client_charselect")!.style.display = "none";

  const me = client.chars[client.charID];
  client.selectedEmote = -1;
  const { emotes } = client;
  const emotesList = document.getElementById("client_emo")!;
  emotesList.style.display = "";
  emotesList.innerHTML = ""; // Clear emote box
  const ini = me.inifile;
  me.side = ini.options.side;
  updateActionCommands(me.side);
  if (ini.emotions.number === 0) {
    emotesList.innerHTML = `<span
					id="emo_0"
					alt="unavailable"
					class="emote_button">No emotes available</span>`;
  } else {
    for (let i = 1; i <= ini.emotions.number; i++) {
      try {
        const emoteinfo = ini.emotions[i].split("#");
        let esfx;
        let esfxd;
        try {
          esfx = ini.soundn[i] || "0";
          esfxd = Number(ini.soundt[i]) || 0;
        } catch (e) {
          console.warn("ini sound is completly missing");
          esfx = "0";
          esfxd = 0;
        }
        // Make sure the asset server is case insensitive, or that everything on it is lowercase

        emotes[i] = {
          desc: emoteinfo[0].toLowerCase(),
          preanim: emoteinfo[1].toLowerCase(),
          emote: emoteinfo[2].toLowerCase(),
          zoom: Number(emoteinfo[3]) || 0,
          deskmod: Number(emoteinfo[4]) || 1,
          sfx: esfx.toLowerCase(),
          sfxdelay: esfxd,
          frame_screenshake: "",
          frame_realization: "",
          frame_sfx: "",
          button: `${AO_HOST}characters/${encodeURI(
            me.name.toLowerCase()
          )}/emotions/button${i}_off.png`,
        };

        let emote_item = new Image();
        emote_item.id = "emo_"+i;
        emote_item.className = "emote_button";
        emote_item.src = emotes[i].button;
        emote_item.alt = emotes[i].desc;
        emote_item.title = emotes[i].desc;
        emote_item.onclick = () => { window.pickEmotion(i) }
        emotesList.appendChild(emote_item);
      } catch (e) {
        console.error(`missing emote ${i}`);
      }
    }
    pickEmotion(1);
  }

  if (
    await fileExists(
      `${AO_HOST}characters/${encodeURI(me.name.toLowerCase())}/custom.gif`
    )
  ) {
    document.getElementById("button_4")!.style.display = "";
  } else {
    document.getElementById("button_4")!.style.display = "none";
  }

}