Advertisement
Guest User

Untitled

a guest
Jan 16th, 2023
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. function SideJobEventManager:_setup()
  2. if not Global[self.global_table_name] then
  3. Global[self.global_table_name] = {}
  4. self:_setup_challenges()
  5. end
  6. self._global = Global[self.global_table_name]
  7. if self._global.event_stage then
  8. for _, challenge in ipairs(self:challenges()) do
  9. for event_id, event_data in pairs(self._tweak_data.event_info) do
  10. self:_update_challenge_stages(challenge, "stage_id", event_id .. "_stages", self._global.event_stage[event_id], self.completed_challenge)
  11. end
  12. end
  13. end
  14.  
  15. if setup.IS_START_MENU then
  16. self._event_data_fetched = false
  17.  
  18. self:_fetch_challenges()
  19. end
  20. end
  21.  
  22. function SideJobEventManager:_cg22_fetch_done_clbk(success, s)
  23. print("[SideJobEventManager] - CG22", success, s)
  24. if success then
  25. local events_data = json.decode(s) or {}
  26. self._event_data_fetched = true
  27. local cg22_unlock_stage = (events_data.unlockstage or 0) + 1
  28. local cg22_bags = events_data.bags or 0
  29. self._global.event_data.cg22 = self._global.event_data.cg22 or {}
  30. self._global.event_data.cg22.stage = cg22_unlock_stage
  31. self._global.event_data.cg22.bags = cg22_bags
  32.  
  33. if self._global.event_stage.cg22 ~= cg22_unlock_stage then
  34. self:set_event_stage("cg22", cg22_unlock_stage)
  35. end
  36. end
  37.  
  38. self._fetching_json = false
  39.  
  40. self:_pop_fetch_que()
  41. end
  42.  
  43. function SideJobEventManager:load(cache, version)
  44. local state = cache[self.save_table_name]
  45. if state and state.version == self.save_version then
  46. for idx, saved_challenge in ipairs(state.challenges or {}) do
  47. local challenge = self:get_challenge(saved_challenge.id)
  48. if challenge then
  49. local objectives_complete = true
  50. if not saved_challenge.completed then
  51. for _, objective in ipairs(challenge.objectives) do
  52. for _, saved_objective in ipairs(saved_challenge.objectives) do
  53. if objective.achievement_id ~= nil and objective.achievement_id == saved_objective.achievement_id or objective.progress_id ~= nil and objective.progress_id == saved_objective.progress_id or objective.collective_id ~= nil and objective.collective_id == saved_objective.collective_id then
  54. for _, save_value in ipairs(objective.save_values) do
  55. objective[save_value] = saved_objective[save_value] or objective[save_value]
  56. end
  57. if not saved_objective.completed then
  58. objectives_complete = false
  59. end
  60. elseif objective.choice_id ~= nil and objective.choice_id == saved_objective.choice_id then
  61. for _, save_value in ipairs(objective.save_values) do
  62. objective[save_value] = saved_objective[save_value] or objective[save_value]
  63. end
  64. local any_objective_completed = false
  65. for choice_index, choice_objective in ipairs(objective.challenge_choices) do
  66. for _, save_value in ipairs(choice_objective.save_values) do
  67. choice_objective[save_value] = objective.challenge_choices_saved_values and objective.challenge_choices_saved_values[choice_index][save_value] or choice_objective[save_value]
  68. end
  69. if choice_objective.completed then
  70. any_objective_completed = true
  71. end
  72. end
  73. objectives_complete = any_objective_completed
  74. elseif objective.choice_id or saved_objective.choice_id then
  75. local choice_table = objective.choice_id and objective.challenge_choices or saved_objective.choice_id and saved_objective.challenge_choices_saved_values
  76. for choice_idx, item in pairs(choice_table) do
  77. if item.progress_id and (item.progress_id == objective.progress_id or item.progress_id == saved_objective.progress_id) then
  78. local new_objective = saved_objective.choice_id and item or saved_objective
  79. if objective.choice_id then
  80. for _, save_value in ipairs(objective.challenge_choices[choice_idx].save_values) do
  81. objective.challenge_choices[choice_idx][save_value] = new_objective[save_value] or objective.challenge_choices[choice_idx][save_value]
  82. end
  83. else
  84. for _, save_value in ipairs(objective.save_values) do
  85. objective[save_value] = new_objective[save_value] or objective[save_value]
  86. end
  87. end
  88. end
  89. end
  90. objectives_complete = false
  91. end
  92. end
  93. end
  94. else
  95. for _, objective in ipairs(challenge.objectives) do
  96. objective.progress = objective.max_progress
  97. objective.completed = true
  98. if objective.challenge_choices then
  99. for _, saved_objective in ipairs(saved_challenge.objectives) do
  100. if objective.choice_id ~= nil and objective.choice_id == saved_objective.choice_id then
  101. for _, save_value in ipairs(objective.save_values) do
  102. objective[save_value] = saved_objective[save_value] or objective[save_value]
  103. end
  104. for choice_index, choice_objective in ipairs(objective.challenge_choices) do
  105. for _, save_value in ipairs(choice_objective.save_values) do
  106. choice_objective[save_value] = saved_objective.challenge_choices_saved_values and saved_objective.challenge_choices_saved_values[choice_index][save_value] or choice_objective[save_value]
  107. end
  108. end
  109. elseif objective.choice_id or saved_objective.choice_id then
  110. local choice_table = objective.choice_id and objective.challenge_choices or saved_objective.choice_id and saved_objective.challenge_choices_saved_values
  111. for choice_idx, item in pairs(choice_table) do
  112. if item.progress_id and (item.progress_id == objective.progress_id or item.progress_id == saved_objective.progress_id) then
  113. local new_objective = saved_objective.choice_id and item or saved_objective
  114. if objective.choice_id then
  115. for _, save_value in ipairs(objective.challenge_choices[choice_idx].save_values) do
  116. objective.challenge_choices[choice_idx][save_value] = new_objective[save_value] or objective.challenge_choices[choice_idx][save_value]
  117. end
  118. else
  119. for _, save_value in ipairs(objective.save_values) do
  120. objective[save_value] = new_objective[save_value] or objective[save_value]
  121. end
  122. end
  123. end
  124. end
  125. end
  126. end
  127. end
  128. end
  129. end
  130. challenge.completed = objectives_complete
  131. local all_rewarded = true
  132. for i, reward in ipairs(saved_challenge.rewards) do
  133. if not reward.rewarded then
  134. all_rewarded = false
  135. end
  136. if challenge.rewards[i] then
  137. challenge.rewards[i].rewarded = reward.rewarded
  138. end
  139. end
  140. challenge.rewarded = #saved_challenge.rewards > 0 and all_rewarded or false
  141. end
  142. end
  143. for id, saved_stat in pairs(state.collective_stats or {}) do
  144. local stat = self._global.collective_stats and self._global.collective_stats[id] or nil
  145. if stat then
  146. stat.found = saved_stat.found
  147. end
  148. end
  149. if not self._event_data_fetched then
  150. self._global.event_data = state.event_data or {}
  151. for event_id, data in pairs(self._global.event_data) do
  152. if data.stage then
  153. self:set_event_stage(event_id, data.stage)
  154. end
  155. end
  156. end
  157. for _, challenge in ipairs(self:challenges()) do
  158. for stat_id, stat in pairs(self._global.collective_stats) do
  159. self:_update_challenge_collective(challenge, "collective_id", stat_id, "pda9_update", self.completed_challenge)
  160. end
  161. end
  162. elseif state and state.version == 2 and self.save_version == 3 then
  163. for idx, saved_challenge in ipairs(state.challenges or {}) do
  164. local challenge = self:get_challenge(saved_challenge.id)
  165. if challenge and (challenge.id == "pda9_community_1" or challenge.id == "pda9_community_2" or challenge.id == "pda9_community_3") then
  166. local choice_objective = challenge.objectives[1].challenge_choices[1]
  167. local new_objective = {}
  168. for _, saved_value in ipairs(challenge.objectives[1].save_values) do
  169. new_objective[saved_value] = challenge.objectives[1][saved_value]
  170. end
  171. for _, saved_value in ipairs(choice_objective.save_values) do
  172. new_objective.challenge_choices_saved_values[1][saved_value] = saved_challenge.objectives[1][saved_value] or choice_objective[saved_value]
  173. end
  174. saved_challenge.objectives[1] = new_objective
  175. end
  176. end
  177. state.version = 3
  178. self:load(cache, 3)
  179. end
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement