mirror of
https://github.com/gooba42/adventureland.git
synced 2026-10-26 15:00:13 -05:00
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:
+8
-7
@@ -9745,25 +9745,26 @@ function init_io() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
socket.on("use", function (data) {
|
socket.on("use", function (data) {
|
||||||
var player = players[socket.id];
|
const player = players[socket.id];
|
||||||
if (!player) {
|
if (!player) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.item == "hp" || data.item == "mp") {
|
if (data.item == "hp" || data.item == "mp") {
|
||||||
if (player.last.potion && mssince(player.last.potion) < 0) {
|
if (player.last.potion) {
|
||||||
return fail_response("not_ready");
|
const ms = -mssince(player.last.potion);
|
||||||
|
if (ms > 0) {
|
||||||
|
return fail_response("not_ready", { ms: ms });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
player.last.potion = future_ms(4000);
|
player.last.potion = future_ms(4000);
|
||||||
if (data.item == "hp") {
|
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 });
|
disappearing_text(socket, player, "+50", { color: "green", xy: 1, s: "hp", nohp: 1 });
|
||||||
}
|
}
|
||||||
if (data.item == "mp") {
|
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 });
|
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]
|
// calculate_player_stats(player); [22/11/16]
|
||||||
player.cid++;
|
player.cid++;
|
||||||
player.u = true;
|
player.u = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user