feat: add flee system

This commit is contained in:
Kazhnuz 2021-03-13 18:00:39 +01:00
parent e32cd09804
commit c83eb7ee61
7 changed files with 69 additions and 2 deletions

View file

@ -69,6 +69,13 @@ function Hero:getNewAnimation(animation)
end end
end end
function Hero:flee()
if (not self.isKo) then
self:changeAnimation("walk")
self:goTo(-80, self.y, 3)
end
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- Draw everything related to the hero -- Draw everything related to the hero

View file

@ -29,11 +29,22 @@ function EnnemyController:addVillain(ennData)
end end
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) function EnnemyController:addBoss(ennData)
local boss = Villain(self, ennData.category, ennData.name, self:count() + 1) local boss = Villain(self, ennData.category, ennData.name, self:count() + 1)
boss:setBonus(ennData.pvFactor, ennData.statFactor) boss:setBonus(ennData.pvFactor, ennData.statFactor)
boss.isBoss = true boss.isBoss = true
boss:setCheapEffect(ennData.cheapEffect) boss:setCheapEffect(ennData.cheapEffect)
self.owner.canFleeBattle = false
self:add(boss) self:add(boss)
end end

View file

@ -11,7 +11,21 @@ end
function FleeAction:startAction() function FleeAction:startAction()
core.debug:print("cbs/action", "Starting flee action") core.debug:print("cbs/action", "Starting flee action")
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() self:finishAction()
end end
end
return FleeAction return FleeAction

View file

@ -24,6 +24,8 @@ function TurnController:new(scene, battleData)
self.currentFighter = nil self.currentFighter = nil
self.canFleeBattle = true
self.hud = HUD(self) self.hud = HUD(self)
self.player = Player(self) self.player = Player(self)
@ -34,6 +36,18 @@ function TurnController:new(scene, battleData)
self:applyDeath() self:applyDeath()
end 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) function TurnController:showMessage(message)
self.hud:showMessage(message) self.hud:showMessage(message)
end end

View file

@ -14,6 +14,13 @@ function HeroFighterController:initHeroes()
end end
end end
function HeroFighterController:fleeBattle()
for i, hero in ipairs(self.list) do
hero.actor:flee()
end
end
function HeroFighterController:draw() function HeroFighterController:draw()
for i, hero in ipairs(self.list) do for i, hero in ipairs(self.list) do
hero:drawHUD() hero:drawHUD()

View file

@ -26,7 +26,6 @@ end
function HUD:showMessage(message) function HUD:showMessage(message)
self.message = message self.message = message
self.messageOpacity = 1 self.messageOpacity = 1
self.tweens:resetTweens()
self.tweens:newTween(0, 0.2, {messageOpacity = 1}, 'inOutCubic') self.tweens:newTween(0, 0.2, {messageOpacity = 1}, 'inOutCubic')
self.tweens:newTween(1, 0.2, {messageOpacity = 0}, 'inOutCubic') self.tweens:newTween(1, 0.2, {messageOpacity = 0}, 'inOutCubic')
end end

View file

@ -9,6 +9,8 @@ local Turns = require "scenes.battlesystem.controllers"
local VictoryScreen = require "scenes.battlesystem.screens.victory" local VictoryScreen = require "scenes.battlesystem.screens.victory"
local GameOverScreen = require "scenes.battlesystem.screens.gameover" local GameOverScreen = require "scenes.battlesystem.screens.gameover"
local TweenManager = require "game.modules.tweenmanager"
function BattleSystem:new(battleData) function BattleSystem:new(battleData)
BattleSystem.super.new(self) BattleSystem.super.new(self)
@ -23,6 +25,7 @@ function BattleSystem:new(battleData)
self:startBattle() self:startBattle()
self.screen = nil self.screen = nil
self.tweens = TweenManager(self)
end end
function BattleSystem:playMusic(music) function BattleSystem:playMusic(music)
@ -47,6 +50,17 @@ function BattleSystem:finishBattle()
self.screen = VictoryScreen(self) self.screen = VictoryScreen(self)
end 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() function BattleSystem:looseBattle()
self.screen = GameOverScreen(self) self.screen = GameOverScreen(self)
end end
@ -59,6 +73,7 @@ function BattleSystem:haveMenus()
end end
function BattleSystem:update(dt) function BattleSystem:update(dt)
self.tweens:update(dt)
self.world:update(dt) self.world:update(dt)
self.turns:update(dt) self.turns:update(dt)
if (self.screen ~= nil) then if (self.screen ~= nil) then