sonic-radiance/sonic-radiance.love/game/loot/effectManager.lua

57 lines
1.7 KiB
Lua
Raw Normal View History

2020-09-13 13:25:44 +02:00
local EffectManager = Object:extend()
local itemutils = require "game.utils.items"
local effectList = require "game.loot.effects"
function EffectManager:new()
self.itemdata = nil;
end
function EffectManager:getItemData(category, item)
self.itemdata = itemutils.getItemData(category, item)
end
function EffectManager:applyEffects(character)
for _, effect in ipairs(self.itemdata.effects) do
local effectInstance = self:getEffectObject(effect, character)
effectInstance:applyEffect()
end
end
function EffectManager:applyEffectsBattle(battleTarget)
local character = battleTarget.abstract
for _, effect in ipairs(self.itemdata.effects) do
local effectInstance = self:getEffectObject(effect, character)
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
local effectInstance = self:getEffectObject(self.itemdata.effects[1], character)
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
local effectInstance = self:getEffectObject(self.itemdata.effects[2], character)
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
function EffectManager:getEffectObject(rawEffectData, character)
local effect = itemutils.getItemEffectData(rawEffectData)
if (effectList[effect.type] ~= nil) then
return effectList[effect.type](effect, character)
else
return nil
end
end
return EffectManager