diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index ac8cd14..0d0148c 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -69,6 +69,13 @@ function Hero:getNewAnimation(animation) end end +function Hero:flee() + if (not self.isKo) then + self:changeAnimation("walk") + self:goTo(-80, self.y, 3) + end +end + -- DRAW FUNCTIONS -- Draw everything related to the hero diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua index d9a2652..b8e5e01 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua @@ -29,11 +29,22 @@ function EnnemyController:addVillain(ennData) end end +function EnnemyController:getHighestSpeed() + local highestSpeed = 0 + for i, villain in ipairs(self.list) do + if (villain.abstract.stats.speed > highestSpeed) then + highestSpeed = villain.abstract.stats.speed + end + end + return highestSpeed +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:setCheapEffect(ennData.cheapEffect) + self.owner.canFleeBattle = false self:add(boss) end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua index def62b6..0e0a949 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua @@ -11,7 +11,21 @@ end function FleeAction:startAction() core.debug:print("cbs/action", "Starting flee action") - self:finishAction() + if (self.fighter.abstract.name == "shadow") then + self.fighter.turns.hud:showMessage("You won't flee the battle") + self:finishAction() + return + end + + local chanceToFlee = self.fighter.turnSystem:getChanceTooFlee(self.fighter.abstract.stats.speed) + if (math.random(100) < chanceToFlee) then + self.fighter.turnSystem.hud:showMessage("You flee the battle") + self.fighter.turnSystem:fleeBattle() + else + self.fighter.turnSystem.hud:showMessage("You failed to flee the battle") + self:finishAction() + end + end return FleeAction diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua index 4d96f2e..91490a4 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/init.lua @@ -24,6 +24,8 @@ function TurnController:new(scene, battleData) self.currentFighter = nil + self.canFleeBattle = true + self.hud = HUD(self) self.player = Player(self) @@ -34,6 +36,18 @@ function TurnController:new(scene, battleData) self:applyDeath() end +function TurnController:getChanceTooFlee(value) + if (self.canFleeBattle) then + local speedComparison = math.min(value / self.ennemies:getHighestSpeed(), 1.5) + return 25 + (50 * speedComparison) + end +end + +function TurnController:fleeBattle() + self.player:fleeBattle() + self.scene:fleeBattle() +end + function TurnController:showMessage(message) self.hud:showMessage(message) end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/player.lua b/sonic-radiance.love/scenes/battlesystem/controllers/player.lua index 007e734..cf9d54f 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/player.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/player.lua @@ -14,6 +14,13 @@ function HeroFighterController:initHeroes() end end + +function HeroFighterController:fleeBattle() + for i, hero in ipairs(self.list) do + hero.actor:flee() + end +end + function HeroFighterController:draw() for i, hero in ipairs(self.list) do hero:drawHUD() diff --git a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua b/sonic-radiance.love/scenes/battlesystem/gui/hud.lua index fd4b856..47e9127 100644 --- a/sonic-radiance.love/scenes/battlesystem/gui/hud.lua +++ b/sonic-radiance.love/scenes/battlesystem/gui/hud.lua @@ -26,7 +26,6 @@ end function HUD:showMessage(message) self.message = message self.messageOpacity = 1 - self.tweens:resetTweens() self.tweens:newTween(0, 0.2, {messageOpacity = 1}, 'inOutCubic') self.tweens:newTween(1, 0.2, {messageOpacity = 0}, 'inOutCubic') end diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index 2fa39e3..2fe636d 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -9,6 +9,8 @@ local Turns = require "scenes.battlesystem.controllers" local VictoryScreen = require "scenes.battlesystem.screens.victory" local GameOverScreen = require "scenes.battlesystem.screens.gameover" +local TweenManager = require "game.modules.tweenmanager" + function BattleSystem:new(battleData) BattleSystem.super.new(self) @@ -23,6 +25,7 @@ function BattleSystem:new(battleData) self:startBattle() self.screen = nil + self.tweens = TweenManager(self) end function BattleSystem:playMusic(music) @@ -47,6 +50,17 @@ function BattleSystem:finishBattle() self.screen = VictoryScreen(self) end +function BattleSystem:fleeBattle() + self.tweens:newTimer(2, "flee") +end + +function BattleSystem:timerResponse(name) + if (name == "flee") then + --placeholder, pour l'instant on retourne juste au menu + scenes.debug.menu() + end +end + function BattleSystem:looseBattle() self.screen = GameOverScreen(self) end @@ -59,6 +73,7 @@ function BattleSystem:haveMenus() end function BattleSystem:update(dt) + self.tweens:update(dt) self.world:update(dt) self.turns:update(dt) if (self.screen ~= nil) then