sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua

109 lines
3 KiB
Lua
Raw Normal View History

local ChoregraphySystem = Object:extend()
local stepObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step"
2020-07-31 20:06:35 +02:00
local qteObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte"
function ChoregraphySystem:new(action, choregraphy)
self.action = action
self.fighter = action.fighter
self.actor = self.fighter.actor
self.assets = self.fighter.actor.assets
self.world = self.actor.world
self.target = action.target
2021-05-09 15:08:36 +02:00
self.haveSentDamage = false
self.currentStepId = 0
self.currentStep = nil
self.stepList = choregraphy
2020-07-31 20:06:35 +02:00
self.qte = {}
self.qte.current = nil
self.qte.wasSuccess = false
end
function ChoregraphySystem:update(dt)
2020-07-31 20:06:35 +02:00
if (self.qte.current ~= nil) then
2021-04-25 12:19:46 +02:00
self.qte.current:updateQte(dt)
2020-07-31 20:06:35 +02:00
end
if (self.currentStep ~= nil) then
self.currentStep:updateStep(dt)
else
self:switchStep()
end
end
function ChoregraphySystem:switchStep()
if self:haveNextStep() then
self.currentStepId = self.currentStepId + 1
2021-05-15 22:48:25 +02:00
local stepData = core.datas:parse("choregraphystep", self.stepList[self.currentStepId])
core.debug:print("cbs/choregraphy", "Starting step " .. stepData.name)
2021-05-09 15:08:36 +02:00
if (stepObjectList[stepData.name] ~= nil and self:checkCondition(stepData.condition)) then
self.currentStep = stepObjectList[stepData.name](self, stepData.arguments)
end
else
self:endChoregraphy()
end
end
2021-05-09 15:08:36 +02:00
function ChoregraphySystem:checkCondition(condition)
local conditionArgs = utils.string.split(condition, ":")
local success = true
if (conditionArgs[1] == "sentDamage" and (not self.haveSentDamage)) then
success = false
end
return success
end
2020-07-31 20:06:35 +02:00
function ChoregraphySystem:addQTE(action, origin, qteBaseData, blockProcess)
2021-05-15 22:48:25 +02:00
local qteData = core.datas:parse("qtesteps", qteBaseData)
2020-07-31 20:06:35 +02:00
if (qteObjectList[qteData.name] ~= nil) then
2021-04-25 12:19:46 +02:00
core.debug:print("cbs/choregraphy", "Starting qte " .. qteData.name)
self.qte.current = qteObjectList[qteData.name](self, qteData.arguments, 0, 0)
2020-07-31 20:06:35 +02:00
self.qte.current:blockAction(action, blockProcess)
self.qte.current:setOrigin(origin)
end
end
2021-04-25 12:19:46 +02:00
function ChoregraphySystem:endQte(success)
self.qte.current = nil
self.qte.wasSuccess = success
end
function ChoregraphySystem:sendDamage(power, type, element, isSpecial)
if (self.target ~= nil) then
if (self.fighter.isAlive) then
self.haveSentDamage = self.fighter:sendDamage(self.target, power, type, element, isSpecial)
else
2021-05-09 15:08:36 +02:00
self.haveSentDamage = false
end
end
end
function ChoregraphySystem:useItemEffect()
self.action:useItemEffect()
end
function ChoregraphySystem:endStep()
self.currentStep = nil
end
function ChoregraphySystem:endChoregraphy()
2020-07-25 10:25:00 +02:00
self.actor:choregraphyEnded()
self.action:choregraphyEnded()
self.fighter.turnSystem:applyDeath()
end
function ChoregraphySystem:haveNextStep()
return ((self.currentStepId + 1) <= #self.stepList)
end
2021-04-25 12:19:46 +02:00
function ChoregraphySystem:draw()
if (self.qte.current ~= nil) then
self.qte.current:draw()
end
end
return ChoregraphySystem