fantasy-brawl-cd2025/_classes/skill_status_hud.lua

151 lines
5.2 KiB
Lua

local function append_slot_texture_and_change_pointer() end
local function remove_txr_from_hotbar() end
local function append_txr_to_selected_slot() end
local base_hotbar_text = "fbrawl_hotbar.png"
local max_yellow_recharge_seconds = 2
local T = fbrawl.T
function fbrawl.show_status_hud(arena)
if not arena or not arena.in_game then return end
for pl_name, props in pairs(arena.players) do
local slots = {}
local player = minetest.get_player_by_name(pl_name)
local inv = player:get_inventory()
local list = inv:get_list("main")
local selected_slot_texture = "gui_hotbar_selected.png"
-- for each skill in the hotbar determines which color to assign its slot
for i, itemstack in ipairs(list) do
local skill_name = itemstack:get_name():gsub("fantasy_brawl", "fbrawl")
local skill = pl_name:get_skill(skill_name)
if skill then
-- first item has a right click and could have a left lick skill, but it's not a skill itself
if i == 1 then
local right_skill = pl_name:get_skill(skill.rightclick_skill)
local left_skill = pl_name:get_skill(skill.leftclick_skill)
selected_slot_texture = append_slot_texture_and_change_pointer(arena, right_skill, pl_name, slots, i, selected_slot_texture, "right") or selected_slot_texture
selected_slot_texture = append_slot_texture_and_change_pointer(arena, left_skill, pl_name, slots, i, selected_slot_texture, "left") or selected_slot_texture
else
selected_slot_texture = append_slot_texture_and_change_pointer(arena, skill, pl_name, slots, i, selected_slot_texture) or selected_slot_texture
end
end
end
player:hud_set_hotbar_selected_image(selected_slot_texture)
-- apply the final hotbar texture
local final_hotbar_tex = base_hotbar_text
for i, slot_tex in ipairs(slots) do
final_hotbar_tex = final_hotbar_tex .. "^" .. slot_tex
end
player:hud_set_hotbar_image(final_hotbar_tex)
end
minetest.after(0, function ()
fbrawl.show_status_hud(arena)
end)
end
function append_slot_texture_and_change_pointer(arena, skill, pl_name, slots, i, selected_slot_texture, side)
local sp_skill = pl_name:get_skill("fbrawl:sp")
if not skill or not sp_skill then return end
local player = minetest.get_player_by_name(pl_name)
local skill_sp = skill.sp
local pointer_hud = sp_skill.data._hud["pointer_status"]
local pointer_hud_table = player:hud_get(pointer_hud)
local remaining_recharge_seconds = 0
local wielded_idx = player:get_wield_index()
-- determines remaining_seconds_to_recharge
if skill_sp and sp_skill then -- when skill uses sp
local sp_recharged_per_second = sp_skill:get_recharged_sp_per_second()
local remaining_sp_needed_to_cast_skill = math.max(skill_sp - sp_skill.data.amount, 0)
remaining_recharge_seconds = remaining_sp_needed_to_cast_skill / sp_recharged_per_second
end
if sp_skill and skill.cooldown_timer > 0 then -- when skill has a cooldown
if skill.cooldown_timer > remaining_recharge_seconds then
remaining_recharge_seconds = skill.cooldown_timer
end
end
if i == 5 then -- when skill is an ultimate
remaining_recharge_seconds = fbrawl.min_kills_to_use_ultimate - arena.players[pl_name].ultimate_recharge
end
if arena.initial_time - arena.current_time > 5 then
if remaining_recharge_seconds > 0 and wielded_idx == 5 then
arena_lib.HUD_send_msg("broadcast", pl_name, T("@1 kills left to use the ultimate", remaining_recharge_seconds))
else
arena_lib.HUD_hide("broadcast", pl_name)
end
end
-- appends a yellow or red slot to slots and change the pointer HUD
-- yellow
if remaining_recharge_seconds > 0 and remaining_recharge_seconds <= max_yellow_recharge_seconds then
if i == 1 then -- the item with the double skill
table.insert(slots, "fbrawl_slot_yellow_1_"..side..".png")
player:hud_change(pointer_hud, "text",
pointer_hud_table.text ..
"^fbrawl_pointer_yellow_"..side..".png"
)
if wielded_idx == 1 then
selected_slot_texture = selected_slot_texture.."^fbrawl_slot_yellow_"..side..".png"
end
else
if wielded_idx == i then
selected_slot_texture = selected_slot_texture.."^fbrawl_slot_yellow.png"
end
table.insert(slots, "fbrawl_slot_yellow_"..i..".png")
end
-- red
elseif remaining_recharge_seconds > max_yellow_recharge_seconds then
if i == 1 then
table.insert(slots, "fbrawl_slot_red_1_"..side..".png")
player:hud_change(pointer_hud, "text",
pointer_hud_table.text ..
"^fbrawl_pointer_red_"..side..".png"
)
if wielded_idx == 1 then
selected_slot_texture = selected_slot_texture.."^fbrawl_slot_red_"..side..".png"
end
else
if wielded_idx == i then
selected_slot_texture = selected_slot_texture.."^fbrawl_slot_red.png"
end
table.insert(slots, "fbrawl_slot_red_"..i..".png")
end
end
-- remove the left/right hud when the recharge is over
if (i == 1 and remaining_recharge_seconds == 0) then
local texture = pointer_hud_table.text
texture = texture:gsub("%^fbrawl_pointer_red_"..side..".png", "")
texture = texture:gsub("%^fbrawl_pointer_yellow_"..side..".png", "")
player:hud_change(pointer_hud, "text", texture)
end
-- remove the left/right hud when the wielded item is not the first one
if wielded_idx ~= 1 then
player:hud_change(pointer_hud, "text", "fbrawl_transparent.png")
end
return selected_slot_texture
end