sonic-radiance/sonic-radiance.love/game/modules/subgames/ennemies.lua

53 lines
1.4 KiB
Lua
Raw Normal View History

2022-05-28 11:55:40 +02:00
local EnnemyController = Object:extend()
local Villain = require "scenes.battlesystem.fighters.ennemy"
local STATS = require "datas.consts.stats"
function EnnemyController:new(scene)
self.super.new(self)
self.scene = scene
self.list = {}
end
function EnnemyController:addAll(ennemies)
local count = self:countList(ennemies)
for i, ennemyBaseData in ipairs(ennemies) do
local ennData = core.datas:parse("ennemytype", ennemyBaseData)
local nbr = ennData.number or 1
for i=1, nbr do
self:add(ennData, count)
end
end
end
function EnnemyController:countList(ennemies)
local count = 0
for i, ennemyBaseData in ipairs(ennemies) do
local ennData = core.datas:parse("ennemytype", ennemyBaseData)
local nbr = ennData.number or 1
count = count + nbr
end
return count
end
function EnnemyController:getEnnemyArchetype(ennData)
if (ennData.archetype ~= nil) then
return ennData.archetype
end
return ennData.name
end
function EnnemyController:add(ennData, count)
local ennemy = {}
ennemy.type = ennData.type
ennemy.name = ennData.name
ennemy.category = ennData.category
ennemy.actor = nil
ennemy.isAlive = true
ennemy.data = ennData
table.insert(self.list, ennemy)
self.scene.world:spawnEnnemy(self:getEnnemyArchetype(ennData), ennemy, count)
end
return EnnemyController