sonic-radiance/sonic-radiance.love/scenes/battlesystem/actors/systems/choregraphy.lua

96 lines
2.3 KiB
Lua
Raw Normal View History

local ChoregraphySystem = Object:extend()
local actionList = require "scenes.battlesystem.actors.systems.actions"
function ChoregraphySystem:new(actor)
self.actor = actor
self:init({}, nil, self.actor.x, self.actor.y, false)
end
function ChoregraphySystem:init(choregraphy, effectArea, dx, dy, isActive)
self.current = 0
self.action = nil
self.isFinished = false
self.data = choregraphy
self.effectArea = effectArea
self.startx = self.actor.x
self.starty = self.actor.y
self.direction = self.actor.direction
self.dx = dx or self.actor.x
self.dy = dy or self.actor.y
self.haveSentDamage = false
self.isActive = isActive
self.actionHaveEnded = false
end
function ChoregraphySystem:start(skill, dx, dy)
local skill = skill
self:init(skill.choregraphy, skill.effectArea, dx, dy, true)
end
function ChoregraphySystem:finish()
self.isActive = false
self.actor:switchActiveBattler()
end
function ChoregraphySystem:update(dt)
if (self.actionHaveEnded) then
self.action = nil
self.actionHaveEnded = false
end
if (self.isActive) then
if (self.action == nil) then
self:switchAction()
else
self.action:update(dt)
end
end
end
function ChoregraphySystem:switchAction()
self.current = self.current + 1
local nextAction = self.data[self.current]
if (nextAction == nil) then
print("finished")
self:finish()
else
local args = game.skills:getActionArguments(nextAction)
local condition = args.condition
if (condition == "sentDamage") and (not self.haveSentDamage) then
core.debug:print("cbs/hero", "you didn't do damage, skipping " .. args.name)
self:switchAction()
else
self:doAction(nextAction)
end
end
end
function ChoregraphySystem:doAction(choregraphyAction)
local args = game.skills:getActionArguments(choregraphyAction)
local type = args.type or "unknown"
local effectArea = self.effectArea
local action = actionList[type]
if (action == nil) then
core.debug:warning("cbs/hero", "unknown action type " .. type .. ' (' .. args.name .. ')')
else
self.action = action(self, args, effectArea)
end
end
function ChoregraphySystem:endAction()
self.action = nil
self.actionHaveEnded = true
end
return ChoregraphySystem