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
|
2021-03-12 21:51:10 +01:00
|
|
|
self.recovered = 0
|
2020-09-19 11:10:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function HealEffect:applyEffect()
|
2021-03-12 21:51:10 +01:00
|
|
|
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
|
2021-03-12 21:51:10 +01:00
|
|
|
if (self.effect.healType == "hp") then
|
2021-07-03 09:51:19 +02:00
|
|
|
return stats:get(stats.HPMAX)
|
2021-03-12 21:51:10 +01:00
|
|
|
elseif (self.effect.healType == "mp") then
|
2021-07-03 09:51:19 +02:00
|
|
|
return stats:get(stats.PPMAX)
|
2021-03-12 21:51:10 +01:00
|
|
|
end
|
|
|
|
end
|
2020-09-19 11:10:20 +02:00
|
|
|
|
2021-03-12 21:51:10 +01: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
|