ending.lua 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- Authored post-escape cinematic states; exact native completion/skip incidents advance once.
  2. --
  3. -- An authored region is `sliceSetIndex + stateOrdinal`, so apex gameplay (region 0) and both
  4. -- ending bookends (regions 1 and 2) are sibling states of one slice set. Selecting a bookend
  5. -- instantiates no new world, so no slice-set teleport is armed for it -- and that also means the
  6. -- client never sends another region report. Waiting for one leaves the movie unstarted forever,
  7. -- which is exactly what a run with the teleport removed showed: the state was selected and no
  8. -- cinematic was ever enqueued.
  9. --
  10. -- So the activation is queued with the selection instead of on a later callback. Intents are
  11. -- dispatched in order and a state selection completes only once its own roster revision has
  12. -- published, so the cinematic Auth always follows the seed that carries its slot. Slot handles
  13. -- resolve against the static SDK definition table, not the selected state, so naming the
  14. -- bookend before its state is live is safe.
  15. return function(m)
  16. local movies = {
  17. {state = m.states.STATE_80B3C09E_0000_0001_80B3C091, slot = m.Slot.PF_CINEMATIC_BOOKEND_STM_CINEMATIC},
  18. {state = m.states.STATE_80B3C09E_0000_0002_80B3C093, slot = m.Slot.PF_CINEMATIC_BOOKEND_CNN_CINEMATIC},
  19. }
  20. local E = {}
  21. local music = require("mission_ember.music")(m)
  22. local function play(c, index)
  23. local row = assert(movies[index])
  24. c:set_variable("ember.ending", index)
  25. c:clear_variable("ember.ending.playing")
  26. c:clear_variable("ember.ending.runtime")
  27. c:clear_variable("ember.ending.stopping")
  28. c:select_state(assert(row.state))
  29. c:slot(assert(row.slot)):set_cinematic_active{active = true}
  30. end
  31. function E.start(c, s)
  32. if s:variable("ember.ending") then return end
  33. music.update(c, s)
  34. play(c, 1)
  35. end
  36. local function matched(c, s, e)
  37. local index = s:variable("ember.ending")
  38. local row = index and movies[index]
  39. if not row then return end
  40. local slot = c:slot(row.slot)
  41. if e.registry_key ~= slot.registry_key or e.slot_type ~= slot.slot_type or e.slot_index ~= slot.slot_index then return end
  42. return index, slot
  43. end
  44. function E.started(c, s, e)
  45. local index = matched(c, s, e)
  46. if not index or s:variable("ember.ending.playing") or type(e.runtime_object_id) ~= "string" then return end
  47. c:set_variable("ember.ending.playing", index)
  48. c:set_variable("ember.ending.runtime", e.runtime_object_id)
  49. end
  50. function E.skip(c, s, e)
  51. local index, slot = matched(c, s, e)
  52. if not index or s:variable("ember.ending.playing") ~= index
  53. or e.runtime_object_id ~= s:variable("ember.ending.runtime")
  54. or s:variable("ember.ending.stopping") then return end
  55. c:set_variable("ember.ending.stopping", true)
  56. slot:set_cinematic_active{active = false}
  57. end
  58. function E.terminated(c, s, e)
  59. local index, slot = matched(c, s, e)
  60. if not index or s:variable("ember.ending.playing") ~= index
  61. or e.runtime_object_id ~= s:variable("ember.ending.runtime") then return end
  62. slot:set_cinematic_active{active = false}
  63. if movies[index + 1] then play(c, index + 1)
  64. else
  65. c:set_variable("ember.ending", index + 1)
  66. c:set_variable("ember.complete", true)
  67. -- Native lifetime 6 enters the completion/reward branch (BEA9D0/B37100).
  68. c.lifetime:set{state = c.sdk.lifetime_states:at(6)}
  69. c:set_phase(100)
  70. end
  71. end
  72. return E
  73. end