From 357b27c0aae95031a5d94bdbc504d82b797b22e2 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 30 Aug 2022 18:08:05 -0400 Subject: Several packets added --- webAO/packets/handlers/handleHP.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 webAO/packets/handlers/handleHP.ts (limited to 'webAO/packets/handlers/handleHP.ts') diff --git a/webAO/packets/handlers/handleHP.ts b/webAO/packets/handlers/handleHP.ts new file mode 100644 index 0000000..f365590 --- /dev/null +++ b/webAO/packets/handlers/handleHP.ts @@ -0,0 +1,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"); + } + (( + healthbox.getElementsByClassName("health-bar")[0] + )).style.width = `${percent_hp}%`; + } \ No newline at end of file -- cgit