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

147 lines
2.9 KiB
Lua
Raw Normal View History

local FighterParent = Object:extend()
local counter = 0
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.action = nil
end
-- LIFE handling functions
function FighterParent:setHP(value, relative)
self.abstract:setHP(value, relative)
end
function FighterParent:setPP(value, relative)
self.abstract:setPP(value, relative)
end
function FighterParent:applyDeath()
if (self.abstract.hp <= 0 and self.isAlive) then
self:die()
end
end
function FighterParent:die()
self.isAlive = false
2020-08-05 11:40:29 +02:00
self.actor:die()
end
function FighterParent:sendDamage(target, value, accuracy, isSpecial, isAerial)
local stats = self:getStats()
local value = value / 10
if (isSpecial) then
value = value * stats.power
else
value = value * stats.attack
end
core.debug:print("cbs/battler", "Sending " .. value .." damage at " .. target.name)
target:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho)
end
function FighterParent:receiveDamage(value, accuracy, isSpecial, isAerial)
local stats = self:getStats()
if (isSpecial) then
value = value / stats.mind
else
value = value / stats.defense
end
core.debug:print("cbs/fighter", "Taken " .. value .. " damage" )
self:setHP(value * -1, true)
2020-08-05 11:40:29 +02:00
self.actor:getHurt()
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()
counter = 0
self.isActive = true
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 (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