From 1acada1b5198aeba4e37be4ecdcdc40e39ad6187 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 25 Jul 2020 12:15:50 +0200 Subject: [PATCH] fix: re-add victory condition --- .../scenes/battlesystem/controllers/init.lua | 7 +++++-- .../scenes/battlesystem/controllers/parent.lua | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua index 1f5b376..26b3826 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua @@ -36,7 +36,7 @@ function TurnController:startBattle() end function TurnController:finishBattle() - self.isBattleActive = false + self.isActive = false self.actionlist = {} self.hud:movePlayerHUD(false) self.scene:finishBattle() @@ -90,7 +90,10 @@ function TurnController:removeAllActionsFromFighter(fighterToRemove) end function TurnController:applyDeath() - self.ennemies:applyDeath() + local ennemiesAlive = self.ennemies:applyDeath() + if (ennemiesAlive == 0) then + self:finishBattle() + end self.player:applyDeath() end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua index 15342a5..7ac8d5f 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua @@ -18,6 +18,16 @@ function FighterControllerParent:count() return #self.list end +function FighterControllerParent:countAlive() + local aliveCount = 0 + for i, fighter in ipairs(self.list) do + if (fighter:canFight()) then + aliveCount = aliveCount + 1 + end + end + return aliveCount +end + function FighterControllerParent:getTargets(onlyAlive) local targetList = {} for i, fighter in ipairs(self.list) do @@ -32,6 +42,7 @@ function FighterControllerParent:applyDeath() for i, fighter in ipairs(self.list) do fighter:applyDeath() end + return self:countAlive() end function FighterControllerParent:setActive(activeActor)