2 // QuestListCommand.swift
5 // Created by Hori,Masaki on 2017/01/08.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class QuestListCommand: JSONCommand {
13 override class func canExecuteAPI(_ api: String) -> Bool {
15 if api == "/kcsapi/api_get_member/questlist" { return true }
20 override func execute() {
23 guard let tab = parameter["api_tab_id"].int,
27 guard let ql0No = data["api_list"][0]["api_no"].int,
28 let pageCount = data["api_page_count"].int,
29 let page = data["api_disp_page"].int
30 else { return print("data is wrong") }
32 let store = ServerDataStore.oneTimeEditor()
34 // 範囲内の任務をいったん遂行中からはずす
35 let qlmNo = data["api_list"].last["api_no"].int ?? 9999
36 let minNo = (page == 1) ? 0 : ql0No
37 let maxNo = (page == pageCount) ? 9999 : qlmNo
38 store.quests(in: minNo...maxNo).forEach { $0.state = 1 }
41 let quests = store.sortedQuestByNo()
42 data["api_list"].forEach { _, quest in
44 guard let no = quest["api_no"].int
47 let t = quests.binarySearch { $0.no ==? no }
49 guard let new = t ?? store.createQuest()
50 else { return print("Can not create Quest") }
52 new.bonus_flag = quest["api_bonus_flag"].int.map { $0 != 0 } ?? false
53 new.category = quest["api_category"].int ?? 0
54 new.detail = quest["api_detail"].string ?? ""
55 // new.get_material_0 = questData["api_get_material_0"] as? Int ?? 0
56 // new.get_material_1 = questData["api_get_material_1"] as? Int ?? 0
57 // new.get_material_2 = questData["api_get_material_2"] as? Int ?? 0
58 // new.get_material_3 = questData["api_get_material_3"] as? Int ?? 0
59 new.invalid_flag = quest["api_invalid_flag"].int ?? 0
60 new.no = quest["api_no"].int ?? 0
61 new.progress_flag = quest["api_progress_flag"].int ?? 0
62 new.state = quest["api_state"].int ?? 0
63 new.title = quest["api_title"].string ?? ""
64 new.type = quest["api_type"].int ?? 0