150 lines
4.1 KiB
Lua
150 lines
4.1 KiB
Lua
local ChoregraphySystem = Object:extend()
|
|
|
|
local stepObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step"
|
|
local qteObjectList = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.qte"
|
|
|
|
local ACTION_STARTED = 1
|
|
local ACTION_FINISHED = 2
|
|
|
|
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
|
|
|
|
self.haveSentDamage = false
|
|
|
|
self.currentStepId = 0
|
|
self.currentStep = nil
|
|
self.stepList = choregraphy
|
|
|
|
self.qte = {}
|
|
self.qte.current = nil
|
|
self.qte.wasSuccess = false
|
|
self.qte.list = {}
|
|
|
|
self.finishedTagActions = {}
|
|
end
|
|
|
|
function ChoregraphySystem:update(dt)
|
|
if (self.qte.current ~= nil) then
|
|
self.qte.current:updateQte(dt)
|
|
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
|
|
local stepData, tagName = self:parseStep(self.stepList[self.currentStepId])
|
|
if (stepObjectList[stepData.name] ~= nil and self:checkCondition(stepData.condition)) then
|
|
self.currentStep = stepObjectList[stepData.name](self, stepData.arguments)
|
|
if (not utils.string.isEmpty(tagName)) then
|
|
self.currentStep:addTag(tagName)
|
|
self:startTagAction(tagName)
|
|
end
|
|
end
|
|
else
|
|
self:endChoregraphy()
|
|
end
|
|
end
|
|
|
|
function ChoregraphySystem:parseStep(step)
|
|
local tagName = ""
|
|
if (step[1] == "taggedAction") then
|
|
tagName = step[2]
|
|
step = step[3]
|
|
end
|
|
local stepData = core.datas:parse("choregraphystep", step)
|
|
core.debug:print("cbs/choregraphy", "Starting step " .. stepData.name)
|
|
return stepData, tagName
|
|
end
|
|
|
|
function ChoregraphySystem:checkCondition(condition)
|
|
local conditionArgs = utils.string.split(condition, ":")
|
|
local success = true
|
|
|
|
if (conditionArgs[1] == "sentDamage" and (not self.haveSentDamage)) then
|
|
success = false
|
|
elseif (conditionArgs[1] == "qteSuccess" and (not self.qte.list[tonumber(conditionArgs[2])])) then
|
|
success = false
|
|
elseif (conditionArgs[1] == "qteFailure" and (self.qte.list[tonumber(conditionArgs[2])])) then
|
|
success = false
|
|
end
|
|
|
|
return success
|
|
end
|
|
|
|
function ChoregraphySystem:addQTE(action, origin, qteBaseData, blockProcess)
|
|
local qteData = core.datas:parse("qtesteps", qteBaseData)
|
|
if (qteObjectList[qteData.name] ~= nil) then
|
|
core.debug:print("cbs/choregraphy", "Starting qte " .. qteData.name)
|
|
self.qte.current = qteObjectList[qteData.name](self, qteData.arguments, 0, 0)
|
|
self.qte.current:blockAction(action, blockProcess)
|
|
self.qte.current:setOrigin(origin)
|
|
end
|
|
end
|
|
|
|
function ChoregraphySystem:endQte(success)
|
|
self.qte.current = nil
|
|
self.qte.wasSuccess = success
|
|
|
|
table.insert(self.qte.list, success)
|
|
end
|
|
|
|
function ChoregraphySystem:testTagAction(tag, statut)
|
|
local tagStatut = self.finishedTagActions[tag] or 0
|
|
return (statut <= tagStatut)
|
|
end
|
|
|
|
function ChoregraphySystem:startTagAction(tag)
|
|
self.finishedTagActions[tag] = ACTION_FINISHED
|
|
end
|
|
|
|
function ChoregraphySystem:finishTagAction(tag)
|
|
core.debug:print("choregraphy/step", "Tag action " .. tag .. " finished.")
|
|
self.finishedTagActions[tag] = ACTION_STARTED
|
|
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
|
|
self.haveSentDamage = false
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChoregraphySystem:useItemEffect()
|
|
self.action:useItemEffect()
|
|
end
|
|
|
|
function ChoregraphySystem:endStep()
|
|
self.currentStep = nil
|
|
end
|
|
|
|
function ChoregraphySystem:endChoregraphy()
|
|
self.actor:choregraphyEnded()
|
|
self.action:choregraphyEnded()
|
|
self.fighter.turnSystem:applyDeath()
|
|
end
|
|
|
|
function ChoregraphySystem:haveNextStep()
|
|
return ((self.currentStepId + 1) <= #self.stepList)
|
|
end
|
|
|
|
function ChoregraphySystem:draw()
|
|
if (self.qte.current ~= nil) then
|
|
self.qte.current:draw()
|
|
end
|
|
end
|
|
|
|
return ChoregraphySystem
|