OSDN Git Service

7隻の艦隊表示を作成
[kcd/KCD.git] / KCD / QuestListCommand.swift
1 //
2 //  QuestListCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/08.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class QuestListCommand: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: String) -> Bool {
14         
15         if api == "/kcsapi/api_get_member/questlist" { return true }
16         
17         return false
18     }
19     
20     override func execute() {
21         
22         // 左のタブがAllじゃない時は無視する
23         guard let tab = parameter["api_tab_id"].int, tab == 0 else { return }
24         guard let ql0No = data["api_list"][0]["api_no"].int,
25             let pageCount = data["api_page_count"].int,
26             let page = data["api_disp_page"].int else {
27                 
28                 return Logger.shared.log("data is wrong")
29         }
30         
31         let store = ServerDataStore.oneTimeEditor()
32         
33         // 範囲内の任務をいったん遂行中からはずす
34         let qlmNo = data["api_list"].last["api_no"].int ?? 9999
35         let minNo = (page == 1) ? 0 : ql0No
36         let maxNo = (page == pageCount) ? 9999 : qlmNo
37         store.quests(in: minNo...maxNo).forEach { $0.state = 1 }
38         
39         // 新しいデータ投入
40         let quests = store.sortedQuestByNo()
41         data["api_list"].forEach { _, quest in
42             
43             guard let no = quest["api_no"].int else { return }
44             
45             let t = quests.binarySearch { $0.no ==? no }
46             
47             guard let new = t ?? store.createQuest() else { return Logger.shared.log("Can not create Quest") }
48             
49             new.bonus_flag = quest["api_bonus_flag"].int.map { $0 != 0 } ?? false
50             new.category = quest["api_category"].int ?? 0
51             new.detail = quest["api_detail"].string ?? ""
52 //            new.get_material_0 = questData["api_get_material_0"] as? Int ?? 0
53 //            new.get_material_1 = questData["api_get_material_1"] as? Int ?? 0
54 //            new.get_material_2 = questData["api_get_material_2"] as? Int ?? 0
55 //            new.get_material_3 = questData["api_get_material_3"] as? Int ?? 0
56             new.invalid_flag = quest["api_invalid_flag"].int ?? 0
57             new.no = quest["api_no"].int ?? 0
58             new.progress_flag = quest["api_progress_flag"].int ?? 0
59             new.state = quest["api_state"].int ?? 0
60             new.title = quest["api_title"].string ?? ""
61             new.type = quest["api_type"].int ?? 0
62         }
63     }
64 }