2021-08-06 20:18:48 +02:00
|
|
|
local Parent = require("scenes.battlesystem.actors.movable")
|
2019-08-14 16:26:23 +02:00
|
|
|
local Battler = Parent:extend()
|
|
|
|
|
2021-05-09 15:07:38 +02:00
|
|
|
local outputColor = {
|
|
|
|
good = {0, 1, 0},
|
|
|
|
bad = {1, 0, 0},
|
|
|
|
pp = {0.3, 0.8, 1}
|
|
|
|
}
|
|
|
|
|
2020-08-03 17:38:30 +02:00
|
|
|
function Battler:new(world, x, y, z, owner)
|
2019-08-14 16:26:23 +02:00
|
|
|
Battler.super.new(self, world, x, y, z)
|
|
|
|
|
|
|
|
self.isBattler = true
|
|
|
|
self.isActive = false
|
|
|
|
self.debugActiveTimer = 0
|
2020-07-19 21:41:14 +02:00
|
|
|
|
2021-05-09 15:07:38 +02:00
|
|
|
self.output = {}
|
|
|
|
self.output.string = "0"
|
|
|
|
self.output.isBad = true
|
|
|
|
self.output.type = ""
|
|
|
|
self.showOutput = false
|
|
|
|
self.outputY = 0
|
2020-08-22 23:53:13 +02:00
|
|
|
|
2020-07-19 21:41:14 +02:00
|
|
|
self.isSelected = false
|
2020-08-03 17:38:30 +02:00
|
|
|
self.owner = owner
|
2021-03-13 15:49:21 +01:00
|
|
|
|
|
|
|
self.isDefending = false
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
2019-08-15 19:00:01 +02:00
|
|
|
function Battler:destroy()
|
|
|
|
Battler.super.destroy(self)
|
|
|
|
end
|
|
|
|
|
2021-05-09 15:07:38 +02:00
|
|
|
function Battler:getOutputY()
|
|
|
|
return self.sprHeight or 32
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:avoidedAttack()
|
|
|
|
self:newOutput("", "MISS")
|
2020-08-22 23:53:13 +02:00
|
|
|
end
|
|
|
|
|
2021-03-12 20:12:20 +01:00
|
|
|
function Battler:setDamageNumber(number, isPP)
|
2021-05-09 15:07:38 +02:00
|
|
|
local type = "good"
|
|
|
|
if (isPP == true) then type = "pp" end
|
|
|
|
if (number < 0) then type = "bad" end
|
|
|
|
local string = math.abs(math.floor(number))
|
|
|
|
|
|
|
|
self:newOutput(type, string)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:newOutput(type, string)
|
|
|
|
self.output.type = type or ""
|
|
|
|
self.output.string = string or "error"
|
|
|
|
self.outputY = self:getOutputY() - 8
|
|
|
|
self.showOutput = true
|
|
|
|
|
|
|
|
self.tweens:newTween(0, 0.4, {outputY = self:getOutputY()}, "outQuad")
|
|
|
|
self.tweens:newTimer(0.5, "removeOutput")
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:getOuputColor(type)
|
|
|
|
return outputColor[type] or {1,1,1}
|
2020-08-22 23:53:13 +02:00
|
|
|
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
|
2020-08-04 23:21:45 +02:00
|
|
|
end
|
|
|
|
|
2021-08-07 11:39:34 +02:00
|
|
|
-- Movement
|
|
|
|
-- Some specific movement function
|
|
|
|
|
|
|
|
function Battler:land()
|
|
|
|
self:changeAnimation("idle")
|
|
|
|
end
|
|
|
|
|
2020-08-04 23:21:45 +02:00
|
|
|
-- CHOREGRAPHY FUNCTIONS
|
|
|
|
-- All functions related to the choregraphy system
|
|
|
|
|
|
|
|
function Battler:choregraphyEnded()
|
2021-08-07 11:09:49 +02:00
|
|
|
self:resetMovement()
|
2020-08-04 23:21:45 +02:00
|
|
|
end
|
|
|
|
|
2021-08-07 11:28:27 +02:00
|
|
|
-- DAMAGE FUNCTIONS
|
|
|
|
|
2020-08-05 11:40:29 +02:00
|
|
|
function Battler:getHurt()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function Battler:die()
|
|
|
|
self:destroy()
|
|
|
|
end
|
|
|
|
|
2020-08-04 23:21:45 +02:00
|
|
|
-- DRAW FUNCTIONS
|
2021-05-09 15:07:38 +02:00
|
|
|
function Battler:drawOutput()
|
|
|
|
if (self.showOutput) then
|
2020-08-22 23:53:13 +02:00
|
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
2021-05-09 15:07:38 +02:00
|
|
|
local color = self:getOuputColor(self.output.type)
|
|
|
|
love.graphics.setColor(color[1], color[2], color[3], 1)
|
2020-08-22 23:53:13 +02:00
|
|
|
|
2021-05-09 15:07:38 +02:00
|
|
|
self.assets.fonts["hudnbrs_small"]:print(self.output.string, x, y - self.outputY - self.z, "center")
|
2020-08-22 23:53:13 +02:00
|
|
|
utils.graphics.resetColor()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-03 17:38:30 +02:00
|
|
|
function Battler:draw()
|
|
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
|
|
|
love.graphics.setColor(1, 0, 0, 1)
|
|
|
|
love.graphics.rectangle("fill", x - 8, y - 32, 16, 32)
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
end
|
|
|
|
|
2020-08-04 22:19:11 +02:00
|
|
|
function Battler:initSprite()
|
|
|
|
if (self.assets.sprites[self.owner.name] == nil) then
|
|
|
|
self.assets:addSprite(self.owner.name, self:getSpritePath())
|
|
|
|
end
|
|
|
|
self.assets.sprites[self.owner.name]:setCustomSpeed(16)
|
|
|
|
self:setSprite(self.owner.name, 32, 48, true)
|
|
|
|
self:cloneSprite()
|
|
|
|
self:changeAnimation("idle")
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Battler:validateAction()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return Battler
|