local this = L_BevTree:registClass("guide.guideTreeSequencer", L_BevTree.composite)
local tag = this.getName()

function this:param()
  self.isAutoSaveOnFinish = 1
end

function this:parse()
  self._hasCompleted = false
  self.isAutoSaveOnFinish = self:getParam("isAutoSaveOnFinish", true) or 1
end

function this:onEnter()
  self._hasCompleted = L_GuideStore:isGuideStepComplete(self.tree.param.guideId, 0)
end

function this:execute(childResult)
  if self._hasCompleted == true then
    return L_BevTree.taskResult.Success
  end
  if childResult == L_BevTree.taskResult.Failure or childResult == L_BevTree.taskResult.Running then
    return childResult
  end
  return L_BevTree.taskResult.Success
end

function this:onFinish()
  if self._hasCompleted == false and not L_GuideManager:isOnDebugMode() and self.isAutoSaveOnFinish == 1 and self.lastResult == L_BevTree.taskResult.Success then
    L_GuideManager:saveStepId(self.tree.param.guideId, 0)
  end
  if L_GuideManager:isOnDebugMode() or self.isAutoSaveOnFinish ~= 1 then
    L_GuideManager:endGuide(self.tree.param.guideId)
  end
  if self.lastResult == L_BevTree.taskResult.Failure then
    printf("guide\230\143\144\231\164\186", "\229\188\149\229\175\188\230\160\145\228\187\165\229\164\177\232\180\165\231\187\147\230\157\159\239\188\154 " .. self.id)
    L_GuideManager:endGuide(self.tree.param.guideId)
    C_InputManager.DisableHighLevelControl()
  end
  L_GuideManager:setGuideDebug(false)
end

function this:moveNext()
  if self.lastResult == L_BevTree.taskResult.Failure or self.lastResult == L_BevTree.taskResult.Running then
    return false
  end
  self.childIndex = self.childIndex + 1
  return self.childIndex <= #self.children
end

return this
