feat: add duration support

This commit is contained in:
Kazhnuz 2021-03-12 21:50:45 +01:00
parent b7a0ec7c7b
commit 99c4090698
2 changed files with 9 additions and 8 deletions

View file

@ -13,7 +13,7 @@ end
function EffectManager:applyEffects(character) function EffectManager:applyEffects(character)
for _, effect in ipairs(self.itemdata.effects) do for _, effect in ipairs(self.itemdata.effects) do
local effectInstance = self:getEffectObject(effect, character) local effectInstance = self:getEffectObject(effect, character, self.itemdata.duration)
effectInstance:applyEffect() effectInstance:applyEffect()
end end
end end
@ -21,7 +21,7 @@ end
function EffectManager:applyEffectsBattle(battleTarget) function EffectManager:applyEffectsBattle(battleTarget)
local character = battleTarget.abstract local character = battleTarget.abstract
for _, effect in ipairs(self.itemdata.effects) do for _, effect in ipairs(self.itemdata.effects) do
local effectInstance = self:getEffectObject(effect, character) local effectInstance = self:getEffectObject(effect, character, self.itemdata.duration)
effectInstance:applyEffect() effectInstance:applyEffect()
effectInstance:battleCallback(battleTarget) effectInstance:battleCallback(battleTarget)
end end
@ -30,13 +30,13 @@ end
function EffectManager:getEffectStrings(character) function EffectManager:getEffectStrings(character)
local returnString = "No Effect"; local returnString = "No Effect";
if (#self.itemdata.effects >= 1) then if (#self.itemdata.effects >= 1) then
local effectInstance = self:getEffectObject(self.itemdata.effects[1], character) local effectInstance = self:getEffectObject(self.itemdata.effects[1], character, self.itemdata.duration)
if (effectInstance ~= nil) then if (effectInstance ~= nil) then
returnString = effectInstance:getText() .. "\n" returnString = effectInstance:getText() .. "\n"
end end
end end
if (#self.itemdata.effects >= 2) then if (#self.itemdata.effects >= 2) then
local effectInstance = self:getEffectObject(self.itemdata.effects[2], character) local effectInstance = self:getEffectObject(self.itemdata.effects[2], character, self.itemdata.duration)
if (effectInstance ~= nil) then if (effectInstance ~= nil) then
returnString = returnString .. effectInstance:getText() returnString = returnString .. effectInstance:getText()
end end
@ -44,10 +44,10 @@ function EffectManager:getEffectStrings(character)
return returnString return returnString
end end
function EffectManager:getEffectObject(rawEffectData, character) function EffectManager:getEffectObject(rawEffectData, character, duration)
local effect = itemutils.getItemEffectData(rawEffectData) local effect = itemutils.getItemEffectData(rawEffectData)
if (effectList[effect.type] ~= nil) then if (effectList[effect.type] ~= nil) then
return effectList[effect.type](effect, character) return effectList[effect.type](effect, character, duration)
else else
return nil return nil
end end

View file

@ -1,8 +1,9 @@
local EffectParent = Object:extend() local EffectParent = Object:extend()
function EffectParent:new(effect, character) function EffectParent:new(effect, character, duration)
self.effect = effect self.effect = effect
self.character = character self.character = character
self.duration = duration
end end
function EffectParent:applyEffect() function EffectParent:applyEffect()