From 698d6697fbdc621c7f641ba899918672ed595cf9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 19 Jul 2020 13:13:54 +0200 Subject: [PATCH] chore: add a basic abstractmob system --- .../game/abstractmobs/ennemy.lua | 26 +++++++++++ .../game/abstractmobs/parent.lua | 45 +++++++++++++++++++ sonic-radiance.love/game/ennemies.lua | 8 ++-- 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 sonic-radiance.love/game/abstractmobs/ennemy.lua create mode 100644 sonic-radiance.love/game/abstractmobs/parent.lua diff --git a/sonic-radiance.love/game/abstractmobs/ennemy.lua b/sonic-radiance.love/game/abstractmobs/ennemy.lua new file mode 100644 index 0000000..65df743 --- /dev/null +++ b/sonic-radiance.love/game/abstractmobs/ennemy.lua @@ -0,0 +1,26 @@ +AbstractMobParent = require "game.abstractmobs.parent" + +AbstractEnnemy = AbstractMobParent:extend() + +function AbstractEnnemy:new(name) + self.simplename = name + self.super.new(self) +end + +function AbstractEnnemy:initBasicElements() + self.data = require("datas.gamedata.ennemies." .. self.simplename) + self.name = self.data.name + self.fullname = self.data.fullname + self.turns = self.data.turns + +end + +function AbstractEnnemy:createStats() + return require("datas.gamedata.ennemies." .. self.simplename .. ".stats") +end + +function AbstractEnnemy:createSkills() + return require("datas.gamedata.ennemies." .. self.simplename .. ".skills") +end + +return AbstractEnnemy diff --git a/sonic-radiance.love/game/abstractmobs/parent.lua b/sonic-radiance.love/game/abstractmobs/parent.lua new file mode 100644 index 0000000..b3ee25e --- /dev/null +++ b/sonic-radiance.love/game/abstractmobs/parent.lua @@ -0,0 +1,45 @@ +local AbstractMobParent = Object:extend() + +function AbstractMobParent:new() + self:initBasicElements() + self.stats = self:createStats() + self.skills = self:createSkills() + self:initLife() +end + +function AbstractMobParent:initBasicElements() + self.name = "PlaceHolder" + self.fullname = "PlaceHolder" + self.turns = 2 +end + +function AbstractMobParent:createStats() + local stats = {} + + stats.hpmax = 0 + stats.ppmax = 0 + stats.attack = 0 + stats.power = 0 + stats.defense = 0 + stats.technic = 0 + stats.mind = 0 + stats.speed = 0 + + return stats +end + +function AbstractMobParent:createSkills() + return {} +end + +function AbstractMobParent:initLife() + self.hp = self.stats.hpmax + self.mp = self.stats.mpmax + self.status = 0 +end + +function AbstractMobParent:getStats() + return self.stats +end + +return AbstractMobParent diff --git a/sonic-radiance.love/game/ennemies.lua b/sonic-radiance.love/game/ennemies.lua index 60336f1..4a656eb 100644 --- a/sonic-radiance.love/game/ennemies.lua +++ b/sonic-radiance.love/game/ennemies.lua @@ -1,15 +1,13 @@ local EnnemyManager = Object:extend() +local AbstractEnnemy = require "game.abstractmobs.ennemy" + function EnnemyManager:new(controller) self.controller = controller end function EnnemyManager:getEnnemyData(ennemy) - local data = require("datas.gamedata.ennemies." .. ennemy) - data.skills = require("datas.gamedata.ennemies." .. ennemy .. ".skills") - data.stats = require("datas.gamedata.ennemies." .. ennemy .. ".stats") - - return data + return AbstractEnnemy(ennemy) end return EnnemyManager