feat:detect tagged actions and handle tags

This commit is contained in:
Kazhnuz 2021-07-17 21:19:33 +02:00
parent f7221971c3
commit 0377077ca9
3 changed files with 44 additions and 3 deletions

View file

@ -15,7 +15,7 @@ return {
choregraphy = { -- the main attack choregraphy
{"setAnimation", "none", "walk", false},
{"goTo", "none", "target", 0, 0, 0.6, false},
{"taggedAction", "playerMove", {"goTo", "none", "target", 0, 0, 0.6, false}},
{"wait", "none", 0.3},
{"setAnimation", "none", "spin", false},
{'playSFX', "none", 'spinrelease'},

View file

@ -3,6 +3,9 @@ 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
@ -21,6 +24,8 @@ function ChoregraphySystem:new(action, choregraphy)
self.qte.current = nil
self.qte.wasSuccess = false
self.qte.list = {}
self.finishedTagActions = {}
end
function ChoregraphySystem:update(dt)
@ -38,16 +43,30 @@ end
function ChoregraphySystem:switchStep()
if self:haveNextStep() then
self.currentStepId = self.currentStepId + 1
local stepData = core.datas:parse("choregraphystep", self.stepList[self.currentStepId])
core.debug:print("cbs/choregraphy", "Starting step " .. stepData.name)
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
@ -80,6 +99,20 @@ function ChoregraphySystem:endQte(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

View file

@ -5,6 +5,14 @@ function StepParent:new(choregraphySystem, arguments, canBeAsync)
self.arguments = arguments
self.isStarted = false
self.canBeAsync = (canBeAsync == true)
self.tag = ""
end
function StepParent:addTag(tag)
if (self.canBeAsync) then
core.debug:print("choregraphy/step", "Tag " .. tag .. " added to step.")
self.tag = tag
end
end
function StepParent:updateStep(dt)