From 40b362543afb10dd5c684cb22e5476a9c24eac34 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 25 Jul 2020 12:09:50 +0200 Subject: [PATCH] fix: only get potential targets for the selection system --- .../controllers/fighters/character.lua | 4 ++-- .../controllers/fighters/systems/selection.lua | 14 +++++++------- .../scenes/battlesystem/controllers/parent.lua | 10 ++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua index 0abc3ce..a35e22f 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua @@ -81,9 +81,9 @@ function HeroFighter:verifyTargets() if (needTarget) then if (targetEnnemies) then - self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies) + self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies, true) else - self.selection = SelectionSystem(self, self.owner) + self.selection = SelectionSystem(self, self.owner, false) end else self.action:start() diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua index 2d57620..1db4db9 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua @@ -1,7 +1,7 @@ local SelectionSystem = Object:extend() -function SelectionSystem:new(owner, fighterList) - self.fighterList = fighterList +function SelectionSystem:new(owner, fighterSide, onlyAlive) + self.fighterList = fighterSide:getTargets(onlyAlive) self.owner = owner self.assets = self.owner.assets self.selectedTarget = 1 @@ -13,14 +13,14 @@ function SelectionSystem:update(dt) self:purgeTarget() if (keys["up"].isPressed) then if (self.selectedTarget == 1) then - self.selectedTarget = self.fighterList:count() + self.selectedTarget = #self.fighterList else self.selectedTarget = self.selectedTarget - 1 end self.assets.sfx["mBeep"]:play() end if (keys["down"].isPressed) then - if (self.selectedTarget == self.fighterList:count()) then + if (self.selectedTarget == #self.fighterList) then self.selectedTarget = 1 else self.selectedTarget = self.selectedTarget + 1 @@ -43,18 +43,18 @@ function SelectionSystem:update(dt) end function SelectionSystem:purgeTarget() - local target = self.fighterList:get(self.selectedTarget) + local target = self.fighterList[self.selectedTarget] target.actor.isSelected = false end function SelectionSystem:updateTarget() - local target = self.fighterList:get(self.selectedTarget) + local target = self.fighterList[self.selectedTarget] target.actor.isSelected = true end function SelectionSystem:selectTarget() self:purgeTarget() - self.owner:receiveTarget(self.fighterList:get(self.selectedTarget)) + self.owner:receiveTarget(self.fighterList[self.selectedTarget]) end function SelectionSystem:goBack() diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua index 69cb720..15342a5 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:getTargets(onlyAlive) + local targetList = {} + for i, fighter in ipairs(self.list) do + if (fighter:canFight() or (not onlyAlive)) then + table.insert(targetList, fighter) + end + end + return targetList +end + function FighterControllerParent:applyDeath() for i, fighter in ipairs(self.list) do fighter:applyDeath()