2020-11-16 23:06:07 +01:00
|
|
|
local recursive_time = 0.1
|
2020-11-23 15:21:10 +01:00
|
|
|
local MAX_ENERGY = 100
|
2020-10-27 18:13:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-29 10:56:30 +01:00
|
|
|
function block_league.energy_refill_loop(arena)
|
2020-10-27 18:13:15 +01:00
|
|
|
|
|
|
|
if not arena.in_game then return end
|
|
|
|
|
|
|
|
for pl_name, stats in pairs(arena.players) do
|
|
|
|
|
|
|
|
local player = minetest.get_player_by_name(pl_name)
|
|
|
|
local health = player:get_hp()
|
|
|
|
|
|
|
|
-- se è vivo
|
|
|
|
if health > 0 then
|
2020-11-23 15:21:10 +01:00
|
|
|
if player:get_meta():get_int("bl_has_ball") == 0 and arena.players[pl_name].energy < MAX_ENERGY then
|
2020-10-27 18:13:15 +01:00
|
|
|
arena.players[pl_name].energy = arena.players[pl_name].energy + 1
|
|
|
|
block_league.energy_update(arena, pl_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
if player:get_pos().y < arena.min_y then
|
|
|
|
player:set_hp(0)
|
2020-10-29 10:56:30 +01:00
|
|
|
player:get_meta():set_int("bl_has_ball", 0)
|
2020-10-27 18:13:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-29 10:56:30 +01:00
|
|
|
minetest.after(recursive_time, function() block_league.energy_refill_loop(arena) end)
|
2020-10-27 18:13:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function block_league.energy_drain(arena, w_name)
|
|
|
|
|
|
|
|
-- per vedere se è online devo per forza fare minetest.ecc, dacché è inutile passare l'intero giocatore come parametro (dato che mi serve il nome)
|
|
|
|
local wielder = minetest.get_player_by_name(w_name)
|
|
|
|
|
2020-10-29 10:56:30 +01:00
|
|
|
if not arena.in_game or not wielder or wielder:get_meta():get_int("bl_has_ball") == 0 then return end
|
2020-10-27 18:13:15 +01:00
|
|
|
|
|
|
|
if arena.players[w_name].energy > 0 then
|
2020-11-16 23:06:07 +01:00
|
|
|
arena.players[w_name].energy = arena.players[w_name].energy -2
|
2020-10-27 18:13:15 +01:00
|
|
|
block_league.energy_update(arena, w_name)
|
|
|
|
else
|
2020-10-28 16:24:06 +01:00
|
|
|
wielder:set_physics_override({speed = block_league.SPEED_LOW})
|
2020-10-27 18:13:15 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.after(recursive_time, function() block_league.energy_drain(arena, w_name) end)
|
|
|
|
end
|