feat: add healing and setStatut effect support

This commit is contained in:
Kazhnuz 2021-03-12 21:51:10 +01:00
parent 32d5aae8ef
commit f72c416f57
2 changed files with 64 additions and 1 deletions

View file

@ -4,10 +4,60 @@ local HealEffect = ParentEffect:extend()
function HealEffect:new(effect, character)
self.effect = effect
self.character = character
self.recovered = 0
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()
if (self.effect.healType == "hp") then
return self.character.stats.hpmax
elseif (self.effect.healType == "mp") then
return self.character.stats.ppmax
end
end
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
end
function HealEffect:getText()

View file

@ -1,13 +1,26 @@
local ParentEffect = require "game.loot.effects.parent"
local StatusEffect = ParentEffect:extend()
function StatusEffect:new(effect, character)
function StatusEffect:new(effect, character, duration)
self.effect = effect
self.character = character
self.duration = duration or -1
end
function StatusEffect:applyEffect()
if (self.effect.set) then
self:addStatut()
else
self:removeStatut()
end
end
function StatusEffect:addStatut()
self.character:addStatut(self.effect.status, self.duration)
end
function StatusEffect:removeStatut()
self.character:removeStatut(self.effect.status)
end
function StatusEffect:getText()