OSDN Git Service

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