wipe.lua 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. -- Native type35 countdown followed by the membership hard-wipe handshake.
  2. return function(mission, landing, reset_later)
  3. local function checkpoint(state)
  4. return state:variable("ember.checkpoint.region") or landing.region,
  5. state:variable("ember.checkpoint.hash") or 0x9C58857A
  6. end
  7. local function timer(state)
  8. return "ember.wipe.countdown." .. (state:variable("ember.wipe.cycle") or 0)
  9. end
  10. local function stage(state) return state:variable("ember.wipe.stage") or 0 end
  11. local function countdown(context, seconds)
  12. context:slot(mission.Slot.HARD_WIPE_GLOBALS):set_darkness_zone{enabled = true, wipe_seconds = seconds}
  13. end
  14. local function cancel(context, state)
  15. context:cancel_timer(timer(state))
  16. context:clear_variable("ember.wipe.stage")
  17. context:clear_variable("ember.wipe.seconds")
  18. context:clear_variable("ember.wipe.request")
  19. context:slot(mission.Slot.HARD_WIPE_GLOBALS):set_darkness_zone{
  20. enabled = state:variable("ember.darkness.enabled") == true}
  21. end
  22. return {
  23. active = function(state) return stage(state) >= 2 end,
  24. fireteam = function(context, state, event)
  25. local all_dead = event.dead_count > 0 and event.alive_count == 0 and event.unknown_count == 0
  26. context:set_variable("ember.wipe.all_dead", all_dead)
  27. if stage(state) >= 2 then return end -- Native cleanup now owns missing players.
  28. if not all_dead then
  29. if stage(state) == 1 then cancel(context, state) end
  30. return
  31. end
  32. if stage(state) == 0 and state:variable("ember.darkness.enabled") == true then
  33. context:set_variable("ember.wipe.cycle", (state:variable("ember.wipe.cycle") or 0) + 1)
  34. context:set_variable("ember.wipe.stage", 1)
  35. context:set_variable("ember.wipe.seconds", 3)
  36. countdown(context, 3)
  37. context:start_timer(timer(state), 1000)
  38. end
  39. end,
  40. timer = function(context, state, event)
  41. if event.timer_name ~= timer(state) then return false end
  42. if stage(state) ~= 1 then return true end
  43. if not state:variable("ember.wipe.all_dead") or not state:variable("ember.darkness.enabled") then
  44. cancel(context, state); return true
  45. end
  46. local remaining = state:variable("ember.wipe.seconds") - 1
  47. context:set_variable("ember.wipe.seconds", remaining)
  48. countdown(context, remaining)
  49. if remaining > 0 then context:start_timer(timer(state), 1000)
  50. else
  51. context:set_variable("ember.wipe.stage", 2)
  52. local region, hash = checkpoint(state)
  53. context:set_variable("ember.wipe.request", (context:restart_checkpoint{
  54. region = region, spawn_set_hash = hash}).value)
  55. end
  56. return true
  57. end,
  58. client_state = function(context, state, event)
  59. if stage(state) < 2 or event.spawn_state == nil then return end
  60. -- Native state2 follows player teardown/fade start. Publish the clean
  61. -- encounter before its state4 release spawns the team at the checkpoint.
  62. if stage(state) == 2 and event.spawn_state >= 2 then
  63. local region, hash = checkpoint(state)
  64. if state:variable("ember.checkpoint.name") then reset_later(context, state)
  65. else landing.reset_checkpoint(context, state) end
  66. context:set_variable("ember.wipe.stage", 3)
  67. context:restart_checkpoint{region = region, spawn_set_hash = hash,
  68. release_request = state:variable("ember.wipe.request")}
  69. end
  70. if stage(state) == 3 and event.spawn_state == 0 then cancel(context, state) end
  71. end,
  72. effect = function(context, state, event)
  73. if event.request_key and event.request_key.value == state:variable("ember.wipe.request")
  74. and event.outcome ~= "transport_staged" then cancel(context, state) end
  75. end,
  76. }
  77. end