OSDN Git Service

コード整形
[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 final class KenzoMarkCommand: JSONCommand {
12     
13     override func execute() {
14         
15         guard let kdockId = parameter["api_kdock_id"].int
16             else { return print("api_kdock_id is wrong") }
17         
18         let store = ServerDataStore.default
19         
20         guard let kenzoDock = store.kenzoDock(by: kdockId)
21             else { return print("KenzoDock is not fount") }
22         
23         let fuel = kenzoDock.item1
24         let bull = kenzoDock.item2
25         let steel = kenzoDock.item3
26         let bauxite = kenzoDock.item4
27         let kaihatu = kenzoDock.item5
28         let shipId = kenzoDock.created_ship_id
29         
30         guard let flagShip = store.masterShip(by: shipId)
31             else { return print("MasterShip is not found") }
32         
33         let localStore = LocalDataStore.oneTimeEditor()
34         guard let new = localStore.createKenzoHistory()
35             else { return print("Can not create KenzoHistory") }
36         
37         new.name = flagShip.name
38         new.sTypeId = flagShip.stype.id
39         new.fuel = fuel
40         new.bull = bull
41         new.steel = steel
42         new.bauxite = bauxite
43         new.kaihatusizai = kaihatu
44         new.date = Date()
45         (new.flagShipLv, new.flagShipName, new.commanderLv) =
46             markedValues(fuel: fuel,
47                          bull: bull,
48                          steel: steel,
49                          bauxite: bauxite,
50                          kaihatu: kaihatu,
51                          kdockId: kdockId,
52                          shipId: shipId)
53     }
54     
55     // swiftlint:disable function_parameter_count
56     private func markedValues(fuel: Int,
57                               bull: Int,
58                               steel: Int,
59                               bauxite: Int,
60                               kaihatu: Int,
61                               kdockId: Int,
62                               shipId: Int) -> (Int, String, Int) {
63         
64         let store = LocalDataStore.default
65         
66         if let kenzoMark = store.kenzoMark(fuel: fuel,
67                                            bull: bull,
68                                            steel: steel,
69                                            bauxite: bauxite,
70                                            kaihatusizai: kaihatu,
71                                            kDockId: kdockId,
72                                            shipId: shipId) {
73             
74             return (kenzoMark.flagShipLv,
75                     kenzoMark.flagShipName,
76                     kenzoMark.commanderLv)
77         }
78         
79         return (-1, "", -1)
80     }
81 }