Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SideJobEventManager:_setup()
- if not Global[self.global_table_name] then
- Global[self.global_table_name] = {}
- self:_setup_challenges()
- end
- self._global = Global[self.global_table_name]
- if self._global.event_stage then
- for _, challenge in ipairs(self:challenges()) do
- for event_id, event_data in pairs(self._tweak_data.event_info) do
- self:_update_challenge_stages(challenge, "stage_id", event_id .. "_stages", self._global.event_stage[event_id], self.completed_challenge)
- end
- end
- end
- if setup.IS_START_MENU then
- self._event_data_fetched = false
- self:_fetch_challenges()
- end
- end
- function SideJobEventManager:_cg22_fetch_done_clbk(success, s)
- print("[SideJobEventManager] - CG22", success, s)
- if success then
- local events_data = json.decode(s) or {}
- self._event_data_fetched = true
- local cg22_unlock_stage = (events_data.unlockstage or 0) + 1
- local cg22_bags = events_data.bags or 0
- self._global.event_data.cg22 = self._global.event_data.cg22 or {}
- self._global.event_data.cg22.stage = cg22_unlock_stage
- self._global.event_data.cg22.bags = cg22_bags
- if self._global.event_stage.cg22 ~= cg22_unlock_stage then
- self:set_event_stage("cg22", cg22_unlock_stage)
- end
- end
- self._fetching_json = false
- self:_pop_fetch_que()
- end
- function SideJobEventManager:load(cache, version)
- local state = cache[self.save_table_name]
- if state and state.version == self.save_version then
- for idx, saved_challenge in ipairs(state.challenges or {}) do
- local challenge = self:get_challenge(saved_challenge.id)
- if challenge then
- local objectives_complete = true
- if not saved_challenge.completed then
- for _, objective in ipairs(challenge.objectives) do
- for _, saved_objective in ipairs(saved_challenge.objectives) do
- 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
- for _, save_value in ipairs(objective.save_values) do
- objective[save_value] = saved_objective[save_value] or objective[save_value]
- end
- if not saved_objective.completed then
- objectives_complete = false
- end
- elseif objective.choice_id ~= nil and objective.choice_id == saved_objective.choice_id then
- for _, save_value in ipairs(objective.save_values) do
- objective[save_value] = saved_objective[save_value] or objective[save_value]
- end
- local any_objective_completed = false
- for choice_index, choice_objective in ipairs(objective.challenge_choices) do
- for _, save_value in ipairs(choice_objective.save_values) do
- choice_objective[save_value] = objective.challenge_choices_saved_values and objective.challenge_choices_saved_values[choice_index][save_value] or choice_objective[save_value]
- end
- if choice_objective.completed then
- any_objective_completed = true
- end
- end
- objectives_complete = any_objective_completed
- elseif objective.choice_id or saved_objective.choice_id then
- local choice_table = objective.choice_id and objective.challenge_choices or saved_objective.choice_id and saved_objective.challenge_choices_saved_values
- for choice_idx, item in pairs(choice_table) do
- if item.progress_id and (item.progress_id == objective.progress_id or item.progress_id == saved_objective.progress_id) then
- local new_objective = saved_objective.choice_id and item or saved_objective
- if objective.choice_id then
- for _, save_value in ipairs(objective.challenge_choices[choice_idx].save_values) do
- objective.challenge_choices[choice_idx][save_value] = new_objective[save_value] or objective.challenge_choices[choice_idx][save_value]
- end
- else
- for _, save_value in ipairs(objective.save_values) do
- objective[save_value] = new_objective[save_value] or objective[save_value]
- end
- end
- end
- end
- objectives_complete = false
- end
- end
- end
- else
- for _, objective in ipairs(challenge.objectives) do
- objective.progress = objective.max_progress
- objective.completed = true
- if objective.challenge_choices then
- for _, saved_objective in ipairs(saved_challenge.objectives) do
- if objective.choice_id ~= nil and objective.choice_id == saved_objective.choice_id then
- for _, save_value in ipairs(objective.save_values) do
- objective[save_value] = saved_objective[save_value] or objective[save_value]
- end
- for choice_index, choice_objective in ipairs(objective.challenge_choices) do
- for _, save_value in ipairs(choice_objective.save_values) do
- 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]
- end
- end
- elseif objective.choice_id or saved_objective.choice_id then
- local choice_table = objective.choice_id and objective.challenge_choices or saved_objective.choice_id and saved_objective.challenge_choices_saved_values
- for choice_idx, item in pairs(choice_table) do
- if item.progress_id and (item.progress_id == objective.progress_id or item.progress_id == saved_objective.progress_id) then
- local new_objective = saved_objective.choice_id and item or saved_objective
- if objective.choice_id then
- for _, save_value in ipairs(objective.challenge_choices[choice_idx].save_values) do
- objective.challenge_choices[choice_idx][save_value] = new_objective[save_value] or objective.challenge_choices[choice_idx][save_value]
- end
- else
- for _, save_value in ipairs(objective.save_values) do
- objective[save_value] = new_objective[save_value] or objective[save_value]
- end
- end
- end
- end
- end
- end
- end
- end
- end
- challenge.completed = objectives_complete
- local all_rewarded = true
- for i, reward in ipairs(saved_challenge.rewards) do
- if not reward.rewarded then
- all_rewarded = false
- end
- if challenge.rewards[i] then
- challenge.rewards[i].rewarded = reward.rewarded
- end
- end
- challenge.rewarded = #saved_challenge.rewards > 0 and all_rewarded or false
- end
- end
- for id, saved_stat in pairs(state.collective_stats or {}) do
- local stat = self._global.collective_stats and self._global.collective_stats[id] or nil
- if stat then
- stat.found = saved_stat.found
- end
- end
- if not self._event_data_fetched then
- self._global.event_data = state.event_data or {}
- for event_id, data in pairs(self._global.event_data) do
- if data.stage then
- self:set_event_stage(event_id, data.stage)
- end
- end
- end
- for _, challenge in ipairs(self:challenges()) do
- for stat_id, stat in pairs(self._global.collective_stats) do
- self:_update_challenge_collective(challenge, "collective_id", stat_id, "pda9_update", self.completed_challenge)
- end
- end
- elseif state and state.version == 2 and self.save_version == 3 then
- for idx, saved_challenge in ipairs(state.challenges or {}) do
- local challenge = self:get_challenge(saved_challenge.id)
- if challenge and (challenge.id == "pda9_community_1" or challenge.id == "pda9_community_2" or challenge.id == "pda9_community_3") then
- local choice_objective = challenge.objectives[1].challenge_choices[1]
- local new_objective = {}
- for _, saved_value in ipairs(challenge.objectives[1].save_values) do
- new_objective[saved_value] = challenge.objectives[1][saved_value]
- end
- for _, saved_value in ipairs(choice_objective.save_values) do
- new_objective.challenge_choices_saved_values[1][saved_value] = saved_challenge.objectives[1][saved_value] or choice_objective[saved_value]
- end
- saved_challenge.objectives[1] = new_objective
- end
- end
- state.version = 3
- self:load(cache, 3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement