feat: add battle definition files

Fix #9
This commit is contained in:
Kazhnuz 2020-08-04 17:50:03 +02:00
parent 1935659378
commit 58264e2a19
14 changed files with 256 additions and 29 deletions

View file

@ -0,0 +1,12 @@
return {
music = "battle1",
ennemies = {
{"normal", "classics", "motobug", 2},
{"normal", "classics", "motobug", 1}}
}
-- There are three possible type of ennemies
-- NORMAL {"normal", category, name, number}
-- BOSS : {"boss", category, pvbonus, statbonus}
-- RIVALS : {"rival", charname, level, pvbonus}

View file

@ -0,0 +1,13 @@
return {
music = "battle1",
ennemies = {
{"normal", "classics", "motobug", 1},
{"boss", "classics", "motobug", 2, 1.2, true},
{"normal", "classics", "motobug", 1}}
}
-- There are three possible type of ennemies
-- NORMAL {"normal", category, name, number}
-- BOSS : {"boss", category, pvbonus, statbonus}
-- RIVALS : {"rival", charname, level, pvbonus}

View file

@ -2,29 +2,27 @@ AbstractMobParent = require "game.abstractmobs.parent"
AbstractEnnemy = AbstractMobParent:extend() AbstractEnnemy = AbstractMobParent:extend()
local ennutils = require "game.utils.ennemies"
function AbstractEnnemy:new(directory, name) function AbstractEnnemy:new(directory, name)
self.simplename = name self.simplename = name
self.directory = directory self.directory = directory
self.super.new(self) self.super.new(self)
end end
function AbstractEnnemy:getDirectory()
return "datas.gamedata.ennemies." .. self.directory .. "."
end
function AbstractEnnemy:initBasicElements() function AbstractEnnemy:initBasicElements()
self.data = require(self:getDirectory() .. self.simplename) self.data = ennutils.getData(self.directory, self.simplename)
self.name = self.data.name self.name = self.data.name
self.fullname = self.data.fullname self.fullname = self.data.fullname
self.turns = self.data.turns self.turns = self.data.turns
end end
function AbstractEnnemy:createStats() function AbstractEnnemy:createStats()
return require(self:getDirectory() .. self.simplename .. ".stats") return self.data.stats
end end
function AbstractEnnemy:createSkills() function AbstractEnnemy:createSkills()
return require(self:getDirectory() .. self.simplename .. ".skills") return self.data.skills
end end
return AbstractEnnemy return AbstractEnnemy

View file

@ -65,4 +65,18 @@ function AbstractMobParent:getStats()
return self.stats return self.stats
end end
-- Bonus stuff
function AbstractMobParent:setBonus(pvFactor, statFactor)
self.stats.hpmax = self.stats.hpmax * pvFactor
self.hp = self.stats.hpmax
self.stats.attack = self.stats.attack * statFactor
self.stats.power = self.stats.power * statFactor
self.stats.defense = self.stats.defense * statFactor
self.stats.mind = self.stats.mind * statFactor
self.stats.technic = self.stats.technic * statFactor
self.stats.speed = self.stats.speed * statFactor
end
return AbstractMobParent return AbstractMobParent

View file

@ -6,8 +6,8 @@ function EnnemyManager:new(controller)
self.controller = controller self.controller = controller
end end
function EnnemyManager:getEnnemyData(ennemy) function EnnemyManager:getEnnemyData(category, ennemy)
return AbstractEnnemy("classics", ennemy) return AbstractEnnemy(category, ennemy)
end end
return EnnemyManager return EnnemyManager

View file

@ -0,0 +1,5 @@
return {
["normal"] = {"category", "name", "number"},
["boss"] = {"category", "name", "pvFactor", "statFactor", "cheapEffect"},
["rival"] = {"character", "level", "pvFactor"}
}

View file

@ -0,0 +1,74 @@
BattleUtils = {}
local datasutils = require "game.utils.datas"
local DIR = "battles"
function BattleUtils.getBaseDirectory(lua)
return datasutils.concatDataFolder(DIR, lua)
end
function BattleUtils.listCategories()
return love.filesystem.getDirectoryItems(BattleUtils.getBaseDirectory(false))
end
function BattleUtils.getCategoryDirectory(directory, lua)
local baseDir = BattleUtils.getBaseDirectory(lua)
return datasutils.concatFolder(baseDir, directory, lua)
end
function BattleUtils.getDirectoryLuaStyle(directory)
return REQUIREDIR .. "." .. directory
end
function BattleUtils.getBattleFromCategory(directory)
local folder = BattleUtils.getCategoryDirectory(directory, false)
return datasutils.luaFileListToModuleList(love.filesystem.getDirectoryItems(folder))
end
function BattleUtils.getBattleData(directory, battlename)
local categoryDir = BattleUtils.getCategoryDirectory(directory, true)
return datasutils.require(categoryDir, battlename)
end
-- ENNEMY FUNCTIONS
function BattleUtils.getEnnemyTypeStructure(type)
local typeList = require "game.utils.battle.arguments"
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

View file

@ -0,0 +1,45 @@
local EnnemyUtils = {}
local datasutils = require "game.utils.datas"
local DIR = "ennemies"
function EnnemyUtils.getBaseDirectory(lua)
return datasutils.concatDataFolder(DIR, lua)
end
function EnnemyUtils.listCategories()
return require(EnnemyUtils.getBaseDirectory(true))
end
function EnnemyUtils.getCategoryDirectory(directory, lua)
return datasutils.concatFolder(EnnemyUtils.getBaseDirectory(lua), directory, lua)
end
function EnnemyUtils.getEnnemyFolder(directory, ennemy, lua)
local categoryDirectory = EnnemyUtils.getCategoryDirectory(directory, lua)
return datasutils.concatFolder(categoryDirectory, ennemy, lua)
end
function EnnemyUtils.getEnnemiesFromCategory(directory)
local folder = EnnemyUtils.getCategoryDirectory(directory, false)
return love.filesystem.getDirectoryItems(folder)
end
function EnnemyUtils.dataExists(directory, name)
local dir = datasutils.concatFolder(EnnemyUtils.getEnnemyFolder(directory, name, false), "init.lua", false)
local fileinfo = love.filesystem.getInfo(dir)
return (fileinfo ~= nil)
end
function EnnemyUtils.getData(directory, name)
-- va eprmettre de récupérer les données d'un personnage
local folder = EnnemyUtils.getEnnemyFolder(directory, name, true)
local ennemy = require(folder)
ennemy.stats = datasutils.require(folder, "stats")
ennemy.skills = datasutils.require(folder, "skills")
return ennemy
end
return EnnemyUtils

View file

@ -3,19 +3,38 @@ local EnnemyController = FighterControllerParent:extend()
local Villain = require "scenes.battlesystem.controllers.fighters.villain" local Villain = require "scenes.battlesystem.controllers.fighters.villain"
function EnnemyController:new(owner) local battleutils = require "game.utils.battle"
function EnnemyController:new(owner, battleData)
self.super.new(self, owner) self.super.new(self, owner)
self:initVillains() self:initVillains(battleData)
end end
function EnnemyController:initVillains() function EnnemyController:initVillains(battleData)
self:addVillain("motobug") for i,ennemyBaseData in ipairs(battleData.ennemies) do
self:addVillain("motobug") local ennData = battleutils.getEnnemyData(ennemyBaseData)
self:addVillain("motobug") if (ennData.type == "normal") then
self:addVillain(ennData)
elseif (ennData.type == "boss") then
self:addBoss(ennData)
else
print("unknown type " .. ennData.type)
end
end
end end
function EnnemyController:addVillain(name) function EnnemyController:addVillain(ennData)
self:add(Villain(self, name, self:count() + 1)) for i=1, ennData.number do
self:add(Villain(self, ennData.category, ennData.name, self:count() + 1))
end
end
function EnnemyController:addBoss(ennData)
local boss = Villain(self, ennData.category, ennData.name, self:count() + 1)
boss:setBonus(ennData.pvFactor, ennData.statFactor)
boss.isBoss = true
boss.cheapEffect = ennData.cheapEffect
self:add(boss)
end end
return EnnemyController return EnnemyController

View file

@ -6,11 +6,13 @@ local SimpleHPBar = require "game.modules.gui.simplehpbar"
local POSITIONS = {1, 3, 5} local POSITIONS = {1, 3, 5}
local ENNEMY_LINE = 11; local ENNEMY_LINE = 11;
function VillainFighter:new(owner, ennemy, id) function VillainFighter:new(owner, category, ennemy, id)
self.name = ennemy self.name = ennemy
self.category = category
self.super.new(self, owner, false, id) self.super.new(self, owner, false, id)
self.hpbar = SimpleHPBar(self.abstract.hp) self.hpbar = SimpleHPBar(self.abstract.hp)
self.isBoss = false
end end
function VillainFighter:updateAssets(dt) function VillainFighter:updateAssets(dt)
@ -19,7 +21,7 @@ end
function VillainFighter:getAbstract() function VillainFighter:getAbstract()
return game.ennemies:getEnnemyData(self.name) return game.ennemies:getEnnemyData(self.category, self.name)
end end
function VillainFighter:createActor() function VillainFighter:createActor()
@ -40,6 +42,10 @@ function FighterParent:die()
self.actor:destroy() self.actor:destroy()
end end
function VillainFighter:setBonus(pvFactor, statFactor)
self.abstract:setBonus(pvFactor, statFactor)
end
-- LIFE FUNCTIONS -- LIFE FUNCTIONS
function VillainFighter:setHP(value, relative) function VillainFighter:setHP(value, relative)
VillainFighter.super.setHP(self, value, relative) VillainFighter.super.setHP(self, value, relative)
@ -54,7 +60,9 @@ function VillainFighter:drawIcon(x, y)
end end
function VillainFighter:drawHUD(x, y) function VillainFighter:drawHUD(x, y)
self.hpbar:draw(x, y) if (not self.isBoss) then
self.hpbar:draw(x, y)
end
end end
return VillainFighter return VillainFighter

View file

@ -7,7 +7,7 @@ local HUD = require "scenes.battlesystem.gui.hud"
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
function TurnController:new(scene) function TurnController:new(scene, battleData)
self.scene = scene self.scene = scene
self.world = scene.world self.world = scene.world
@ -27,7 +27,7 @@ function TurnController:new(scene)
self.hud = HUD(self) self.hud = HUD(self)
self.player = Player(self) self.player = Player(self)
self.ennemies = Ennemy(self) self.ennemies = Ennemy(self, battleData)
end end
function TurnController:startBattle() function TurnController:startBattle()

View file

@ -8,15 +8,14 @@ local Turns = require "scenes.battlesystem.controllers"
local VictoryScreen = require "scenes.battlesystem.screens.victory" local VictoryScreen = require "scenes.battlesystem.screens.victory"
function BattleSystem:new() function BattleSystem:new(battleData)
BattleSystem.super.new(self) BattleSystem.super.new(self)
self.assets:batchImport("scenes.battlesystem.assets") self.assets:batchImport("scenes.battlesystem.assets")
self.assets:setMusic("assets/music/battle1.mp3") self:playMusic(battleData.music)
self.assets:playMusic()
self:initManagers() self:initManagers(battleData)
self:register() self:register()
@ -25,11 +24,16 @@ function BattleSystem:new()
self.screen = nil self.screen = nil
end end
function BattleSystem:initManagers() function BattleSystem:playMusic(music)
self.assets:setMusic("assets/music/" .. music .. ".mp3")
self.assets:playMusic()
end
function BattleSystem:initManagers(battleData)
self.datas = {} self.datas = {}
self.world = World(self) self.world = World(self)
self.menu = MenuSystem(self) self.menu = MenuSystem(self)
self.turns = Turns(self) self.turns = Turns(self, battleData)
end end
function BattleSystem:startBattle() function BattleSystem:startBattle()

View file

@ -3,6 +3,7 @@ local menu = require "scenes.debug.menu.menu"
local DebugMenu = Scene:extend() local DebugMenu = Scene:extend()
local panels = require "scenes.debug.menu.infopanel" local panels = require "scenes.debug.menu.infopanel"
local battleutils = require "game.utils.battle"
function DebugMenu:new() function DebugMenu:new()
DebugMenu.super.new(self) DebugMenu.super.new(self)
@ -30,11 +31,30 @@ end
function DebugMenu:buildBattleMenu() function DebugMenu:buildBattleMenu()
self:addSubMenu("combat", "BaseMenu", "Battle System") self:addSubMenu("combat", "BaseMenu", "Battle System")
menu.commons.SceneWidget(self, "combat", scenes.cbs, "Launch Battle") self:addSubMenu("launchBattle", "combat", "Launch Battle")
local listCat = battleutils.listCategories()
for i,battleCat in ipairs(listCat) do
self:addBattles(battleCat)
end
menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.battleBack, "Background Viewer") menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.battleBack, "Background Viewer")
menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.choregraphy, "Ennemies' Action Viewer") menu.commons.SceneWidget(self, "combat", scenes.debug.viewers.choregraphy, "Ennemies' Action Viewer")
menu.commons.SubMenuWidget(self, "combat", "BaseMenu", "Back") menu.commons.SubMenuWidget(self, "combat", "BaseMenu", "Back")
menu.commons.SubMenuWidget(self, "launchBattle", "combat", "Back")
end
function DebugMenu:addBattles(battleCat)
local menuName = "b_" .. battleCat
self:addSubMenu(menuName, "launchBattle", battleCat)
for i,battleName in ipairs(battleutils.getBattleFromCategory(battleCat)) do
local data = battleutils.getBattleData(battleCat, battleName)
menu.commons.SceneWidget(self, menuName, scenes.cbs, "Launch " .. battleName, data)
end
menu.commons.SubMenuWidget(self, menuName, "launchBattle", "Back")
end end
function DebugMenu:buildSaveMenu() function DebugMenu:buildSaveMenu()

View file

@ -6,6 +6,7 @@ local ChoregraphyViewer = Scene:extend()
local World = require "scenes.battlesystem.world" local World = require "scenes.battlesystem.world"
local Fighter = require "scenes.debug.viewers.choregraphy.mocks.fighter" local Fighter = require "scenes.debug.viewers.choregraphy.mocks.fighter"
local ennutils = require "game.utils.ennemies"
function ChoregraphyViewer:new() function ChoregraphyViewer:new()
ChoregraphyViewer.super.new(self) ChoregraphyViewer.super.new(self)
@ -28,6 +29,10 @@ function ChoregraphyViewer:buildMenu()
end end
function ChoregraphyViewer:buildCharacterMenu() function ChoregraphyViewer:buildCharacterMenu()
for i,category in ipairs(ennutils.listCategories()) do
self:buildEnnemyListMenu(category)
end
self:addSubMenu("characters", "MainMenu", "Rivals") self:addSubMenu("characters", "MainMenu", "Rivals")
for k, character in pairs(game.characters.list) do for k, character in pairs(game.characters.list) do
self:addSubMenu(k, "characters", character.fullname) self:addSubMenu(k, "characters", character.fullname)
@ -38,6 +43,16 @@ function ChoregraphyViewer:buildCharacterMenu()
menu.commons.SubMenuWidget(self, "characters", "MainMenu", "Back") menu.commons.SubMenuWidget(self, "characters", "MainMenu", "Back")
end end
function ChoregraphyViewer:buildEnnemyListMenu(category)
self:addSubMenu(category, "MainMenu", category)
for i,ennemy in ipairs(ennutils.getEnnemiesFromCategory(category)) do
self:addSubMenu(ennemy, category, ennemy)
menu.commons.SubMenuWidget(self, ennemy, category, "Back")
end
menu.commons.SubMenuWidget(self, category, "MainMenu", "Back")
end
function ChoregraphyViewer:buildSkillMenu(charName) function ChoregraphyViewer:buildSkillMenu(charName)
local skillList = require("datas.gamedata.characters." .. charName .. ".skills") local skillList = require("datas.gamedata.characters." .. charName .. ".skills")
local skillTreated = {} local skillTreated = {}