2 // DropShipHistoryCommand.swift
5 // Created by Hori,Masaki on 2017/01/14.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class DropShipHistoryCommand: JSONCommand {
13 override func execute() {
15 if api.endpoint == .port || api.endpoint == .shipDeck {
20 if api.type != .battleResult { return }
22 guard let shipName = data["api_get_ship"]["api_ship_name"].string else { return }
23 guard let winRank = data["api_win_rank"].string else { return }
25 guard let battle = TemporaryDataStore.default.battle() else {
27 return Logger.shared.log("Can not get Battle")
30 let mapAreaId = battle.mapArea
32 let store = ServerDataStore.default
34 guard let mapInfo = store.mapInfo(area: mapAreaId, no: battle.mapInfo) else {
36 return Logger.shared.log("KCMasterMapInfo is not found")
39 guard let mapArea = store.mapArea(by: mapAreaId) else {
41 return Logger.shared.log("KCMasterMapArea is not found")
45 let localStore = LocalDataStore.oneTimeEditor()
46 guard let new = localStore.createHiddenDropShipHistory() else {
48 return Logger.shared.log("Can not create HiddenDropShipHistory")
51 new.shipName = shipName
52 new.mapArea = "\(mapAreaId)"
53 new.mapAreaName = mapArea.name
54 new.mapInfo = battle.mapInfo
55 new.mapInfoName = mapInfo.name
56 new.mapCell = battle.no
61 private func storeToVisible() {
63 let store = LocalDataStore.oneTimeEditor()
65 store.hiddenDropShipHistories()
68 guard let new = store.createDropShipHistory() else {
70 return Logger.shared.log("Can not create DropShipHistory")
73 new.shipName = $0.shipName
74 new.mapArea = $0.mapArea
75 new.mapAreaName = $0.mapAreaName
76 new.mapInfo = $0.mapInfo
77 new.mapInfoName = $0.mapInfoName
78 new.mapCell = $0.mapCell
79 new.winRank = $0.winRank