2022-10-29 17:36:41 +02:00
|
|
|
skillz.register_skill("fbrawl:sp", {
|
|
|
|
name = "fbrawl:sp",
|
2022-10-29 02:22:18 +02:00
|
|
|
hud = {
|
|
|
|
{
|
|
|
|
name = "bar",
|
|
|
|
hud_elem_type = "image",
|
2022-10-29 17:36:41 +02:00
|
|
|
text = "fbrawl_hud_sp_bar.png",
|
2022-10-29 02:22:18 +02:00
|
|
|
position = {x=0.51, y=0.909},
|
2022-10-29 17:36:41 +02:00
|
|
|
scale = {x=13*16, y=1.1*16},
|
2022-10-29 02:22:18 +02:00
|
|
|
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},
|
|
|
|
}
|
|
|
|
},
|
2022-10-03 18:51:13 +02:00
|
|
|
data = {
|
2022-10-09 22:53:41 +02:00
|
|
|
amount = 100,
|
|
|
|
multiplier = 1
|
2022-10-03 18:51:13 +02:00
|
|
|
},
|
|
|
|
loop_params = {
|
2022-10-30 00:55:17 +02:00
|
|
|
cast_rate = 0.3,
|
2022-10-03 18:51:13 +02:00
|
|
|
},
|
2022-10-29 02:22:18 +02:00
|
|
|
recharge_duration = 14,
|
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
|
|
|
|
-- "PUBLIC" FUNCTIONS
|
|
|
|
set = function(self, new_amount)
|
2022-10-20 21:30:09 +02:00
|
|
|
self.data.amount = math.min(math.max(new_amount, 0), 100)
|
2022-10-03 18:51:13 +02:00
|
|
|
end,
|
|
|
|
add = function(self, amount)
|
|
|
|
self:set(self.data.amount + amount)
|
|
|
|
end,
|
|
|
|
sub = function(self, amount)
|
|
|
|
self:set(self.data.amount - amount)
|
|
|
|
end,
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
get_recharged_sp_per_second = function (self)
|
2022-10-29 02:22:18 +02:00
|
|
|
return (100 / self.recharge_duration) * self.data.multiplier
|
|
|
|
end,
|
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
-- SKILL LOGIC
|
|
|
|
cast = function(self)
|
2022-10-09 22:53:41 +02:00
|
|
|
local speed_multiplier = self.data.multiplier
|
|
|
|
local recharge_step = 100 / self.recharge_duration * self.loop_params.cast_rate * speed_multiplier
|
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
self:add(recharge_step)
|
|
|
|
self:update_bar_size()
|
|
|
|
self:update_bar_color()
|
|
|
|
end,
|
|
|
|
|
2022-10-29 02:22:18 +02:00
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
-- "PRIVATE" FUNCTIONS
|
|
|
|
update_bar_size = function(self)
|
2022-10-29 17:36:41 +02:00
|
|
|
local max_length = 13 * 16
|
2022-10-03 18:51:13 +02:00
|
|
|
local progress = self.data.amount/100
|
|
|
|
local scale_x = progress * max_length
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
self.player:hud_change(self.data._hud["bar"], "scale", {x=scale_x, y=1.1*16})
|
2022-10-03 18:51:13 +02:00
|
|
|
end,
|
2022-10-29 02:22:18 +02:00
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
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"))
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
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")
|
2022-10-03 18:51:13 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
self.player:hud_change(self.data._hud["bar"], "text", "fbrawl_hud_sp_bar.png")
|
2022-10-03 18:51:13 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
function fbrawl.consume_sp(skill)
|
|
|
|
if fbrawl.has_enough_sp(skill) then
|
|
|
|
local sp_skill = skill.pl_name:get_skill("fbrawl:sp")
|
2022-10-27 01:28:32 +02:00
|
|
|
|
2022-10-03 18:51:13 +02:00
|
|
|
if skill.cooldown_timer > 0 then
|
|
|
|
skill:cast() --
|
|
|
|
skill:start() -- this will print an error in the chat
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
sp_skill:sub(skill.sp)
|
2022-10-03 18:51:13 +02:00
|
|
|
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
function fbrawl.has_enough_sp(skill)
|
|
|
|
local sp_skill = skill.pl_name:get_skill("fbrawl:sp")
|
2022-10-03 18:51:13 +02:00
|
|
|
|
2022-10-29 17:36:41 +02:00
|
|
|
if skill.sp and sp_skill and sp_skill.is_active then
|
|
|
|
return sp_skill.data.amount >= skill.sp
|
2022-10-03 18:51:13 +02:00
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|