sonic-radiance/sonic-radiance.love/game/loot/effects/heal.lua

79 lines
2.1 KiB
Lua
Raw Normal View History

2020-09-19 11:10:20 +02:00
local ParentEffect = require "game.loot.effects.parent"
local HealEffect = ParentEffect:extend()
function HealEffect:new(effect, character)
self.effect = effect
self.character = character
self.recovered = 0
2020-09-19 11:10:20 +02:00
end
function HealEffect:applyEffect()
self:autosetHealFactor()
self:heal(self.recovered)
end
function HealEffect:autosetHealFactor()
local recovered = 0
local max = self:getMaxValue()
if (self.character:isAlive()) then
if (self.effect.computationMode == "percent") then
recovered = max * (self.effect.value/100)
else
recovered = self.effect.value
end
recovered = math.min(recovered, max - self:getCurrentValue())
end
self.recovered = recovered
end
function HealEffect:getCurrentValue()
if (self.effect.healType == "hp") then
return self.character.hp
elseif (self.effect.healType == "mp") then
return self.character.pp
end
end
function HealEffect:getMaxValue()
2021-07-03 09:51:19 +02:00
local stats = self.character.stats
if (self.effect.healType == "hp") then
2021-07-03 09:51:19 +02:00
return stats:get(stats.HPMAX)
elseif (self.effect.healType == "mp") then
2021-07-03 09:51:19 +02:00
return stats:get(stats.PPMAX)
end
end
2020-09-19 11:10:20 +02:00
function HealEffect:heal(value)
if (self.effect.healType == "hp") then
self.character:setHP(value, true)
elseif (self.effect.healType == "mp") then
self.character:setPP(value, true)
end
end
function HealEffect:battleCallback(fighter)
if (self.effect.healType == "hp") then
fighter.actor:setDamageNumber(self.recovered)
fighter:updateHP()
elseif (self.effect.healType == "mp") then
fighter.actor:setDamageNumber(self.recovered, true)
fighter:updatePP()
end
2020-09-19 11:10:20 +02:00
end
function HealEffect:getText()
local num = self.effect.value
if (self.effect.computationMode == "percent") then
num = num .. "%"
end
local type = ""
if (self.effect.healType == "hp") then
type = "HP"
end
if (self.effect.healType == "mp") then
type = "MP"
end
return "Heal " .. num .. " " .. type;
end
return HealEffect