2020-09-13 13:25:44 +02:00
|
|
|
local EffectManager = Object:extend()
|
|
|
|
|
|
|
|
local effectList = require "game.loot.effects"
|
|
|
|
|
|
|
|
function EffectManager:new()
|
|
|
|
self.itemdata = nil;
|
|
|
|
end
|
|
|
|
|
|
|
|
function EffectManager:getItemData(category, item)
|
2021-05-15 21:43:15 +02:00
|
|
|
self.itemdata = core.datas:get("items", item)
|
2020-09-13 13:25:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function EffectManager:applyEffects(character)
|
|
|
|
for _, effect in ipairs(self.itemdata.effects) do
|
2021-03-12 21:50:45 +01:00
|
|
|
local effectInstance = self:getEffectObject(effect, character, self.itemdata.duration)
|
2020-09-13 13:25:44 +02:00
|
|
|
effectInstance:applyEffect()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-12 21:14:17 +01:00
|
|
|
function EffectManager:applyEffectsBattle(battleTarget)
|
|
|
|
local character = battleTarget.abstract
|
|
|
|
for _, effect in ipairs(self.itemdata.effects) do
|
2021-03-12 21:50:45 +01:00
|
|
|
local effectInstance = self:getEffectObject(effect, character, self.itemdata.duration)
|
2021-03-12 21:14:17 +01:00
|
|
|
effectInstance:applyEffect()
|
|
|
|
effectInstance:battleCallback(battleTarget)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-13 13:25:44 +02:00
|
|
|
function EffectManager:getEffectStrings(character)
|
|
|
|
local returnString = "No Effect";
|
|
|
|
if (#self.itemdata.effects >= 1) then
|
2021-03-12 21:50:45 +01:00
|
|
|
local effectInstance = self:getEffectObject(self.itemdata.effects[1], character, self.itemdata.duration)
|
2020-09-13 13:25:44 +02:00
|
|
|
if (effectInstance ~= nil) then
|
2020-09-19 11:10:20 +02:00
|
|
|
returnString = effectInstance:getText() .. "\n"
|
2020-09-13 13:25:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if (#self.itemdata.effects >= 2) then
|
2021-03-12 21:50:45 +01:00
|
|
|
local effectInstance = self:getEffectObject(self.itemdata.effects[2], character, self.itemdata.duration)
|
2020-09-13 13:25:44 +02:00
|
|
|
if (effectInstance ~= nil) then
|
2020-09-19 11:10:20 +02:00
|
|
|
returnString = returnString .. effectInstance:getText()
|
2020-09-13 13:25:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return returnString
|
|
|
|
end
|
|
|
|
|
2021-03-12 21:50:45 +01:00
|
|
|
function EffectManager:getEffectObject(rawEffectData, character, duration)
|
2021-05-15 22:48:25 +02:00
|
|
|
local effect = core.datas:parse("itemeffects", rawEffectData)
|
2021-03-12 21:50:45 +01:00
|
|
|
if (effectList[effect.type] ~= nil) then
|
|
|
|
return effectList[effect.type](effect, character, duration)
|
2020-09-13 13:25:44 +02:00
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return EffectManager
|