aboutsummaryrefslogtreecommitdiff
path: root/webAO/packets/handlers/handleHP.ts
blob: f3655903068dcb6bab999b839283740d537436e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { client } from "../../client";


  /**
   * Handles a change in the health bars' states.
   * @param {Array} args packet arguments
   */
export const handleHP = (args: string[]) => {
    const percent_hp = Number(args[2]) * 10;
    let healthbox;
    if (args[1] === "1") {
      // Def hp
      client.hp[0] = Number(args[2]);
      healthbox = document.getElementById("client_defense_hp");
    } else {
      // Pro hp
      client.hp[1] = Number(args[2]);
      healthbox = document.getElementById("client_prosecutor_hp");
    }
    (<HTMLElement>(
      healthbox.getElementsByClassName("health-bar")[0]
    )).style.width = `${percent_hp}%`;
  }