2019-08-14 16:26:23 +02:00
|
|
|
local Parent = require("scenes.battlesystem.actors.parent")
|
|
|
|
local Battler = Parent:extend()
|
|
|
|
|
|
|
|
function Battler:new(world, x, y, z)
|
|
|
|
Battler.super.new(self, world, x, y, z)
|
|
|
|
|
|
|
|
self.isBattler = true
|
|
|
|
self.speed = 3
|
|
|
|
self.isActive = false
|
|
|
|
self.debugActiveTimer = 0
|
2020-06-05 10:02:04 +02:00
|
|
|
|
|
|
|
self.side = ""
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
2019-08-15 19:00:01 +02:00
|
|
|
function Battler:destroy()
|
|
|
|
Battler.super.destroy(self)
|
|
|
|
self.world:destroyBattler(self)
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Battler:setActive()
|
|
|
|
core.debug:print("cbs/actor","actor " .. self.id .. " is active")
|
|
|
|
self.isActive = true
|
|
|
|
self.debugActiveTimer = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:update(dt)
|
2019-08-16 23:04:30 +02:00
|
|
|
Battler.super.update(self, dt)
|
2019-08-14 16:26:23 +02:00
|
|
|
if (self.isActive) then
|
|
|
|
self.debugActiveTimer = self.debugActiveTimer + dt
|
|
|
|
if self.debugActiveTimer >= 0.5 then
|
2019-08-14 20:44:20 +02:00
|
|
|
core.debug:print("cbs/battler", "counter ended, switching active battler")
|
2019-08-14 16:26:23 +02:00
|
|
|
self.isActive = false
|
2019-08-15 19:00:01 +02:00
|
|
|
self.world:switchActiveBattler()
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:validateAction()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-08-15 15:06:13 +02:00
|
|
|
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
|
|
|
|
|
2019-08-25 15:54:26 +02:00
|
|
|
local other = self.world:getActorInCase(x, y, self)
|
2019-08-15 15:06:13 +02:00
|
|
|
if (other ~= nil) then
|
|
|
|
core.debug:print("battler", "sending damage to actor at position <" .. x .. ";" .. y .. ">")
|
|
|
|
other:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho)
|
2019-08-19 11:54:06 +02:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
2019-08-15 15:06:13 +02:00
|
|
|
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
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
return Battler
|