211 lines
4.9 KiB
Lua
211 lines
4.9 KiB
Lua
local Parent = require("scenes.battlesystem.actors.movable")
|
|
local Battler = Parent:extend()
|
|
|
|
local outputColor = {
|
|
good = {0, 1, 0},
|
|
bad = {1, 0, 0},
|
|
pp = {0.3, 0.8, 1}
|
|
}
|
|
|
|
function Battler:new(world, x, y, z, owner)
|
|
Battler.super.new(self, world, x, y, z)
|
|
|
|
self.isBattler = true
|
|
self.isActive = false
|
|
self.debugActiveTimer = 0
|
|
|
|
self.output = {}
|
|
self.output.string = "0"
|
|
self.output.isBad = true
|
|
self.output.type = ""
|
|
self.showOutput = false
|
|
self.outputY = 0
|
|
|
|
self.isSelected = false
|
|
self.owner = owner
|
|
|
|
self.isDefending = false
|
|
|
|
self.tags = {}
|
|
self.choregraphy = nil
|
|
self.frameSignals = {}
|
|
end
|
|
|
|
function Battler:destroy()
|
|
Battler.super.destroy(self)
|
|
end
|
|
|
|
function Battler:getOutputY()
|
|
return self.sprHeight or 32
|
|
end
|
|
|
|
function Battler:avoidedAttack()
|
|
self:newOutput("", "MISS")
|
|
end
|
|
|
|
function Battler:setDamageNumber(number, isPP)
|
|
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}
|
|
end
|
|
|
|
function Battler:setActive()
|
|
core.debug:print("cbs/actor","actor " .. self.id .. " is active")
|
|
self.isActive = true
|
|
self.debugActiveTimer = 0
|
|
end
|
|
|
|
function Battler:update(dt)
|
|
Battler.super.update(self, dt)
|
|
if (self.isActive) then
|
|
self.debugActiveTimer = self.debugActiveTimer + dt
|
|
if self.debugActiveTimer >= 0.5 then
|
|
core.debug:print("cbs/battler", "counter ended, switching active battler")
|
|
self.isActive = false
|
|
self.world:switchActiveBattler()
|
|
end
|
|
end
|
|
|
|
self:updateMovement(dt)
|
|
end
|
|
|
|
function Battler:purgeFrameSignal()
|
|
self.frameSignals = {}
|
|
end
|
|
|
|
function Battler:receiveFrameSignal(signal)
|
|
table.insert(self.frameSignals, signal)
|
|
end
|
|
|
|
function Battler:haveFrameSignal(signal)
|
|
return utils.table.contain(self.frameSignals, signal)
|
|
end
|
|
|
|
-- CHOREGRAPHY FUNCTIONS
|
|
-- All functions related to the choregraphy system
|
|
|
|
function Battler:blockChoregraphy(isBlocking, currentlyBlocking, blockedBy)
|
|
if (isBlocking) then
|
|
self.currentlyBlocking = currentlyBlocking
|
|
self.blockedBy = blockedBy
|
|
end
|
|
end
|
|
|
|
function Battler:addTaggedAction(tag, choregraphy, taggedBy)
|
|
if (not utils.string.isEmpty(tag)) then
|
|
self.tags[tag] = taggedBy
|
|
self.choregraphy = choregraphy
|
|
end
|
|
end
|
|
|
|
function Battler:unlockTag(taggedBy)
|
|
for tag, actionTag in pairs(self.tags) do
|
|
if (self.choregraphy ~= nil) and (actionTag == taggedBy) then
|
|
self.choregraphy:finishTagAction(tag)
|
|
self.tags[tag] = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
function Battler:unblockChoregraphy()
|
|
self.currentlyBlocking:finish()
|
|
self.currentlyBlocking = nil
|
|
end
|
|
|
|
function Battler:timerResponse(signal)
|
|
self:finishAction(signal)
|
|
|
|
if (signal == "resetMovement") then
|
|
self:resetMovementType()
|
|
elseif (signal == "removeOutput") then
|
|
self.showOutput = false
|
|
end
|
|
end
|
|
|
|
function Battler:finishAction(signal)
|
|
if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
|
|
self:unblockChoregraphy()
|
|
end
|
|
self:unlockTag(signal)
|
|
end
|
|
|
|
function Battler:choregraphyEnded()
|
|
self:resetMovement()
|
|
end
|
|
|
|
function Battler:getHurt()
|
|
|
|
end
|
|
|
|
function Battler:die()
|
|
self:destroy()
|
|
end
|
|
|
|
-- DRAW FUNCTIONS
|
|
function Battler:drawOutput()
|
|
if (self.showOutput) then
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
|
local color = self:getOuputColor(self.output.type)
|
|
love.graphics.setColor(color[1], color[2], color[3], 1)
|
|
|
|
self.assets.fonts["hudnbrs_small"]:print(self.output.string, x, y - self.outputY - self.z, "center")
|
|
utils.graphics.resetColor()
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
|
|
function Battler:changeAnimation(animation, restart)
|
|
self:purgeFrameSignal()
|
|
Battler.super.changeAnimation(self, animation, restart)
|
|
end
|
|
|
|
function Battler:animationEnded(animation)
|
|
if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then
|
|
self:unblockChoregraphy()
|
|
end
|
|
self:unlockTag("animation")
|
|
self:getNewAnimation(animation)
|
|
end
|
|
|
|
function Battler:getNewAnimation(animation)
|
|
|
|
end
|
|
|
|
function Battler:validateAction()
|
|
|
|
end
|
|
|
|
return Battler
|