112 lines
2.8 KiB
Lua

skillz.register_skill("fbrawl:sp", {
name = "fbrawl:sp",
hud = {
{
name = "bar",
hud_elem_type = "image",
text = "fbrawl_hud_sp_bar.png",
position = {x=0.51, y=0.909},
scale = {x=13*16, y=1.1*16},
alignment = {x=1, y=0.5}
},
{
name = "pointer_status",
hud_elem_type = "image",
text = "fbrawl_transparent.png",
position = {x=0.5, y=0.5},
offset = {x=-18.75, y = 0},
scale = {x=2.5, y=2.5},
alignment = {x=0.5, y=0.5},
}
},
data = {
amount = 100,
multiplier = 1
},
loop_params = {
cast_rate = 0.3,
},
recharge_duration = 14,
-- "PUBLIC" FUNCTIONS
set = function(self, new_amount)
self.data.amount = math.min(math.max(new_amount, 0), 100)
end,
add = function(self, amount)
self:set(self.data.amount + amount)
end,
sub = function(self, amount)
self:set(self.data.amount - amount)
end,
get_recharged_sp_per_second = function (self)
return (100 / self.recharge_duration) * self.data.multiplier
end,
-- SKILL LOGIC
cast = function(self)
local speed_multiplier = self.data.multiplier
local recharge_step = 100 / self.recharge_duration * self.loop_params.cast_rate * speed_multiplier
self:add(recharge_step)
self:update_bar_size()
self:update_bar_color()
end,
-- "PRIVATE" FUNCTIONS
update_bar_size = function(self)
local max_length = 13 * 16
local progress = self.data.amount/100
local scale_x = progress * max_length
self.player:hud_change(self.data._hud["bar"], "scale", {x=scale_x, y=1.1*16})
end,
update_bar_color = function(self)
local wielded_item_name = self.player:get_wielded_item():get_name()
local skill = self.pl_name:get_skill(wielded_item_name:gsub("fantasy_brawl", "fbrawl"))
if skill and skill.sp then
if not fbrawl.has_enough_sp(skill) then
self.player:hud_change(self.data._hud["bar"], "text", "fbrawl_hud_sp_bar_red.png")
return
end
end
self.player:hud_change(self.data._hud["bar"], "text", "fbrawl_hud_sp_bar.png")
end
})
function fbrawl.consume_sp(skill)
if fbrawl.has_enough_sp(skill) then
local sp_skill = skill.pl_name:get_skill("fbrawl:sp")
if skill.cooldown_timer > 0 then
skill:cast() --
skill:start() -- this will print an error in the chat
return false
end
sp_skill:sub(skill.sp)
return true
else
return false
end
end
function fbrawl.has_enough_sp(skill)
local sp_skill = skill.pl_name:get_skill("fbrawl:sp")
if skill.sp and sp_skill and sp_skill.is_active then
return sp_skill.data.amount >= skill.sp
else
return false
end
end