improvement(cbs): use the new skill handling system

This commit is contained in:
Kazhnuz 2019-08-22 22:04:14 +02:00
parent a439c308d6
commit 24b26cc9fc
2 changed files with 62 additions and 11 deletions

View file

@ -21,6 +21,10 @@ function Hero:new(world, x, y, charid, charnumber)
self.charid = charid
self.charnumber = charnumber or 1
self.hp = game.characters.list[self.charid].stats.hp
self.pp = game.characters.list[self.charid].stats.pp
self.actionPerTurn = game.characters.list[self.charid].turns
self:initSprite()
@ -55,6 +59,28 @@ function Hero:getStats()
return game.characters.list[self.charid].stats
end
-- STATS FUNCTIONS
-- All functions related to stats
function Hero:setHP(value, relative)
if relative == true then
value = game.characters.list[self.charid].stats.hp + value
end
game.characters.list[self.charid].stats.hp = value
self.tweens:newTween(0, 0.3, {hp = game.characters.list[self.charid].stats.hp}, 'linear')
end
function Hero:setPP(value, relative)
if relative == true then
value = game.characters.list[self.charid].stats.pp + value
end
game.characters.list[self.charid].stats.pp = value
self.tweens:newTween(0, 0.3, {pp = game.characters.list[self.charid].stats.pp}, 'linear')
end
-- ACTIVITY FUNCTION
-- Function to set or unset activity to the character
@ -178,9 +204,9 @@ function Hero:receiveSignal(action_type, id)
self:switchActiveBattler( )
elseif (action_type == "attack") then
--self:changeAnimation("hit1")
self:startChoregraphy("attack")
self:attack()
elseif (action_type == "skill") then
self:startChoregraphy(id)
self:useSkill(id)
else
self:switchActiveBattler( )
end
@ -236,8 +262,19 @@ function Hero:initChoregraphySystem()
self.isChoregraphyActive = false
end
function Hero:attack(id, dx, dy)
local skill = game.skills:getSkillData("attack")
self:startChoregraphy(skill, dx, dy)
end
function Hero:useSkill(id, dx, dy)
local skill = game.skills:getSkillData(id)
self:setPP(skill.cost * -1, true)
self:startChoregraphy(skill, dx, dy)
end
function Hero:startChoregraphy(skill, dx, dy)
local skill = require("datas.gamedata.skills." .. skill)
local skill = skill
self.choregraphy.current = 0
self.choregraphy.isFinished = false
self.choregraphy.changeAction = true
@ -383,13 +420,11 @@ function Hero:drawHUD()
self.assets.images["m_speedster"]:draw(x, y)
self.assets.images["statusbar"]:draw(x+12, y-6)
local hp = game.characters.list[self.charid].stats.hp
local pp = game.characters.list[self.charid].stats.pp
local hpmax = game.characters.list[self.charid].stats.hpmax
local ppmax = game.characters.list[self.charid].stats.ppmax
local bar1 = math.floor((hp/hpmax)*107)
local bar2 = math.floor((pp/ppmax)*108)
local bar1 = math.floor((self.hp/hpmax)*107)
local bar2 = math.floor((self.pp/ppmax)*108)
love.graphics.setColor(248/255, 160/255, 0, 1)
gui.drawBar(x+29, y+5, bar1, 7)
@ -398,8 +433,8 @@ function Hero:drawHUD()
utils.graphics.resetColor()
self.assets.fonts["hudnbrs_small"]:set()
love.graphics.print(hp .. "/" .. hpmax, x+34, y+5)
love.graphics.print(pp .. "/" .. ppmax, x+28, y+17)
love.graphics.print(math.floor(self.hp) .. "/" .. hpmax, x+34, y+5)
love.graphics.print(math.floor(self.pp) .. "/" .. ppmax, x+28, y+17)
local lvl = game.characters.list[self.charid].stats.level

View file

@ -189,8 +189,19 @@ function SkillWidget:new(scene, menu_name, label1, label2, character)
local menu = scene.menusystem.menus[menu_name] or error("menu " ..menu_name .. " doesn't exist")
local font = scene.assets.fonts["small"]
self.skilldata = game.skills:getSkillData(self.actionType)
CharMenuWidget.super.new(self, menu, font, core.lang:translate("skills", label1))
self.label2 = label2 or ""
if self.skilldata ~= nil then
self.label2 = self.skilldata.cost or 0
if self.label2 < 10 then
self.label2 = "0" .. self.label2
end
else
self.label2 = "n"
end
end
function SkillWidget:drawCanvas()
@ -207,7 +218,12 @@ function SkillWidget:drawCanvas()
end
function SkillWidget:action()
if self.skilldata ~= nil then
self.character:receiveSignal("skill", self.actionType)
else
core.debug:warning("cbs/menu", "skill " .. self.actionType .. " doesn't exist")
self.character:receiveSignal("none")
end
self.scene:flushKeys()
self.scene.menusystem:reset()
end