mission_ember.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. -- Full mission controller: arrival, Powerhouse, Processing, Sunside and Light's End.
  2. local missions = require("missions")
  3. local mission = require(assert(missions.MISSION_EMBER, "mission_ember SDK module is absent"))
  4. local landing = require("mission_ember.landing")(mission)
  5. local opening = require("mission_ember.opening")(mission, landing)
  6. -- Lazy construction keeps the opening independent of later region initialization.
  7. local routes
  8. local function later() if not routes then routes = require("mission_ember.routes")(mission) end; return routes end
  9. local wipe = require("mission_ember.wipe")(mission, landing, function(c, s) later().reset(c, s) end)
  10. local function dispatch(method, c, s, e)
  11. if not wipe.active(s) and opening.playable(s) and s:variable("ember.later.owns_hud") then
  12. return later().dispatch(method, c, s, e)
  13. end
  14. end
  15. local function terminated(c, s, e)
  16. opening.terminated(c, s, e)
  17. if routes then routes.terminated(c, s, e) end
  18. end
  19. return {
  20. initial_state = opening.initial_state,
  21. on_event_cinematic_terminated = terminated,
  22. on_event_cinematic_started = function(c, s, e)
  23. if routes then routes.started(c, s, e) end
  24. end,
  25. on_event_cinematic_skip_requested = function(c, s, e)
  26. opening.terminated(c, s, e)
  27. if routes then routes.skip(c, s, e) end
  28. end,
  29. on_event_client_state_changed = function(context, state, event)
  30. wipe.client_state(context, state, event)
  31. opening.client_state(context, state, event)
  32. local region = event.held_region_index or event.current_region_index
  33. -- A settle-only delta omits region fields; it does not mean that the player left.
  34. if region ~= nil then context:set_variable("ember.region", region) end
  35. region = state:variable("ember.region")
  36. if region == landing.region and opening.playable(state) then
  37. landing.enter(context, state)
  38. landing.client_state(context, state, event)
  39. end
  40. if opening.playable(state) and not wipe.active(state) and (region == 56 or region == 40 or region == 0 or routes) then
  41. later().client(context, state, event)
  42. end
  43. if opening.playable(state) then
  44. landing.update_darkness(context, state)
  45. landing.update_guidance(context, state)
  46. end
  47. end,
  48. on_event_player_trigger = function(context, state, event)
  49. dispatch("trigger", context, state, event)
  50. if wipe.active(state) then return end
  51. if state:variable("ember.region") == landing.region and opening.playable(state) then
  52. landing.on_player_trigger(context, state, event)
  53. landing.update_guidance(context, state)
  54. end
  55. end,
  56. on_event_object_interacted = function(context, state, event)
  57. dispatch("interaction", context, state, event)
  58. if wipe.active(state) then return end
  59. if state:variable("ember.region") == landing.region and opening.playable(state) then
  60. landing.on_object_interacted(context, state, event)
  61. landing.update_guidance(context, state)
  62. end
  63. end,
  64. on_event_ghost_link_state = function(context, state, event)
  65. if wipe.active(state) then return end
  66. if state:variable("ember.region") == landing.region and opening.playable(state) then
  67. landing.on_ghost_link_state(context, state, event)
  68. landing.update_guidance(context, state)
  69. end
  70. end,
  71. on_event_timer_elapsed = function(context, state, event)
  72. if wipe.timer(context, state, event) or wipe.active(state) then return end
  73. if dispatch("timer", context, state, event) then return end
  74. if opening.playable(state) then landing.on_timer(context, state, event) end
  75. end,
  76. on_event_actor_path_state = function(context, state, event)
  77. if wipe.active(state) then return end
  78. -- Existing flights finish and retire even when the player has left this region.
  79. if opening.playable(state) then
  80. landing.on_actor_path_state(context, state, event)
  81. end
  82. end,
  83. on_event_squad_state = function(context, state, event)
  84. if wipe.active(state) then return end
  85. if opening.playable(state) then
  86. if routes then routes.squad(context, state, event) end
  87. landing.on_squad_state(context, state, event)
  88. landing.update_guidance(context, state)
  89. end
  90. end,
  91. on_event_object_state = function(c, s, e) dispatch("object", c, s, e) end,
  92. on_event_damage_state = function(c, s, e) dispatch("damage", c, s, e) end,
  93. on_event_fireteam_state = wipe.fireteam,
  94. on_event_effect_result = wipe.effect,
  95. }