mission_ember.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_skip_requested = terminated,
  23. on_event_client_state_changed = function(context, state, event)
  24. wipe.client_state(context, state, event)
  25. opening.client_state(context, state, event)
  26. local region = event.held_region_index or event.current_region_index
  27. -- A settle-only delta omits region fields; it does not mean that the player left.
  28. if region ~= nil then context:set_variable("ember.region", region) end
  29. region = state:variable("ember.region")
  30. if region == landing.region and opening.playable(state) then
  31. landing.enter(context, state)
  32. landing.client_state(context, state, event)
  33. end
  34. if opening.playable(state) and not wipe.active(state) and (region == 56 or region == 40 or region == 0 or routes) then
  35. later().client(context, state, event)
  36. end
  37. if opening.playable(state) then
  38. landing.update_darkness(context, state)
  39. landing.update_guidance(context, state)
  40. end
  41. end,
  42. on_event_player_trigger = function(context, state, event)
  43. dispatch("trigger", context, state, event)
  44. if wipe.active(state) then return end
  45. if state:variable("ember.region") == landing.region and opening.playable(state) then
  46. landing.on_player_trigger(context, state, event)
  47. landing.update_guidance(context, state)
  48. end
  49. end,
  50. on_event_object_interacted = function(context, state, event)
  51. dispatch("interaction", context, state, event)
  52. if wipe.active(state) then return end
  53. if state:variable("ember.region") == landing.region and opening.playable(state) then
  54. landing.on_object_interacted(context, state, event)
  55. landing.update_guidance(context, state)
  56. end
  57. end,
  58. on_event_ghost_link_state = function(context, state, event)
  59. if wipe.active(state) then return end
  60. if state:variable("ember.region") == landing.region and opening.playable(state) then
  61. landing.on_ghost_link_state(context, state, event)
  62. landing.update_guidance(context, state)
  63. end
  64. end,
  65. on_event_timer_elapsed = function(context, state, event)
  66. if wipe.timer(context, state, event) or wipe.active(state) then return end
  67. if dispatch("timer", context, state, event) then return end
  68. if opening.playable(state) then landing.on_timer(context, state, event) end
  69. end,
  70. on_event_actor_path_state = function(context, state, event)
  71. if wipe.active(state) then return end
  72. -- Existing flights finish and retire even when the player has left this region.
  73. if opening.playable(state) then
  74. landing.on_actor_path_state(context, state, event)
  75. end
  76. end,
  77. on_event_squad_state = function(context, state, event)
  78. if wipe.active(state) then return end
  79. if opening.playable(state) then
  80. if routes then routes.squad(context, state, event) end
  81. landing.on_squad_state(context, state, event)
  82. landing.update_guidance(context, state)
  83. end
  84. end,
  85. on_event_object_state = function(c, s, e) dispatch("object", c, s, e) end,
  86. on_event_damage_state = function(c, s, e) dispatch("damage", c, s, e) end,
  87. on_event_fireteam_state = wipe.fireteam,
  88. on_event_effect_result = wipe.effect,
  89. }