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
|
||||
|
||||
table.insert(self.qte.list, success)
|
||||
self.rewards:addQTE(success)
|
||||
end
|
||||
|
||||
function QteMixin:removeQte()
|
||||
|
|
|
@ -6,6 +6,9 @@ function InfosMixin:initWrappers(action, target)
|
|||
self.actor = self.fighter.actor
|
||||
self.assets = self.fighter.actor.assets
|
||||
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)
|
||||
end
|
||||
|
|
|
@ -140,9 +140,13 @@ end
|
|||
function FighterParent:applyDamage(damage)
|
||||
core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" )
|
||||
self:setHP(damage * -1, true)
|
||||
self.owner:registerDamage(damage)
|
||||
if (not self.isDefending) then
|
||||
self.actor:getHurt()
|
||||
end
|
||||
if (not self.abstract:isAlive()) then
|
||||
self.owner:registerKO()
|
||||
end
|
||||
end
|
||||
|
||||
function FighterParent:getAbstract()
|
||||
|
|
|
@ -4,6 +4,8 @@ function FighterControllerParent:new(turnSystem)
|
|||
self.turnSystem = turnSystem
|
||||
self.world = turnSystem.world
|
||||
self.list = {}
|
||||
self.damages = 0
|
||||
self.ko = 0
|
||||
end
|
||||
|
||||
function FighterControllerParent:get(id)
|
||||
|
@ -22,6 +24,14 @@ function FighterControllerParent:count()
|
|||
return #self.list
|
||||
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()
|
||||
local aliveCount = 0
|
||||
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 Ennemy = require "scenes.battlesystem.fighters.ennemies"
|
||||
|
||||
local Rewards = require "scenes.battlesystem.rewards"
|
||||
|
||||
local maputils = require "scenes.battlesystem.utils"
|
||||
|
||||
function TurnController:new(scene, battleData)
|
||||
|
@ -29,6 +31,8 @@ function TurnController:new(scene, battleData)
|
|||
self.player = Player(self)
|
||||
self.ennemies = Ennemy(self, battleData)
|
||||
|
||||
self.rewards = Rewards(self)
|
||||
|
||||
-- Change the seed at the start of each battle
|
||||
math.randomseed( os.time() )
|
||||
self:applyDeath()
|
||||
|
@ -55,6 +59,7 @@ function TurnController:finishBattle()
|
|||
self.isActive = false
|
||||
self.actionlist = {}
|
||||
self.scene:finishBattle()
|
||||
self.rewards:apply()
|
||||
end
|
||||
|
||||
function TurnController:looseBattle()
|
||||
|
@ -80,16 +85,20 @@ function TurnController:update(dt)
|
|||
end
|
||||
|
||||
function TurnController:getRank()
|
||||
return 3
|
||||
return self.rewards:getRank()
|
||||
end
|
||||
|
||||
function TurnController:getRewards()
|
||||
local exp, ring = 0, 0
|
||||
for i, ennemy in ipairs(self.ennemies.list) do
|
||||
exp = exp + ennemy.abstract.data.giveExp
|
||||
ring = ring + ennemy.abstract.data.giveRings
|
||||
end
|
||||
return exp, ring
|
||||
return self.rewards:getRewards(false)
|
||||
end
|
||||
|
||||
function TurnController:getDatas()
|
||||
local ennemyNbr = #self.ennemies.list
|
||||
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
|
||||
|
||||
function TurnController:nextAction()
|
||||
|
|
Loading…
Reference in a new issue