From aeb08d64d14219c6c293550ceda78cf491e80c07 Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sat, 13 Jan 2024 21:31:52 +0100 Subject: [PATCH] Show players how much time there is left until immunity runs out (closes #112) --- block_league/src/arena_lib/on_celebration.lua | 3 +- block_league/src/game/misc/immunity.lua | 43 +++++++++++++++---- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/block_league/src/arena_lib/on_celebration.lua b/block_league/src/arena_lib/on_celebration.lua index d65035f..beca154 100644 --- a/block_league/src/arena_lib/on_celebration.lua +++ b/block_league/src/arena_lib/on_celebration.lua @@ -8,6 +8,7 @@ arena_lib.on_celebration("block_league", function(arena, winners) player:get_meta():set_int("bl_immunity", 1) panel_lib.get_panel(pl_name, "bl_info_panel"):show() + arena_lib.HUD_hide("broadcast", pl_name) end -- se รจ pareggio, passa una stringa (no one) @@ -27,4 +28,4 @@ arena_lib.on_celebration("block_league", function(arena, winners) minetest.sound_play("bl_jingle_victory", {to_player = pl_name}) end end -end) \ No newline at end of file +end) diff --git a/block_league/src/game/misc/immunity.lua b/block_league/src/game/misc/immunity.lua index 35c9717..d6c0ed2 100644 --- a/block_league/src/game/misc/immunity.lua +++ b/block_league/src/game/misc/immunity.lua @@ -1,10 +1,13 @@ +local S = minetest.get_translator("block_league") + +local function countdown() end + local old_textures = {} -- KEY: p_name; VALUE: {textures} function block_league.start_immunity_countdown(player) local p_name = player:get_player_name() - local arena = arena_lib.get_arena_by_player(p_name) local textures = player:get_properties().textures old_textures[p_name] = player:get_properties().textures @@ -15,13 +18,9 @@ function block_league.start_immunity_countdown(player) player:set_properties({textures = textures}) - -- TODO: immunity countdown HUD + local arena = arena_lib.get_arena_by_player(p_name) - minetest.after(arena.immunity_time, function() - if not player or not arena.players[p_name] or arena.in_celebration then return end - - block_league.remove_immunity(player) - end) + countdown(arena, player, arena.immunity_time) end @@ -32,6 +31,34 @@ function block_league.remove_immunity(player) if p_meta:get_int("bl_immunity") == 0 or p_meta:get_int("bl_death_delay") == 1 then return end + arena_lib.HUD_hide("broadcast", p_name) p_meta:set_int("bl_immunity", 0) player:set_properties({textures = old_textures[p_name]}) -end \ No newline at end of file +end + + + + + +---------------------------------------------- +---------------FUNZIONI LOCALI---------------- +---------------------------------------------- + +function countdown(arena, player, seconds_left) + local p_name = player:get_player_name() + + arena_lib.HUD_send_msg("broadcast", p_name, S("Immunity off in: @1", seconds_left)) + + if seconds_left == 0 then + block_league.remove_immunity(player) + else + minetest.after(1, function() + if not arena.players[p_name] or arena.in_celebration then return end + + local p_meta = player:get_meta() + if p_meta:get_int("bl_immunity") == 0 or p_meta:get_int("bl_death_delay") == 1 then return end + + countdown(arena, player, seconds_left -1) + end) + end +end