OSDN Git Service

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