Skip to content

Lua 活动快速开始

活动脚本运行在 App 的受限 Lua 环境中。一个普通活动通常由三个入口组成:

入口作用
query()查询状态并刷新页面
run(state)执行每日任务、购买或战斗
claim(reward_id, index, catch_time)用户确认后领取奖励或提交进化

最小脚本

lua
local cgi = "activity_cgi"

local function render()
  local state = roco.cgi(cgi, 0)
  local schedule = state:get_int("schedule") or 0

  roco.ui_battle(false)
  roco.ui_progress(schedule, 10)
  roco.ui_daily(schedule >= 10 and "已完成" or "未完成")
  roco.ui_complete(schedule >= 10)

  return state
end

function query()
  return render()
end

function run(state)
  state = state or render()

  if (state:get_int("schedule") or 0) >= 10 then
    roco.toast("今日已完成", "success")
    return
  end

  roco.log("活动", "提交今日任务")
  roco.cgi(cgi, 2)
  render()
end

数据流

text
query()
  -> roco.cgi()
  -> XML 状态对象
  -> roco.ui_* 更新页面
  -> 返回 state 给 run(state)

query() 推荐返回最终渲染使用的状态对象。用户随后点击一键完成时,App 会把它传给 run(state),避免无意义的重复查询。

下一步

脚本边界

普通快速 CGI 活动留在页面作用域内。只有退出页面后仍需继续的长流程才调用 roco.background(true)

仅用于个人学习、协议分析与自动化实验。