OSDN Git Service

MappingConfigurationのプロパティを変更
[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 class QuestListCommand: JSONCommand {
12     override class func canExecuteAPI(_ api: String) -> Bool {
13         if api == "/kcsapi/api_get_member/questlist" { return true }
14         return false
15     }
16     override func execute() {
17         // 左のタブがAllじゃない時は無視する
18         guard let tab = arguments["api_tab_id"].flatMap({ Int($0) }),
19             tab == 0
20             else { return }
21         
22         guard let ql0No = data["api_list"][0]["api_no"].int,
23             let pageCount = data["api_page_count"].int,
24             let page = data["api_disp_page"].int
25             else { return print("data is wrong") }
26         
27         let store = ServerDataStore.oneTimeEditor()
28         
29         // 範囲内の任務をいったん遂行中からはずす
30         let qlmNo = data["api_list"].last["api_no"].int ?? 9999
31         let minNo = (page == 1) ? 0 : ql0No
32         let maxNo = (page == pageCount) ? 9999 : qlmNo
33         store.quests(in: minNo...maxNo).forEach { $0.state = 1 }
34         
35         // 新しいデータ投入
36         let quests = store.sortedQuestByNo()
37         data["api_list"].forEach { (_, quest) in
38             guard let no = quest["api_no"].int
39             else { return }
40             let t = quests.binarySearch { $0.no ==? no }
41             guard let new = t ?? store.createQuest()
42                 else { return print("Can not create Quest") }
43             new.bonus_flag = quest["api_bonus_flag"].bool ?? false
44             new.category = quest["api_category"].int ?? 0
45             new.detail = quest["api_detail"].string ?? ""
46 //            new.get_material_0 = questData["api_get_material_0"] as? Int ?? 0
47 //            new.get_material_1 = questData["api_get_material_1"] as? Int ?? 0
48 //            new.get_material_2 = questData["api_get_material_2"] as? Int ?? 0
49 //            new.get_material_3 = questData["api_get_material_3"] as? Int ?? 0
50             new.invalid_flag = quest["api_invalid_flag"].int ?? 0
51             new.no = quest["api_no"].int ?? 0
52             new.progress_flag = quest["api_progress_flag"].int ?? 0
53             new.state = quest["api_state"].int ?? 0
54             new.title = quest["api_title"].string ?? ""
55             new.type = quest["api_type"].int ?? 0
56         }
57     }
58 }