2021-08-21 17:00:42 +02:00
|
|
|
local Scene = require "game.scenes"
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-03-10 13:26:20 +01:00
|
|
|
local BattleSystem = Scene:extend()
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
local World = require "scenes.battlesystem.world"
|
2021-08-15 16:41:33 +02:00
|
|
|
local Turns = require "scenes.battlesystem.turns"
|
2019-03-10 13:26:20 +01:00
|
|
|
|
2021-09-18 21:31:17 +02:00
|
|
|
local VictoryScreen = require "scenes.battlesystem.gui.victory"
|
2021-09-16 22:06:59 +02:00
|
|
|
local GameOverScreen = require "game.modules.gui.gameover"
|
2019-08-16 22:37:43 +02:00
|
|
|
|
2021-09-16 22:26:59 +02:00
|
|
|
local CbsScreen = require "scenes.battlesystem.gui"
|
|
|
|
|
2021-05-05 11:41:25 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
2021-03-13 18:00:39 +01:00
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
function BattleSystem:new(battleData)
|
2022-01-06 14:34:45 +01:00
|
|
|
BattleSystem.super.new(self, false, false)
|
2021-08-15 16:01:25 +02:00
|
|
|
self.assets:batchImport("assets.battle")
|
2019-08-13 21:08:37 +02:00
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
self:playMusic(battleData.music)
|
|
|
|
self:initManagers(battleData)
|
2019-08-16 18:33:47 +02:00
|
|
|
self:startBattle()
|
2019-08-16 22:37:43 +02:00
|
|
|
|
2021-09-16 22:26:59 +02:00
|
|
|
CbsScreen()
|
|
|
|
|
2019-08-16 22:37:43 +02:00
|
|
|
self.screen = nil
|
2021-03-13 18:00:39 +01:00
|
|
|
self.tweens = TweenManager(self)
|
2019-03-10 13:26:20 +01:00
|
|
|
end
|
|
|
|
|
2020-08-04 17:50:03 +02:00
|
|
|
function BattleSystem:playMusic(music)
|
|
|
|
self.assets:setMusic("assets/music/" .. music .. ".mp3")
|
|
|
|
self.assets:playMusic()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:initManagers(battleData)
|
2019-03-10 13:26:20 +01:00
|
|
|
self.datas = {}
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world = World(self)
|
2020-08-04 17:50:03 +02:00
|
|
|
self.turns = Turns(self, battleData)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-08-16 18:33:47 +02:00
|
|
|
function BattleSystem:startBattle()
|
2020-05-01 14:50:21 +02:00
|
|
|
self.turns:startBattle()
|
2019-08-16 18:33:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:finishBattle()
|
2019-08-19 12:00:24 +02:00
|
|
|
self.assets:setMusic("assets/music/victory.mp3")
|
|
|
|
self.assets:playMusic()
|
2021-09-18 21:31:17 +02:00
|
|
|
VictoryScreen(self)
|
2019-08-16 18:33:47 +02:00
|
|
|
end
|
|
|
|
|
2021-03-13 18:00:39 +01:00
|
|
|
function BattleSystem:fleeBattle()
|
|
|
|
self.tweens:newTimer(2, "flee")
|
|
|
|
end
|
|
|
|
|
|
|
|
function BattleSystem:timerResponse(name)
|
|
|
|
if (name == "flee") then
|
2021-04-02 22:25:26 +02:00
|
|
|
self:returnToOverworld(true)
|
2021-03-13 18:00:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-02 22:25:26 +02:00
|
|
|
function BattleSystem:returnToOverworld(isFleeing)
|
|
|
|
self.assets:silence()
|
|
|
|
game.cbs:endBattle(isFleeing)
|
|
|
|
end
|
|
|
|
|
2020-08-07 11:17:10 +02:00
|
|
|
function BattleSystem:looseBattle()
|
2021-09-16 22:06:59 +02:00
|
|
|
GameOverScreen(self)
|
2020-08-07 11:17:10 +02:00
|
|
|
end
|
|
|
|
|
2019-08-24 15:44:07 +02:00
|
|
|
function BattleSystem:haveMenus()
|
2021-09-16 22:26:59 +02:00
|
|
|
return self.gui.elements["battleMenu"].isVisible
|
2019-08-24 15:44:07 +02:00
|
|
|
end
|
|
|
|
|
2019-03-10 13:11:26 +01:00
|
|
|
function BattleSystem:update(dt)
|
2021-03-13 18:00:39 +01:00
|
|
|
self.tweens:update(dt)
|
2020-05-01 14:50:21 +02:00
|
|
|
self.turns:update(dt)
|
2021-09-18 21:31:17 +02:00
|
|
|
self.world:update(dt)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-03-10 13:26:20 +01:00
|
|
|
function BattleSystem:exit()
|
|
|
|
self.world:destroy()
|
|
|
|
self.battlearena = nil
|
2019-03-10 13:11:26 +01:00
|
|
|
|
|
|
|
collectgarbage()
|
|
|
|
end
|
|
|
|
|
|
|
|
return BattleSystem
|