From ef4bf26ba65adb295d0e226bfe63e3e4fa4fdb6e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 13 Sep 2020 13:25:44 +0200 Subject: [PATCH] feat: initial effect manager system --- .../game/loot/effectManager.lua | 47 +++++++++++++++++++ .../game/loot/effects/init.lua | 3 ++ .../game/loot/effects/parent.lua | 15 ++++++ sonic-radiance.love/game/loot/init.lua | 12 +++++ .../game/utils/items/arguments.lua | 6 +++ sonic-radiance.love/game/utils/items/init.lua | 38 +++++++++++++++ .../overworld/screens/mainmenu/items.lua | 2 + 7 files changed, 123 insertions(+) create mode 100644 sonic-radiance.love/game/loot/effectManager.lua create mode 100644 sonic-radiance.love/game/loot/effects/init.lua create mode 100644 sonic-radiance.love/game/loot/effects/parent.lua create mode 100644 sonic-radiance.love/game/utils/items/arguments.lua diff --git a/sonic-radiance.love/game/loot/effectManager.lua b/sonic-radiance.love/game/loot/effectManager.lua new file mode 100644 index 0000000..d3a9d99 --- /dev/null +++ b/sonic-radiance.love/game/loot/effectManager.lua @@ -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 diff --git a/sonic-radiance.love/game/loot/effects/init.lua b/sonic-radiance.love/game/loot/effects/init.lua new file mode 100644 index 0000000..a210b28 --- /dev/null +++ b/sonic-radiance.love/game/loot/effects/init.lua @@ -0,0 +1,3 @@ +return { + +} \ No newline at end of file diff --git a/sonic-radiance.love/game/loot/effects/parent.lua b/sonic-radiance.love/game/loot/effects/parent.lua new file mode 100644 index 0000000..f055836 --- /dev/null +++ b/sonic-radiance.love/game/loot/effects/parent.lua @@ -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 diff --git a/sonic-radiance.love/game/loot/init.lua b/sonic-radiance.love/game/loot/init.lua index 9f01831..7b6e636 100644 --- a/sonic-radiance.love/game/loot/init.lua +++ b/sonic-radiance.love/game/loot/init.lua @@ -1,5 +1,6 @@ local LootManager = Object:extend() local Pocket = require "game.loot.pocket" +local EffectManager = require "game.loot.effectManager" local itemutils = require "game.utils.items" @@ -8,6 +9,7 @@ function LootManager:new(controller) self.rings = 0 self.inventory = {} self.pocketIndex = {} + self.effects = EffectManager() self:generatePockets() end @@ -58,4 +60,14 @@ function LootManager:getItemNumber(type, item) return pocket:getItemNumber(item) 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 diff --git a/sonic-radiance.love/game/utils/items/arguments.lua b/sonic-radiance.love/game/utils/items/arguments.lua new file mode 100644 index 0000000..b1683b8 --- /dev/null +++ b/sonic-radiance.love/game/utils/items/arguments.lua @@ -0,0 +1,6 @@ +return { + ["heal"] = {"healType", "computationMode", "value"}, + ["setStatus"] = {"status", "set"}, + ["protectElement"] = {"element"}, + ["blockStatus"] = {"blockWhat"}, +} diff --git a/sonic-radiance.love/game/utils/items/init.lua b/sonic-radiance.love/game/utils/items/init.lua index bcae584..41edd6d 100644 --- a/sonic-radiance.love/game/utils/items/init.lua +++ b/sonic-radiance.love/game/utils/items/init.lua @@ -42,4 +42,42 @@ function ItemUtils.getItemData(category, item) return datasutils.copy(path) 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 diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua index f3a45b1..fd3f3d0 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/items.lua @@ -113,11 +113,13 @@ end function ItemWidget:new(scene, pocket, item) self.item = item 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) end function ItemWidget:selectAction() self.scene.currentScreen.desc = self.itemData.description + self.scene.currentScreen.effects = game.loot:getEffectStrings(self.pocket, self.item.name) end --BackWidget