Refonte pour utiliser le systeme de GUI #112
6 changed files with 113 additions and 7 deletions
|
@ -38,6 +38,7 @@ function QteMixin:endQte(success)
|
||||||
self.qte.wasSuccess = success
|
self.qte.wasSuccess = success
|
||||||
|
|
||||||
table.insert(self.qte.list, success)
|
table.insert(self.qte.list, success)
|
||||||
|
self.rewards:addQTE(success)
|
||||||
end
|
end
|
||||||
|
|
||||||
function QteMixin:removeQte()
|
function QteMixin:removeQte()
|
||||||
|
|
|
@ -6,6 +6,9 @@ function InfosMixin:initWrappers(action, target)
|
||||||
self.actor = self.fighter.actor
|
self.actor = self.fighter.actor
|
||||||
self.assets = self.fighter.actor.assets
|
self.assets = self.fighter.actor.assets
|
||||||
self.world = self.actor.world
|
self.world = self.actor.world
|
||||||
|
self.scene = self.world.scene
|
||||||
|
self.turns = self.scene.turns
|
||||||
|
self.rewards = self.turns.rewards
|
||||||
|
|
||||||
self:initTargets(target or action.target)
|
self:initTargets(target or action.target)
|
||||||
end
|
end
|
||||||
|
|
|
@ -140,9 +140,13 @@ end
|
||||||
function FighterParent:applyDamage(damage)
|
function FighterParent:applyDamage(damage)
|
||||||
core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" )
|
core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" )
|
||||||
self:setHP(damage * -1, true)
|
self:setHP(damage * -1, true)
|
||||||
|
self.owner:registerDamage(damage)
|
||||||
if (not self.isDefending) then
|
if (not self.isDefending) then
|
||||||
self.actor:getHurt()
|
self.actor:getHurt()
|
||||||
end
|
end
|
||||||
|
if (not self.abstract:isAlive()) then
|
||||||
|
self.owner:registerKO()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function FighterParent:getAbstract()
|
function FighterParent:getAbstract()
|
||||||
|
|
|
@ -4,6 +4,8 @@ function FighterControllerParent:new(turnSystem)
|
||||||
self.turnSystem = turnSystem
|
self.turnSystem = turnSystem
|
||||||
self.world = turnSystem.world
|
self.world = turnSystem.world
|
||||||
self.list = {}
|
self.list = {}
|
||||||
|
self.damages = 0
|
||||||
|
self.ko = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function FighterControllerParent:get(id)
|
function FighterControllerParent:get(id)
|
||||||
|
@ -22,6 +24,14 @@ function FighterControllerParent:count()
|
||||||
return #self.list
|
return #self.list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function FighterControllerParent:registerDamage(damage)
|
||||||
|
self.damages = math.floor(self.damages + damage)
|
||||||
|
end
|
||||||
|
|
||||||
|
function FighterControllerParent:registerKO()
|
||||||
|
self.ko = self.ko + 1
|
||||||
|
end
|
||||||
|
|
||||||
function FighterControllerParent:countAlive()
|
function FighterControllerParent:countAlive()
|
||||||
local aliveCount = 0
|
local aliveCount = 0
|
||||||
for i, fighter in ipairs(self.list) do
|
for i, fighter in ipairs(self.list) do
|
||||||
|
|
79
sonic-radiance.love/scenes/battlesystem/rewards.lua
Normal file
79
sonic-radiance.love/scenes/battlesystem/rewards.lua
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
local Rewards = Object:extend()
|
||||||
|
|
||||||
|
local rankFactor = {1, 1.25, 1.5, 1.75, 2}
|
||||||
|
|
||||||
|
function Rewards:new(turns)
|
||||||
|
self.turns = turns
|
||||||
|
self.qte = 0
|
||||||
|
self.qteSuccess = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:apply()
|
||||||
|
local _, rings = self:getRewards(true)
|
||||||
|
game.loot.rings = game.loot.rings + rings
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:getRank()
|
||||||
|
local ennemyNbr, turns, _, _, ko = self.turns:getDatas()
|
||||||
|
local qteSuccess, haveDoneQte = self:getQteSuccessRate()
|
||||||
|
local rank = 3
|
||||||
|
|
||||||
|
if (not haveDoneQte) then
|
||||||
|
rank = 3
|
||||||
|
elseif (qteSuccess >= 0.75) then
|
||||||
|
rank = 4
|
||||||
|
elseif (qteSuccess >= 0.5) then
|
||||||
|
rank = 3
|
||||||
|
elseif (qteSuccess >= 0.25) then
|
||||||
|
rank = 2
|
||||||
|
else
|
||||||
|
rank = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: modifier l'effet de nombre de tour pour les boss
|
||||||
|
if (turns/ennemyNbr > 3) then
|
||||||
|
rank = rank - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if (ko == 0) then
|
||||||
|
rank = rank + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return math.max(1, math.min(5, rank))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:getExp(character)
|
||||||
|
local exp = self:getRewards(true)
|
||||||
|
return character.abstract.exp + exp
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:getRewards(real)
|
||||||
|
local exp, ring = 0, 0
|
||||||
|
for i, ennemy in ipairs(self.turns.ennemies.list) do
|
||||||
|
exp = exp + ennemy.abstract.data.giveExp
|
||||||
|
ring = ring + ennemy.abstract.data.giveRings
|
||||||
|
end
|
||||||
|
|
||||||
|
if (real) then
|
||||||
|
exp = exp * rankFactor[self:getRank()]
|
||||||
|
ring = ring * rankFactor[self:getRank()]
|
||||||
|
end
|
||||||
|
|
||||||
|
return exp, ring
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:getQteSuccessRate()
|
||||||
|
if (self.qte == 0) then
|
||||||
|
return 0, false
|
||||||
|
end
|
||||||
|
return self.qteSuccess/self.qte, true
|
||||||
|
end
|
||||||
|
|
||||||
|
function Rewards:addQTE(success)
|
||||||
|
self.qte = self.qte + 1
|
||||||
|
if (success) then
|
||||||
|
self.qteSuccess = self.qteSuccess + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Rewards
|
|
@ -3,6 +3,8 @@ local TurnController = Object:extend()
|
||||||
local Player = require "scenes.battlesystem.fighters.player"
|
local Player = require "scenes.battlesystem.fighters.player"
|
||||||
local Ennemy = require "scenes.battlesystem.fighters.ennemies"
|
local Ennemy = require "scenes.battlesystem.fighters.ennemies"
|
||||||
|
|
||||||
|
local Rewards = require "scenes.battlesystem.rewards"
|
||||||
|
|
||||||
local maputils = require "scenes.battlesystem.utils"
|
local maputils = require "scenes.battlesystem.utils"
|
||||||
|
|
||||||
function TurnController:new(scene, battleData)
|
function TurnController:new(scene, battleData)
|
||||||
|
@ -29,6 +31,8 @@ function TurnController:new(scene, battleData)
|
||||||
self.player = Player(self)
|
self.player = Player(self)
|
||||||
self.ennemies = Ennemy(self, battleData)
|
self.ennemies = Ennemy(self, battleData)
|
||||||
|
|
||||||
|
self.rewards = Rewards(self)
|
||||||
|
|
||||||
-- Change the seed at the start of each battle
|
-- Change the seed at the start of each battle
|
||||||
math.randomseed( os.time() )
|
math.randomseed( os.time() )
|
||||||
self:applyDeath()
|
self:applyDeath()
|
||||||
|
@ -55,6 +59,7 @@ function TurnController:finishBattle()
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
self.actionlist = {}
|
self.actionlist = {}
|
||||||
self.scene:finishBattle()
|
self.scene:finishBattle()
|
||||||
|
self.rewards:apply()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:looseBattle()
|
function TurnController:looseBattle()
|
||||||
|
@ -80,16 +85,20 @@ function TurnController:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:getRank()
|
function TurnController:getRank()
|
||||||
return 3
|
return self.rewards:getRank()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:getRewards()
|
function TurnController:getRewards()
|
||||||
local exp, ring = 0, 0
|
return self.rewards:getRewards(false)
|
||||||
for i, ennemy in ipairs(self.ennemies.list) do
|
end
|
||||||
exp = exp + ennemy.abstract.data.giveExp
|
|
||||||
ring = ring + ennemy.abstract.data.giveRings
|
function TurnController:getDatas()
|
||||||
end
|
local ennemyNbr = #self.ennemies.list
|
||||||
return exp, ring
|
local turns = self.turns.current
|
||||||
|
local dmgSent = self.ennemies.damages
|
||||||
|
local dmgTaken = self.player.damages
|
||||||
|
local ko = self.player.ko
|
||||||
|
return ennemyNbr, turns, dmgSent, dmgTaken, ko
|
||||||
end
|
end
|
||||||
|
|
||||||
function TurnController:nextAction()
|
function TurnController:nextAction()
|
||||||
|
|
Loading…
Reference in a new issue