sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua

241 lines
5.5 KiB
Lua
Raw Normal View History

local FighterParent = Object:extend()
local battleutils = require "game.utils.battle"
2021-07-03 12:56:32 +02:00
local STATS = require "datas.consts.stats"
function FighterParent:new(owner, isHero, id)
self.owner = owner
self.turnSystem = owner.turnSystem
self.world = owner.world
self.isHero = isHero
self.assets = self.turnSystem.scene.assets
-- Note : l'ID est ici relatif à chaque quand, il n'est donc pas unique,
-- ce qui est unique étant le combo id + isHero
self.id = id
self.abstract = self:getAbstract()
self.actor = self:createActor()
self.isActive = false
self.isAlive = true
2021-03-13 15:49:21 +01:00
self.isDefending = false
self.action = nil
2021-07-03 13:18:24 +02:00
self.statsBonus = {}
end
-- LIFE handling functions
function FighterParent:setHP(value, relative)
2020-08-22 23:53:13 +02:00
local relativeNumber = value
if (not relative) then
relativeNumber = relative - self.abstract.hp
end
self.abstract:setHP(value, relative)
2020-08-22 23:53:13 +02:00
self.actor:setDamageNumber(relativeNumber)
self:updateHP()
end
function FighterParent:setPP(value, relative)
self.abstract:setPP(value, relative)
self:updatePP()
end
function FighterParent:applyDeath()
2021-03-12 21:50:27 +01:00
if (self.abstract:isAlive() ~= self.isAlive ) then
if (self.abstract:isAlive()) then
self:revive()
else
self:die()
end
end
end
2021-03-12 21:50:27 +01:00
function FighterParent:revive()
self.isAlive = true
2021-03-13 15:49:21 +01:00
self.isDefending = false
2021-03-12 21:50:27 +01:00
self.actor:revive()
end
function FighterParent:die()
self.isAlive = false
2020-08-05 11:40:29 +02:00
self.actor:die()
end
function FighterParent:updatePP()
-- Fonction vide
end
function FighterParent:updateHP()
-- Fonction vide
end
function FighterParent:haveProtecType(type)
return self.abstract:haveProtecType(type)
end
function FighterParent:sendDamageToAll(listTarget, value, type, element, isSpecial)
for _, target in ipairs(listTarget) do
self:sendDamage(target, value, type, element, isSpecial)
end
end
function FighterParent:getTargets(ourSide)
if (self.isHero == ourSide) then
return self.turnSystem.player:getTargets(true)
else
return self.turnSystem.ennemies:getTargets(true)
end
end
function FighterParent:sendDamage(target, value, type, element, isSpecial)
local damage = battleutils.computeLaunchingDamages(value, self, isSpecial)
core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name)
2021-07-03 12:56:32 +02:00
if (battleutils.rollDice(self:getStat(STATS.ACCURACY))) then
return target:receiveDamage(damage, type, element, isSpecial, self)
else
target.actor:avoidedAttack()
return false
end
end
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
local damages = battleutils.computeReceivingDamages(value, self, isSpecial, self.isDefending)
2021-05-16 08:36:06 +02:00
damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes())
2021-05-16 10:06:20 +02:00
damages = battleutils.applyResistences(damages, element, self.abstract:getResistences())
damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses())
2021-07-03 12:56:32 +02:00
if (battleutils.rollDice(self:getStat(STATS.EVASION))) then
self.actor:avoidedAttack()
return false
2021-07-03 12:56:32 +02:00
else
self:applyDamage(damages)
end
return true
end
function FighterParent:applyDamage(damage)
core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" )
self:setHP(damage * -1, true)
if (not self.isDefending) then
self.actor:getHurt()
2021-03-13 15:49:21 +01:00
end
end
function FighterParent:getAbstract()
return {}
end
function FighterParent:createActor()
return {}
end
function FighterParent:update(dt)
if (self.action ~= nil) then
if (self.action.isStarted) then
self.action:update(dt)
end
end
end
function FighterParent:updateAssets(dt)
-- Vide pour l'instant
end
function FighterParent:setActive()
self.isActive = true
2021-03-13 15:49:21 +01:00
if (self.isDefending) then
self.actor:changeAnimation("idle")
self.actor.isDefending = false
end
self:startAction()
end
2021-07-03 12:56:32 +02:00
function FighterParent:applyRegen()
local regenStat = self:getStat(STATS.HPREGEN)
if (regenStat ~= 0) then
self:setHP(regenStat*self:getStat(STATS.HPMAX)/100, true)
end
local regenStat = self:getStat(STATS.PPREGEN)
if (regenStat ~= 0) then
self:setPP(regenStat*self:getStat(STATS.PPMAX)/100, true)
end
end
function FighterParent:setInactive()
self.isActive = false
2021-07-03 12:56:32 +02:00
self:applyRegen()
self.turnSystem:endAction()
end
function FighterParent:getNbrActionPerTurn()
return self.abstract.turns
end
function FighterParent:getStat(statname)
2021-07-03 18:19:08 +02:00
return (self.abstract.stats:get(statname) * self:getStatBonusValue(statname))
2021-07-03 13:18:24 +02:00
end
function FighterParent:getStatBonusValue(statname)
if (utils.table.contain(STATS.NOBONUS, statname)) then
return 1
else
return STATS.BONUS[self:getStatBonus(statname) + 5]
end
2021-07-03 13:18:24 +02:00
end
function FighterParent:getStatBonus(statname)
return self.statsBonus[statname] or 0
end
function FighterParent:setStatBonus(statname, value, relative)
local statBonus = 0
if (relative) then
statBonus = self:getStatBonus(statname)
end
self.statsBonus[statname] = math.max(-4, math.min(statBonus + value, 4))
end
function FighterParent:getStats()
return self.abstract:getStats()
end
function FighterParent:startAction()
end
function FighterParent:finishAction()
self.action = nil
self:setInactive()
end
function FighterParent:getUniqueIdentificator()
local side = 1
if (self.isHero == false) then
side = -1
end
return self.id * side
end
function FighterParent:getNonUniqueIdentificator()
return self.id
end
function FighterParent:canFight()
return self.isAlive
end
-- DRAW FUNCTIONS
function FighterParent:drawIcon(x, y)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.rectangle("fill", x, y, 16, 16)
end
return FighterParent