2 // KenzoMarkCommand.swift
5 // Created by Hori,Masaki on 2017/01/12.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class KenzoMarkCommand: JSONCommand {
13 struct KenzoDockInfo {
23 override func execute() {
25 let store = LocalDataStore.oneTimeEditor()
27 self.executeInContext(localStore: store)
31 private func executeInContext(localStore: LocalDataStore) {
33 guard let kdockId = parameter["api_kdock_id"].int else {
35 return Logger.shared.log("api_kdock_id is wrong")
38 let store = ServerDataStore.default
39 guard let kenzoDock = store.sync(execute: { store.kenzoDock(by: kdockId) }) else {
41 return Logger.shared.log("KenzoDock is not found")
43 let kenzoDockInfo = store.sync {
44 KenzoDockInfo(dockId: kenzoDock.id,
45 shipId: kenzoDock.created_ship_id,
46 fuel: kenzoDock.item1,
47 bull: kenzoDock.item2,
48 steel: kenzoDock.item3,
49 bauxite: kenzoDock.item4,
50 kaihatusizai: kenzoDock.item5)
52 guard let flagShip = store.sync(execute: { store.masterShip(by: kenzoDock.created_ship_id) }) else {
54 return Logger.shared.log("MasterShip is not found")
57 guard let new = localStore.createKenzoHistory() else {
59 return Logger.shared.log("Can not create KenzoHistory")
62 new.name = store.sync { flagShip.name }
63 new.sTypeId = store.sync { flagShip.stype.id }
64 new.fuel = kenzoDockInfo.fuel
65 new.bull = kenzoDockInfo.bull
66 new.steel = kenzoDockInfo.steel
67 new.bauxite = kenzoDockInfo.bauxite
68 new.kaihatusizai = kenzoDockInfo.kaihatusizai
70 (new.flagShipLv, new.flagShipName, new.commanderLv) = markedValues(docInfo: kenzoDockInfo, in: localStore)
73 private func markedValues(docInfo: KenzoDockInfo, in store: LocalDataStore) -> (Int, String, Int) {
75 if let kenzoMark = store.kenzoMark(docInfo: docInfo) {
77 return (kenzoMark.flagShipLv, kenzoMark.flagShipName, kenzoMark.commanderLv)