feat: initial effect manager system

This commit is contained in:
Kazhnuz 2020-09-13 13:25:44 +02:00
parent 3f265c0b5d
commit ef4bf26ba6
7 changed files with 123 additions and 0 deletions

View 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

View file

@ -0,0 +1,3 @@
return {
}

View 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

View file

@ -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

View file

@ -0,0 +1,6 @@
return {
["heal"] = {"healType", "computationMode", "value"},
["setStatus"] = {"status", "set"},
["protectElement"] = {"element"},
["blockStatus"] = {"blockWhat"},
}

View file

@ -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

View file

@ -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