OSDN Git Service

swiftlint 'line_length'の警告を修正
[kcd/KCD.git] / KCD / CreateShipCommand.swift
1 //
2 //  CreateShipCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/11.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 class CreateShipCommand: JSONCommand {
12     override class func canExecuteAPI(_ api: String) -> Bool {
13         if api == "/kcsapi/api_req_kousyou/createship" { return true }
14         return false
15     }
16     override func execute() {
17         DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
18             self.afterExecute()
19         }
20     }
21     private func afterExecute() {
22         guard let dockId = arguments["api_kdock_id"].flatMap({ Int($0) })
23             else { return print("api_kdock_id is wrong") }
24         let store = ServerDataStore.default
25         guard let kenzoDock = store.kenzoDock(byDockId: dockId),
26             let flagShip = store.deck(byId: 1)
27                 .flatMap({ store.ship(byId: $0.ship_0) }),
28             let basic = store.basic()
29             else { return print("CreateShipCommand: CoreData is wrong") }
30         
31         let localStore = LocalDataStore.oneTimeEditor()
32         guard let newMark = localStore.kenzoMark(byDockId: dockId) ?? localStore.createKenzoMark()
33             else { return print("Can not create KenzoMark") }
34         
35         newMark.fuel = kenzoDock.item1
36         newMark.bull = kenzoDock.item2
37         newMark.steel = kenzoDock.item3
38         newMark.bauxite = kenzoDock.item4
39         newMark.kaihatusizai = kenzoDock.item5
40         newMark.created_ship_id = kenzoDock.created_ship_id
41         newMark.flagShipName = flagShip.name
42         newMark.flagShipLv = flagShip.lv
43         newMark.commanderLv = basic.level
44         newMark.kDockId = dockId
45     }
46 }