2020-07-19 15:07:35 +02:00
|
|
|
local FighterParent = Object:extend()
|
|
|
|
|
|
|
|
local counter = 0
|
|
|
|
|
2021-05-09 15:08:46 +02:00
|
|
|
local AERIAL_ACCURACY_FACTOR = 0
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function FighterParent:new(owner, isHero, id)
|
|
|
|
self.owner = owner
|
|
|
|
self.turnSystem = owner.turnSystem
|
|
|
|
self.world = owner.world
|
|
|
|
self.isHero = isHero
|
2020-07-19 16:20:57 +02:00
|
|
|
self.assets = self.turnSystem.scene.assets
|
2020-07-19 15:07:35 +02:00
|
|
|
|
|
|
|
-- 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
|
2020-07-24 19:49:24 +02:00
|
|
|
self.isAlive = true
|
2020-08-05 09:25:38 +02:00
|
|
|
|
2021-03-13 15:49:21 +01:00
|
|
|
self.isDefending = false
|
|
|
|
|
2020-08-05 09:25:38 +02:00
|
|
|
self.action = nil
|
2020-07-24 19:49:24 +02:00
|
|
|
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
|
2020-07-24 19:49:24 +02:00
|
|
|
self.abstract:setHP(value, relative)
|
2020-08-22 23:53:13 +02:00
|
|
|
self.actor:setDamageNumber(relativeNumber)
|
2021-03-12 20:05:54 +01:00
|
|
|
self:updateHP()
|
2020-07-24 19:49:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:setPP(value, relative)
|
|
|
|
self.abstract:setPP(value, relative)
|
2021-03-12 20:05:54 +01:00
|
|
|
self:updatePP()
|
2020-07-24 19:49:24 +02:00
|
|
|
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
|
2020-07-24 19:49:24 +02:00
|
|
|
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
|
|
|
|
|
2020-07-24 19:49:24 +02:00
|
|
|
function FighterParent:die()
|
|
|
|
self.isAlive = false
|
2020-08-05 11:40:29 +02:00
|
|
|
self.actor:die()
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
|
2021-03-12 20:05:54 +01:00
|
|
|
function FighterParent:updatePP()
|
|
|
|
-- Fonction vide
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:updateHP()
|
|
|
|
-- Fonction vide
|
|
|
|
end
|
|
|
|
|
2021-05-15 14:50:12 +02:00
|
|
|
function FighterParent:haveProtecType(type)
|
|
|
|
return self.abstract:haveProtecType(type)
|
|
|
|
end
|
|
|
|
|
2020-07-25 08:44:03 +02:00
|
|
|
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)
|
|
|
|
|
2021-05-09 15:08:46 +02:00
|
|
|
return target:receiveDamage(value, accuracy, isSpecial, isAerial, self)
|
2020-07-25 08:44:03 +02:00
|
|
|
end
|
|
|
|
|
2020-09-13 16:49:50 +02:00
|
|
|
function FighterParent:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho)
|
2020-07-25 08:44:03 +02:00
|
|
|
local stats = self:getStats()
|
2021-05-09 15:08:46 +02:00
|
|
|
local isSuccess = true
|
2020-07-25 08:44:03 +02:00
|
|
|
|
|
|
|
if (isSpecial) then
|
|
|
|
value = value / stats.mind
|
|
|
|
else
|
|
|
|
value = value / stats.defense
|
|
|
|
end
|
|
|
|
|
2021-05-15 14:50:12 +02:00
|
|
|
if (self:haveProtecType("aerial") and not isAerial) then
|
2021-05-09 15:08:46 +02:00
|
|
|
accuracy = accuracy * AERIAL_ACCURACY_FACTOR
|
|
|
|
end
|
|
|
|
|
|
|
|
isSuccess = (math.random(100) <= accuracy)
|
|
|
|
|
|
|
|
if (isSuccess) then
|
|
|
|
core.debug:print("cbs/fighter", "Taken " .. value .. " damage" )
|
|
|
|
if (self.isDefending) then
|
|
|
|
self:setHP(value * -0.66, true)
|
|
|
|
else
|
|
|
|
self:setHP(value * -1, true)
|
|
|
|
self.actor:getHurt()
|
|
|
|
end
|
2021-03-13 15:49:21 +01:00
|
|
|
else
|
2021-05-09 15:08:46 +02:00
|
|
|
self.actor:avoidedAttack()
|
2021-03-13 15:49:21 +01:00
|
|
|
end
|
2021-05-09 15:08:46 +02:00
|
|
|
|
|
|
|
return isSuccess
|
2020-07-25 08:44:03 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function FighterParent:getAbstract()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:createActor()
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:update(dt)
|
2020-08-05 09:25:38 +02:00
|
|
|
if (self.action ~= nil) then
|
|
|
|
if (self.action.isStarted) then
|
|
|
|
self.action:update(dt)
|
|
|
|
end
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-19 16:20:57 +02:00
|
|
|
function FighterParent:updateAssets(dt)
|
|
|
|
-- Vide pour l'instant
|
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function FighterParent:setActive()
|
|
|
|
counter = 0
|
|
|
|
self.isActive = true
|
2021-03-13 15:49:21 +01:00
|
|
|
if (self.isDefending) then
|
|
|
|
self.actor:changeAnimation("idle")
|
|
|
|
self.actor.isDefending = false
|
|
|
|
end
|
2020-07-19 15:07:35 +02:00
|
|
|
self:startAction()
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:setInactive()
|
|
|
|
self.isActive = false
|
2020-07-19 18:09:53 +02:00
|
|
|
self.turnSystem:endAction()
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:getNbrActionPerTurn()
|
|
|
|
return self.abstract.turns
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:getStats()
|
|
|
|
return self.abstract:getStats()
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:startAction()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-08-05 09:25:38 +02:00
|
|
|
function FighterParent:finishAction()
|
|
|
|
self.action = nil
|
|
|
|
self:setInactive()
|
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
function FighterParent:getUniqueIdentificator()
|
|
|
|
local side = 1
|
2020-09-13 16:49:50 +02:00
|
|
|
if (self.isHero == false) then
|
2020-07-19 15:07:35 +02:00
|
|
|
side = -1
|
|
|
|
end
|
|
|
|
return self.id * side
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:getNonUniqueIdentificator()
|
|
|
|
return self.id
|
|
|
|
end
|
|
|
|
|
|
|
|
function FighterParent:canFight()
|
2020-07-24 19:49:24 +02:00
|
|
|
return self.isAlive
|
2020-07-19 15:07:35 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 16:20:57 +02:00
|
|
|
-- DRAW FUNCTIONS
|
|
|
|
|
|
|
|
function FighterParent:drawIcon(x, y)
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.rectangle("fill", x, y, 16, 16)
|
|
|
|
end
|
|
|
|
|
2020-07-19 15:07:35 +02:00
|
|
|
return FighterParent
|