43 lines
1.1 KiB
Lua
43 lines
1.1 KiB
Lua
local BattleUtils = {}
|
|
|
|
-- ENNEMY FUNCTIONS
|
|
|
|
function BattleUtils.getEnnemyTypeStructure(type)
|
|
local typeList = require "datas.parsers.ennemytype"
|
|
return typeList[type]
|
|
end
|
|
|
|
function BattleUtils.ennemyTypeExists(type)
|
|
return (BattleUtils.getEnnemyTypeStructure(type) ~= nil)
|
|
end
|
|
|
|
function BattleUtils.validateEnnemyType(ennemyBaseData)
|
|
local structure = BattleUtils.getEnnemyTypeStructure(ennemyBaseData[1])
|
|
if (structure == nil) then
|
|
return false
|
|
else
|
|
return ((#structure + 1) == #ennemyBaseData)
|
|
end
|
|
end
|
|
|
|
function BattleUtils.getEnnemyData(ennemyBaseData)
|
|
local ennemyData = {}
|
|
ennemyData.type = ennemyBaseData[1]
|
|
|
|
if (BattleUtils.validateEnnemyType(ennemyBaseData)) then
|
|
local structure = BattleUtils.getEnnemyTypeStructure(ennemyData.type)
|
|
|
|
for i, argumentName in ipairs(structure) do
|
|
local argumentContent = ennemyBaseData[i + 1]
|
|
ennemyData[argumentName] = argumentContent
|
|
end
|
|
|
|
return ennemyData
|
|
else
|
|
error("Le type d'ennemy " .. ennemyData.type .. " à un nbr d'argument incorrect")
|
|
end
|
|
|
|
|
|
end
|
|
|
|
return BattleUtils
|