2020-07-24 19:16:33 +02:00
|
|
|
local ChoregraphySystem = Object:extend()
|
|
|
|
|
2020-07-24 21:54:12 +02:00
|
|
|
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"
|
2020-07-24 19:16:33 +02:00
|
|
|
|
2021-07-17 21:31:42 +02:00
|
|
|
local Predicate = require "birb.classes.predicate"
|
|
|
|
local Conditions = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.conditions"
|
|
|
|
|
2021-07-17 21:19:33 +02:00
|
|
|
local ACTION_STARTED = 1
|
|
|
|
local ACTION_FINISHED = 2
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
function ChoregraphySystem:new(action, choregraphy)
|
|
|
|
self.action = action
|
|
|
|
self.fighter = action.fighter
|
|
|
|
self.actor = self.fighter.actor
|
2020-07-24 21:54:12 +02:00
|
|
|
self.assets = self.fighter.actor.assets
|
|
|
|
self.world = self.actor.world
|
2020-07-25 08:44:59 +02:00
|
|
|
self.target = action.target
|
2020-07-24 19:16:33 +02:00
|
|
|
|
2021-05-09 15:08:36 +02:00
|
|
|
self.haveSentDamage = false
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
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
|
2021-07-03 19:28:58 +02:00
|
|
|
self.qte.list = {}
|
2021-07-17 21:19:33 +02:00
|
|
|
|
|
|
|
self.finishedTagActions = {}
|
2021-07-18 08:59:01 +02:00
|
|
|
self.counters = {}
|
2020-07-24 19:16:33 +02:00
|
|
|
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
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
if (self.currentStep ~= nil) then
|
2020-07-24 21:54:12 +02:00
|
|
|
self.currentStep:updateStep(dt)
|
2020-07-24 19:16:33 +02:00
|
|
|
else
|
|
|
|
self:switchStep()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-17 22:59:12 +02:00
|
|
|
function ChoregraphySystem:findTaggedAction(tag)
|
|
|
|
for stepId, step in ipairs(self.stepList) do
|
|
|
|
if (step[1] == "taggedAction") and (step[2] == tag) then
|
|
|
|
return stepId
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:skipToStepByTag(tag)
|
|
|
|
self:skipToStep(self:findTaggedAction(tag))
|
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:skipToStep(id)
|
|
|
|
if (self.stepList[id] ~= nil) then
|
|
|
|
self.currentStepId = id - 1
|
|
|
|
self:switchStep()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
function ChoregraphySystem:switchStep()
|
|
|
|
if self:haveNextStep() then
|
|
|
|
self.currentStepId = self.currentStepId + 1
|
2021-07-17 21:19:33 +02:00
|
|
|
local stepData, tagName = self:parseStep(self.stepList[self.currentStepId])
|
2021-05-09 15:08:36 +02:00
|
|
|
if (stepObjectList[stepData.name] ~= nil and self:checkCondition(stepData.condition)) then
|
2020-07-24 21:54:12 +02:00
|
|
|
self.currentStep = stepObjectList[stepData.name](self, stepData.arguments)
|
2021-07-17 21:19:33 +02:00
|
|
|
if (not utils.string.isEmpty(tagName)) then
|
|
|
|
self.currentStep:addTag(tagName)
|
|
|
|
self:startTagAction(tagName)
|
|
|
|
end
|
2020-07-24 21:54:12 +02:00
|
|
|
end
|
2020-07-24 19:16:33 +02:00
|
|
|
else
|
|
|
|
self:endChoregraphy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-17 21:19:33 +02:00
|
|
|
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
|
|
|
|
|
2021-05-09 15:08:36 +02:00
|
|
|
function ChoregraphySystem:checkCondition(condition)
|
2021-07-17 21:31:42 +02:00
|
|
|
local predicate = Predicate.createPredicate(condition, Conditions, self)
|
|
|
|
return predicate:solve()
|
2021-05-09 15:08:36 +02:00
|
|
|
end
|
|
|
|
|
2021-07-17 21:23:29 +02:00
|
|
|
function ChoregraphySystem:addQTE(action, origin, qteBaseData, blockProcess, tag)
|
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)
|
2021-07-17 21:23:29 +02:00
|
|
|
self.qte.current:setTag(tag)
|
2020-07-31 20:06:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-17 21:31:42 +02:00
|
|
|
function ChoregraphySystem:isQteSuccess(qteID)
|
2021-07-18 14:09:09 +02:00
|
|
|
qteID = qteID or #self.qte.list
|
2021-07-17 21:31:42 +02:00
|
|
|
return self.qte.list[qteID]
|
|
|
|
end
|
|
|
|
|
2021-04-25 12:19:46 +02:00
|
|
|
function ChoregraphySystem:endQte(success)
|
|
|
|
self.qte.current = nil
|
|
|
|
self.qte.wasSuccess = success
|
2021-07-03 19:28:58 +02:00
|
|
|
|
|
|
|
table.insert(self.qte.list, success)
|
2021-04-25 12:19:46 +02:00
|
|
|
end
|
|
|
|
|
2021-07-17 21:19:33 +02:00
|
|
|
function ChoregraphySystem:testTagAction(tag, statut)
|
|
|
|
local tagStatut = self.finishedTagActions[tag] or 0
|
|
|
|
return (statut <= tagStatut)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:startTagAction(tag)
|
2021-07-17 21:53:10 +02:00
|
|
|
self.finishedTagActions[tag] = ACTION_STARTED
|
2021-07-17 21:19:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:finishTagAction(tag)
|
|
|
|
core.debug:print("choregraphy/step", "Tag action " .. tag .. " finished.")
|
2021-07-17 21:53:10 +02:00
|
|
|
self.finishedTagActions[tag] = ACTION_FINISHED
|
2021-07-17 21:19:33 +02:00
|
|
|
end
|
|
|
|
|
2021-07-18 08:59:01 +02:00
|
|
|
function ChoregraphySystem:getCounter(counterName)
|
|
|
|
return (self.counters[counterName] or 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:setCounter(counterName, number, relative)
|
|
|
|
if (relative == true) then
|
|
|
|
number = number + self:getCounter(counterName)
|
|
|
|
end
|
|
|
|
self.counters[counterName] = number
|
|
|
|
end
|
|
|
|
|
2021-05-15 15:01:02 +02:00
|
|
|
function ChoregraphySystem:sendDamage(power, type, element, isSpecial)
|
2020-07-25 08:44:59 +02:00
|
|
|
if (self.target ~= nil) then
|
|
|
|
if (self.fighter.isAlive) then
|
2021-05-15 15:01:02 +02:00
|
|
|
self.haveSentDamage = self.fighter:sendDamage(self.target, power, type, element, isSpecial)
|
2020-07-25 08:44:59 +02:00
|
|
|
else
|
2021-05-09 15:08:36 +02:00
|
|
|
self.haveSentDamage = false
|
2020-07-25 08:44:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-12 21:14:17 +01:00
|
|
|
function ChoregraphySystem:useItemEffect()
|
|
|
|
self.action:useItemEffect()
|
|
|
|
end
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
function ChoregraphySystem:endStep()
|
|
|
|
self.currentStep = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function ChoregraphySystem:endChoregraphy()
|
2020-07-25 10:25:00 +02:00
|
|
|
self.actor:choregraphyEnded()
|
2020-07-24 19:16:33 +02:00
|
|
|
self.action:choregraphyEnded()
|
2020-07-25 08:44:59 +02:00
|
|
|
self.fighter.turnSystem:applyDeath()
|
2020-07-24 19:16:33 +02:00
|
|
|
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
|
|
|
|
|
2020-07-24 19:16:33 +02:00
|
|
|
return ChoregraphySystem
|