chore: put the damage handling system inside fighters and not actors
This commit is contained in:
parent
4f024dbb39
commit
d69255ead0
5 changed files with 46 additions and 38 deletions
|
@ -14,7 +14,6 @@ end
|
|||
|
||||
function Battler:destroy()
|
||||
Battler.super.destroy(self)
|
||||
self.world:destroyBattler(self)
|
||||
end
|
||||
|
||||
function Battler:setActive()
|
||||
|
@ -39,40 +38,4 @@ function Battler:validateAction()
|
|||
|
||||
end
|
||||
|
||||
function Battler:sendDamage(x, y, 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("battler", "sending " .. value .." damage at position <" .. x .. ";" .. y .. ">")
|
||||
|
||||
local fromEnnemy = self.isEnnemy
|
||||
|
||||
local other = self.world:getActorInCase(x, y, self)
|
||||
if (other ~= nil) then
|
||||
core.debug:print("battler", "sending damage to actor at position <" .. x .. ";" .. y .. ">")
|
||||
other:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function Battler:receiveDamage(value, accuracy, isSpecial, isAerial)
|
||||
local stats = self:getStats()
|
||||
if (fromEnnemy ~= self.isEnnemy) then
|
||||
if (isSpecial) then
|
||||
value = value / stats.mind
|
||||
else
|
||||
value = value / stats.defense
|
||||
end
|
||||
core.debug:print("battler", "taken " .. value .. " damage" )
|
||||
self:setHP(value * -1, true)
|
||||
end
|
||||
end
|
||||
|
||||
return Battler
|
||||
|
|
|
@ -31,7 +31,7 @@ function FighterParent:setPP(value, relative)
|
|||
end
|
||||
|
||||
function FighterParent:applyDeath()
|
||||
if (self.hp <= 0 and self.isAlive) then
|
||||
if (self.abstract.hp <= 0 and self.isAlive) then
|
||||
self:die()
|
||||
end
|
||||
end
|
||||
|
@ -40,6 +40,34 @@ function FighterParent:die()
|
|||
self.isAlive = false
|
||||
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)
|
||||
end
|
||||
|
||||
function FighterParent:getAbstract()
|
||||
return {}
|
||||
end
|
||||
|
|
|
@ -35,6 +35,11 @@ function VillainFighter:endAction()
|
|||
|
||||
end
|
||||
|
||||
function FighterParent:die()
|
||||
self.isAlive = false
|
||||
self.actor:destroy()
|
||||
end
|
||||
|
||||
-- LIFE FUNCTIONS
|
||||
function VillainFighter:setHP(value, relative)
|
||||
VillainFighter.super.setHP(self, value, relative)
|
||||
|
|
|
@ -90,6 +90,12 @@ function TurnController:removeAllActionsFromFighter(fighterToRemove)
|
|||
end
|
||||
end
|
||||
|
||||
function TurnController:applyDeath()
|
||||
self.ennemies:applyDeath()
|
||||
self.player:applyDeath()
|
||||
end
|
||||
|
||||
|
||||
function TurnController:startAction()
|
||||
core.debug:print("cbs/turns", "Starting action " .. self.turns.current)
|
||||
local nextAction = self.actionList[self.turns.current]
|
||||
|
|
|
@ -18,6 +18,12 @@ function FighterControllerParent:count()
|
|||
return #self.list
|
||||
end
|
||||
|
||||
function FighterControllerParent:applyDeath()
|
||||
for i, fighter in ipairs(self.list) do
|
||||
fighter:applyDeath()
|
||||
end
|
||||
end
|
||||
|
||||
function FighterControllerParent:setActive(activeActor)
|
||||
self.activeActor = activeActor
|
||||
activeActor:setActive()
|
||||
|
|
Loading…
Reference in a new issue