feat: initial effect manager system
This commit is contained in:
parent
3f265c0b5d
commit
ef4bf26ba6
7 changed files with 123 additions and 0 deletions
47
sonic-radiance.love/game/loot/effectManager.lua
Normal file
47
sonic-radiance.love/game/loot/effectManager.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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: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
|
||||||
|
returnString = effectInstance:applyEffect() .. "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (#self.itemdata.effects >= 2) then
|
||||||
|
local effectInstance = self:getEffectObject(self.itemdata.effects[2], character)
|
||||||
|
if (effectInstance ~= nil) then
|
||||||
|
returnString = effectInstance:applyEffect()
|
||||||
|
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
|
3
sonic-radiance.love/game/loot/effects/init.lua
Normal file
3
sonic-radiance.love/game/loot/effects/init.lua
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
15
sonic-radiance.love/game/loot/effects/parent.lua
Normal file
15
sonic-radiance.love/game/loot/effects/parent.lua
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
local EffectParent = Object:extend()
|
||||||
|
|
||||||
|
function EffectParent:new(effect, character)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function EffectParent:applyEffect()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function EffectParent:getText()
|
||||||
|
return "No effect"
|
||||||
|
end
|
||||||
|
|
||||||
|
return EffectParent
|
|
@ -1,5 +1,6 @@
|
||||||
local LootManager = Object:extend()
|
local LootManager = Object:extend()
|
||||||
local Pocket = require "game.loot.pocket"
|
local Pocket = require "game.loot.pocket"
|
||||||
|
local EffectManager = require "game.loot.effectManager"
|
||||||
|
|
||||||
local itemutils = require "game.utils.items"
|
local itemutils = require "game.utils.items"
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ function LootManager:new(controller)
|
||||||
self.rings = 0
|
self.rings = 0
|
||||||
self.inventory = {}
|
self.inventory = {}
|
||||||
self.pocketIndex = {}
|
self.pocketIndex = {}
|
||||||
|
self.effects = EffectManager()
|
||||||
|
|
||||||
self:generatePockets()
|
self:generatePockets()
|
||||||
end
|
end
|
||||||
|
@ -58,4 +60,14 @@ function LootManager:getItemNumber(type, item)
|
||||||
return pocket:getItemNumber(item)
|
return pocket:getItemNumber(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function LootManager:applyItemEffect(category, item, target)
|
||||||
|
self.effects:getItemData(category, item)
|
||||||
|
self.effects:applyItemEffect(target)
|
||||||
|
end
|
||||||
|
|
||||||
|
function LootManager:getEffectStrings(category, item)
|
||||||
|
self.effects:getItemData(category, item)
|
||||||
|
return self.effects:getEffectStrings(nil)
|
||||||
|
end
|
||||||
|
|
||||||
return LootManager
|
return LootManager
|
||||||
|
|
6
sonic-radiance.love/game/utils/items/arguments.lua
Normal file
6
sonic-radiance.love/game/utils/items/arguments.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
return {
|
||||||
|
["heal"] = {"healType", "computationMode", "value"},
|
||||||
|
["setStatus"] = {"status", "set"},
|
||||||
|
["protectElement"] = {"element"},
|
||||||
|
["blockStatus"] = {"blockWhat"},
|
||||||
|
}
|
|
@ -42,4 +42,42 @@ function ItemUtils.getItemData(category, item)
|
||||||
return datasutils.copy(path)
|
return datasutils.copy(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- VALIDATION FUNCTIONS
|
||||||
|
|
||||||
|
function ItemUtils.getItemEffectStructure(type)
|
||||||
|
local typeList = require "game.utils.items.arguments"
|
||||||
|
return typeList[type]
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.itemEffectExists(type)
|
||||||
|
return (ItemUtils.getItemEffectStructure(type) ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.validateItemEffect(effectBaseData)
|
||||||
|
local structure = ItemUtils.getItemEffectStructure(effectBaseData[1])
|
||||||
|
if (structure == nil) then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return ((#structure + 1) == #effectBaseData)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemUtils.getItemEffectData(effectBaseData)
|
||||||
|
local effectData = {}
|
||||||
|
effectData.type = effectBaseData[1]
|
||||||
|
|
||||||
|
if (ItemUtils.validateItemEffect(effectBaseData)) then
|
||||||
|
local structure = ItemUtils.getItemEffectStructure(effectData.type)
|
||||||
|
|
||||||
|
for i, argumentName in ipairs(structure) do
|
||||||
|
local argumentContent = effectBaseData[i + 1]
|
||||||
|
effectData[argumentName] = argumentContent
|
||||||
|
end
|
||||||
|
|
||||||
|
return effectData
|
||||||
|
else
|
||||||
|
error("Le type d'effet d'objet " .. effectData.type .. " à un nbr d'argument incorrect")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return ItemUtils
|
return ItemUtils
|
||||||
|
|
|
@ -113,11 +113,13 @@ end
|
||||||
function ItemWidget:new(scene, pocket, item)
|
function ItemWidget:new(scene, pocket, item)
|
||||||
self.item = item
|
self.item = item
|
||||||
self.itemData = game.loot:getItemData(pocket, self.item.name)
|
self.itemData = game.loot:getItemData(pocket, self.item.name)
|
||||||
|
self.pocket = pocket
|
||||||
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. self.item.number)
|
ItemWidget.super.new(self, scene, "menu", self.itemData.fullname, "x" .. self.item.number)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ItemWidget:selectAction()
|
function ItemWidget:selectAction()
|
||||||
self.scene.currentScreen.desc = self.itemData.description
|
self.scene.currentScreen.desc = self.itemData.description
|
||||||
|
self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--BackWidget
|
--BackWidget
|
||||||
|
|
Loading…
Reference in a new issue