From 0377077ca94ec74b2a001048cf9203da8d2f41d0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 17 Jul 2021 21:19:33 +0200 Subject: [PATCH] feat:detect tagged actions and handle tags --- .../datas/gamedata/skills/attack.lua | 2 +- .../fighters/systems/choregraphy/init.lua | 37 ++++++++++++++++++- .../systems/choregraphy/step/parent.lua | 8 ++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/datas/gamedata/skills/attack.lua b/sonic-radiance.love/datas/gamedata/skills/attack.lua index 0ef4bd0..cbcafb0 100644 --- a/sonic-radiance.love/datas/gamedata/skills/attack.lua +++ b/sonic-radiance.love/datas/gamedata/skills/attack.lua @@ -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'}, diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua index 707f49f..36d3b1d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/init.lua @@ -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 diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua index 1a9282f..dd4131d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua @@ -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)