add timeout to use (#120)

* add timeout to `use`

* refactor: use Math.min directly

* fix: remove eval

It doesn't look good in the UI, we can assume that the current timeout is already shown in the UI
This commit is contained in:
Kent Rasmussen
2024-04-19 13:11:36 +02:00
committed by GitHub
parent 8ad43b35ff
commit 7ef2771ef8
+8 -7
View File
@@ -9745,25 +9745,26 @@ function init_io() {
);
});
socket.on("use", function (data) {
var player = players[socket.id];
const player = players[socket.id];
if (!player) {
return;
}
if (data.item == "hp" || data.item == "mp") {
if (player.last.potion && mssince(player.last.potion) < 0) {
return fail_response("not_ready");
if (player.last.potion) {
const ms = -mssince(player.last.potion);
if (ms > 0) {
return fail_response("not_ready", { ms: ms });
}
}
player.last.potion = future_ms(4000);
if (data.item == "hp") {
player.hp += 50;
player.hp = Math.min(player.hp + 50, player.max_hp);
disappearing_text(socket, player, "+50", { color: "green", xy: 1, s: "hp", nohp: 1 });
}
if (data.item == "mp") {
player.mp += 100;
player.mp = Math.min(player.mp + 100, player.max_mp);
disappearing_text(socket, player, "+100", { color: "#006AA9", xy: 1, s: "mp", nomp: 1 });
}
player.hp = min(player.hp, player.max_hp);
player.mp = min(player.mp, player.max_mp);
// calculate_player_stats(player); [22/11/16]
player.cid++;
player.u = true;