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 == "/kcsapi/api_port/port" || api == "/kcsapi/api_get_member/ship_deck" {
21 if !api.hasSuffix("battleresult") { return }
23 guard let shipName = data["api_get_ship"]["api_ship_name"].string else { return }
24 guard let winRank = data["api_win_rank"].string else { return }
26 guard let battle = TemporaryDataStore.default.battle() else {
28 return Logger.shared.log("Can not get Battle")
31 let mapAreaId = battle.mapArea
33 let store = ServerDataStore.default
35 guard let mapInfo = store.mapInfo(area: mapAreaId, no: battle.mapInfo) else {
37 return Logger.shared.log("KCMasterMapInfo is not found")
40 guard let mapArea = store.mapArea(by: mapAreaId) else {
42 return Logger.shared.log("KCMasterMapArea is not found")
46 let localStore = LocalDataStore.oneTimeEditor()
47 guard let new = localStore.createHiddenDropShipHistory() else {
49 return Logger.shared.log("Can not create HiddenDropShipHistory")
52 new.shipName = shipName
53 new.mapArea = "\(mapAreaId)"
54 new.mapAreaName = mapArea.name
55 new.mapInfo = battle.mapInfo
56 new.mapInfoName = mapInfo.name
57 new.mapCell = battle.no
62 private func storeToVisible() {
64 let store = LocalDataStore.oneTimeEditor()
66 store.hiddenDropShipHistories()
69 guard let new = store.createDropShipHistory() else {
71 return Logger.shared.log("Can not create DropShipHistory")
74 new.shipName = $0.shipName
75 new.mapArea = $0.mapArea
76 new.mapAreaName = $0.mapAreaName
77 new.mapInfo = $0.mapInfo
78 new.mapInfoName = $0.mapInfoName
79 new.mapCell = $0.mapCell
80 new.winRank = $0.winRank