sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua
2021-05-16 10:06:20 +02:00

182 lines
4 KiB
Lua

local FighterParent = Object:extend()
local battleutils = require "game.utils.battle"
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
self.isDefending = false
self.action = nil
end
-- LIFE handling functions
function FighterParent:setHP(value, relative)
local relativeNumber = value
if (not relative) then
relativeNumber = relative - self.abstract.hp
end
self.abstract:setHP(value, relative)
self.actor:setDamageNumber(relativeNumber)
self:updateHP()
end
function FighterParent:setPP(value, relative)
self.abstract:setPP(value, relative)
self:updatePP()
end
function FighterParent:applyDeath()
if (self.abstract:isAlive() ~= self.isAlive ) then
if (self.abstract:isAlive()) then
self:revive()
else
self:die()
end
end
end
function FighterParent:revive()
self.isAlive = true
self.isDefending = false
self.actor:revive()
end
function FighterParent:die()
self.isAlive = false
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:sendDamage(target, value, type, element, isSpecial)
local damage = battleutils.computeLaunchingDamages(value, self:getStats(), isSpecial)
core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name)
return target:receiveDamage(damage, type, element, isSpecial, self)
end
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending)
damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes())
damages = battleutils.applyResistences(damages, element, self.abstract:getResistences())
damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses())
if (battleutils.isAttackSuccess(nil)) then
self:applyDamage(damages)
else
self.actor:avoidedAttack()
return false
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()
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
if (self.isDefending) then
self.actor:changeAnimation("idle")
self.actor.isDefending = false
end
self:startAction()
end
function FighterParent:setInactive()
self.isActive = false
self.turnSystem:endAction()
end
function FighterParent:getNbrActionPerTurn()
return self.abstract.turns
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