OSDN Git Service

AppDelegateからウインドウに関する部分を分離した
[kcd/KCD.git] / KCD / KenzoMarkCommand.swift
1 //
2 //  KenzoMarkCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/12.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 class KenzoMarkCommand: JSONCommand {
12     override func execute() {
13         guard let kdockId = parameter["api_kdock_id"].int
14             else { return print("api_kdock_id is wrong") }
15         
16         let store = ServerDataStore.default
17         guard let kenzoDock = store.kenzoDock(by: kdockId)
18             else { return print("KenzoDock is not fount") }
19         let fuel = kenzoDock.item1
20         let bull = kenzoDock.item2
21         let steel = kenzoDock.item3
22         let bauxite = kenzoDock.item4
23         let kaihatu = kenzoDock.item5
24         let shipId = kenzoDock.created_ship_id
25         
26         guard let flagShip = store.masterShip(by: shipId)
27             else { return print("MasterShip is not found") }
28         
29         let localStore = LocalDataStore.oneTimeEditor()
30         guard let new = localStore.createKenzoHistory()
31             else { return print("Can not create KenzoHistory") }
32         
33         new.name = flagShip.name
34         new.sTypeId = flagShip.stype.id
35         new.fuel = fuel
36         new.bull = bull
37         new.steel = steel
38         new.bauxite = bauxite
39         new.kaihatusizai = kaihatu
40         new.date = Date()
41         (new.flagShipLv, new.flagShipName, new.commanderLv) =
42             markedValues(fuel: fuel,
43                          bull: bull,
44                          steel: steel,
45                          bauxite: bauxite,
46                          kaihatu: kaihatu,
47                          kdockId: kdockId,
48                          shipId: shipId)
49     }
50     // swiftlint:disable function_parameter_count
51     private func markedValues(fuel: Int,
52                               bull: Int,
53                               steel: Int,
54                               bauxite: Int,
55                               kaihatu: Int,
56                               kdockId: Int,
57                               shipId: Int) -> (Int, String, Int) {
58         let store = LocalDataStore.default
59         if let kenzoMark = store.kenzoMark(fuel: fuel,
60                                            bull: bull,
61                                            steel: steel,
62                                            bauxite: bauxite,
63                                            kaihatusizai: kaihatu,
64                                            kDockId: kdockId,
65                                            shipId: shipId) {
66             return (kenzoMark.flagShipLv,
67                     kenzoMark.flagShipName,
68                     kenzoMark.commanderLv)
69         }
70         return (-1, "", -1)
71     }
72 }